-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathapp.js
More file actions
47 lines (42 loc) · 1.11 KB
/
Copy pathapp.js
File metadata and controls
47 lines (42 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import fs from 'node:fs'
import * as m from 'mastodonclient'
// load config file
export function config(configFilename) {
let data
try {
data = fs.readFileSync(configFilename)
} catch (e) {
return null
}
if (!data) {
return null
}
return JSON.parse(data)
}
// save config to file
const saveConfig = async function (config, configFilename) {
return new Promise(function (resolve, reject) {
fs.writeFileSync(configFilename, JSON.stringify(config), { mode: '0600' }, function (err, data) {
if (err) {
return reject(err)
}
resolve(data)
})
})
}
// generate config file interactively
export async function interactive(configFilename) {
const config = await m.auth()
await saveConfig(config, configFilename)
console.log('Autentication complete!')
console.log('You can now do:')
console.log(' toot <message>')
console.log('to post to Mastodon.')
console.log('')
return config
}
// send a status update
export async function toot(config, message, visibility, cw) {
const mc = new m.MastodonClient(config)
return await mc.post(message, visibility, cw)
}