|
|
|
@ -1,4 +1,6 @@
|
|
|
|
|
|
|
|
|
|
const args = require('minimist')(process.argv.slice(2));
|
|
|
|
|
|
|
|
|
|
// the main juice
|
|
|
|
|
|
|
|
|
|
const { buddies } = require('./config')
|
|
|
|
@ -6,18 +8,44 @@ if(!buddies) throw "Did you seutp your config?"
|
|
|
|
|
|
|
|
|
|
const { toot } = require('./toot');
|
|
|
|
|
|
|
|
|
|
function assertBuddyConfigCorrect(buddyConfig) {
|
|
|
|
|
const errs = []
|
|
|
|
|
if(!buddyConfig.name) errs.push("No 'name' property found")
|
|
|
|
|
if(!buddyConfig.instance) errs.push("No 'instance' property found")
|
|
|
|
|
if(!buddyConfig.oauthToken) errs.push("No 'oauthToken' property found")
|
|
|
|
|
|
|
|
|
|
if(errs.length > 0) {
|
|
|
|
|
console.error(`Whoops, a buddy is misconfigured: ${errs.join(', ')}. Exiting.`)
|
|
|
|
|
process.exit(-1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function letBuddyChat(buddyConfig) {
|
|
|
|
|
//assertBuddyConfigCorrect(buddyConfig)
|
|
|
|
|
console.log(`bootstrapping chat for ${buddyConfig.name}...`)
|
|
|
|
|
const { chat } = require(`./buddies/${buddyConfig.name}/buddy`)
|
|
|
|
|
|
|
|
|
|
// contains 'toot', and maybe 'attach' / 'attachDescription'
|
|
|
|
|
const message = await chat(buddyConfig)
|
|
|
|
|
console.log(`buddy ${buddyConfig.name} has this to say: ${JSON.stringify(message)}`)
|
|
|
|
|
|
|
|
|
|
//await toot(message, buddyConfig)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(async function() {
|
|
|
|
|
for await(buddyConfig of buddies) {
|
|
|
|
|
console.log(`bootstrapping chat for ${buddyConfig.name}...`)
|
|
|
|
|
const { chat } = require(`./buddies/${buddyConfig.name}/buddy`)
|
|
|
|
|
|
|
|
|
|
// contains 'toot', and maybe 'attach' / 'attachDescription'
|
|
|
|
|
const message = await chat(buddyConfig)
|
|
|
|
|
console.log(`buddy ${buddyConfig.name} has this to say: ${JSON.stringify(message)}`)
|
|
|
|
|
|
|
|
|
|
await toot(message, buddyConfig)
|
|
|
|
|
if(args.buddy) {
|
|
|
|
|
const config = buddies.find(b => b.name === args.buddy)
|
|
|
|
|
if(!config) {
|
|
|
|
|
console.error(`Whoops, you asked to let buddy "${args.buddy}" chat, but no config found? Exiting.`)
|
|
|
|
|
process.exit(-1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await letBuddyChat(config)
|
|
|
|
|
} else {
|
|
|
|
|
for await(buddyConfig of buddies) {
|
|
|
|
|
await letBuddyChat(buddyConfig)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('Done! for now... ')
|
|
|
|
|
})()
|
|
|
|
|
|
|
|
|
|