44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
require('dotenv').config()
|
|
const database = require('./database.json')
|
|
const Mastodon = require('mastodon-api')
|
|
|
|
function getSubKey(arr, key, lang) {
|
|
return arr[`${key}_${lang}`] || arr[lang]
|
|
}
|
|
function randomValue(arr) {
|
|
return arr[Math.floor(Math.random() * arr.length)]
|
|
}
|
|
|
|
const TOKEN = 'ACCESS_TOKEN'
|
|
const URL = 'API_URL'
|
|
const VISIBILITY = 'VISIBILITY'
|
|
|
|
const CONF = process.env
|
|
|
|
Object.keys(CONF)
|
|
.filter(e => e[0].startsWith(TOKEN))
|
|
.map(key => key.substring(TOKEN.length + 1))
|
|
.forEach(async (lang) => {
|
|
const getOption = (key) => getSubKey(CONF, key, lang)
|
|
|
|
const visi = getOption(VISIBILITY)
|
|
|
|
const M = new Mastodon({
|
|
access_token: getOption(TOKEN),
|
|
api_url: `${getOption(URL)}/api/v1/`,
|
|
timeout_ms: 60 * 1000
|
|
})
|
|
|
|
const me = await M.get('accounts/verify_credentials')
|
|
if (me.data.error) throw me.data.error
|
|
|
|
const fols = await M.get(`accounts/${me.data.id}/followers`, { limit: 9999 })
|
|
for (const follow of fols.data) {
|
|
M.post('statuses', {
|
|
status: `@${follow.acct} ${lang.length > 0 ?
|
|
randomValue(database)[lang] :
|
|
'\n' + Object.entries(randomValue(database)).map(m => `[${m[0]}] ${m[1]}`).join('\n\n')
|
|
}`, visibility: visi
|
|
})
|
|
}
|
|
}) |