simple argument parsing to let a specific buddy chat
This commit is contained in:
parent
2266cd4789
commit
60e8dbe69f
|
@ -42,7 +42,8 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
|
||||||
["got", "npm:11.8.2"],
|
["got", "npm:11.8.2"],
|
||||||
["jest", "npm:26.6.3"],
|
["jest", "npm:26.6.3"],
|
||||||
["jsdom", "virtual:defa486869c88441047200a53b3aa18d79743b272095f3ee31b5b7b80b2c93d87f722added867470dcb94104504489a1a89040ea8fd89dffb9cfb1864d4bf54e#npm:16.5.2"],
|
["jsdom", "virtual:defa486869c88441047200a53b3aa18d79743b272095f3ee31b5b7b80b2c93d87f722added867470dcb94104504489a1a89040ea8fd89dffb9cfb1864d4bf54e#npm:16.5.2"],
|
||||||
["md5", "npm:2.3.0"]
|
["md5", "npm:2.3.0"],
|
||||||
|
["minimist", "npm:1.2.5"]
|
||||||
],
|
],
|
||||||
"linkType": "SOFT",
|
"linkType": "SOFT",
|
||||||
}]
|
}]
|
||||||
|
@ -4754,7 +4755,8 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
|
||||||
["got", "npm:11.8.2"],
|
["got", "npm:11.8.2"],
|
||||||
["jest", "npm:26.6.3"],
|
["jest", "npm:26.6.3"],
|
||||||
["jsdom", "virtual:defa486869c88441047200a53b3aa18d79743b272095f3ee31b5b7b80b2c93d87f722added867470dcb94104504489a1a89040ea8fd89dffb9cfb1864d4bf54e#npm:16.5.2"],
|
["jsdom", "virtual:defa486869c88441047200a53b3aa18d79743b272095f3ee31b5b7b80b2c93d87f722added867470dcb94104504489a1a89040ea8fd89dffb9cfb1864d4bf54e#npm:16.5.2"],
|
||||||
["md5", "npm:2.3.0"]
|
["md5", "npm:2.3.0"],
|
||||||
|
["minimist", "npm:1.2.5"]
|
||||||
],
|
],
|
||||||
"linkType": "SOFT",
|
"linkType": "SOFT",
|
||||||
}]
|
}]
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
"got": "^11.8.2",
|
"got": "^11.8.2",
|
||||||
"jsdom": "^16.5.2",
|
"jsdom": "^16.5.2",
|
||||||
"md5": "^2.3.0"
|
"md5": "^2.3.0",
|
||||||
|
"minimist": "^1.2.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
48
src/chat.js
48
src/chat.js
|
@ -1,4 +1,6 @@
|
||||||
|
|
||||||
|
const args = require('minimist')(process.argv.slice(2));
|
||||||
|
|
||||||
// the main juice
|
// the main juice
|
||||||
|
|
||||||
const { buddies } = require('./config')
|
const { buddies } = require('./config')
|
||||||
|
@ -6,18 +8,44 @@ if(!buddies) throw "Did you seutp your config?"
|
||||||
|
|
||||||
const { toot } = require('./toot');
|
const { toot } = require('./toot');
|
||||||
|
|
||||||
(async function() {
|
function assertBuddyConfigCorrect(buddyConfig) {
|
||||||
for await(buddyConfig of buddies) {
|
const errs = []
|
||||||
console.log(`bootstrapping chat for ${buddyConfig.name}...`)
|
if(!buddyConfig.name) errs.push("No 'name' property found")
|
||||||
const { chat } = require(`./buddies/${buddyConfig.name}/buddy`)
|
if(!buddyConfig.instance) errs.push("No 'instance' property found")
|
||||||
|
if(!buddyConfig.oauthToken) errs.push("No 'oauthToken' property found")
|
||||||
// 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(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() {
|
||||||
|
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... ')
|
console.log('Done! for now... ')
|
||||||
})()
|
})()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue