30 lines
1.0 KiB
JavaScript
30 lines
1.0 KiB
JavaScript
require('dotenv').config()
|
|
const database = require('./database.json')
|
|
const Mastodon = require('mastodon-api')
|
|
|
|
const TOKEN = 'ACCESS_TOKEN'
|
|
const URL = 'API_URL'
|
|
|
|
Object.entries(process.env)
|
|
.filter(e => e[0].startsWith(TOKEN))
|
|
.forEach(e => {
|
|
const lang = e[0].substring(TOKEN.length + 1)
|
|
|
|
const M = new Mastodon({
|
|
access_token: process.env[`${TOKEN}_${lang}`] || process.env[TOKEN],
|
|
api_url: `${process.env[`API_URL_${lang}`] || process.env[URL]}/api/v1/`,
|
|
timeout_ms: 60 * 1000
|
|
})
|
|
|
|
M.get('accounts/verify_credentials').then(
|
|
me => 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: 'unlisted' })
|
|
}
|
|
})
|
|
)
|
|
})
|