simple argument parsing to let a specific buddy chat

This commit is contained in:
Wouter Groeneveld 2021-04-02 08:53:04 +02:00
parent 2266cd4789
commit 60e8dbe69f
4 changed files with 45 additions and 13 deletions

6
.pnp.js generated
View File

@ -42,7 +42,8 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["got", "npm:11.8.2"],
["jest", "npm:26.6.3"],
["jsdom", "virtual:defa486869c88441047200a53b3aa18d79743b272095f3ee31b5b7b80b2c93d87f722added867470dcb94104504489a1a89040ea8fd89dffb9cfb1864d4bf54e#npm:16.5.2"],
["md5", "npm:2.3.0"]
["md5", "npm:2.3.0"],
["minimist", "npm:1.2.5"]
],
"linkType": "SOFT",
}]
@ -4754,7 +4755,8 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["got", "npm:11.8.2"],
["jest", "npm:26.6.3"],
["jsdom", "virtual:defa486869c88441047200a53b3aa18d79743b272095f3ee31b5b7b80b2c93d87f722added867470dcb94104504489a1a89040ea8fd89dffb9cfb1864d4bf54e#npm:16.5.2"],
["md5", "npm:2.3.0"]
["md5", "npm:2.3.0"],
["minimist", "npm:1.2.5"]
],
"linkType": "SOFT",
}]

View File

@ -20,6 +20,7 @@
"form-data": "^4.0.0",
"got": "^11.8.2",
"jsdom": "^16.5.2",
"md5": "^2.3.0"
"md5": "^2.3.0",
"minimist": "^1.2.5"
}
}

View File

@ -1,4 +1,6 @@
const args = require('minimist')(process.argv.slice(2));
// the main juice
const { buddies } = require('./config')
@ -6,8 +8,20 @@ if(!buddies) throw "Did you seutp your config?"
const { toot } = require('./toot');
(async function() {
for await(buddyConfig of buddies) {
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`)
@ -15,9 +29,23 @@ const { toot } = require('./toot');
const message = await chat(buddyConfig)
console.log(`buddy ${buddyConfig.name} has this to say: ${JSON.stringify(message)}`)
await toot(message, buddyConfig)
//await toot(message, buddyConfig)
}
(async function() {
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... ')
})()

View File

@ -4040,6 +4040,7 @@ fsevents@^2.1.2:
jest: ^26.6.3
jsdom: ^16.5.2
md5: ^2.3.0
minimist: ^1.2.5
languageName: unknown
linkType: soft