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