add buddy next to name in config for args
This commit is contained in:
parent
60e8dbe69f
commit
4d687cd22e
|
@ -12,6 +12,12 @@ Yay! **Working examples** say more than a 1000 words:
|
|||
|
||||
Execute through `yarn toot` or `yarn node src/chat.js`. It cycles through all configured "buddies" and toots a message accordingly. Use your favorite `crontab` timestamp to fire off toots automatically.
|
||||
|
||||
If you'd like to let a specific buddy chat - for instance to configure them individually in your crontab - use the argument `buddy`:
|
||||
|
||||
`yarn toot --buddy [by-cool-buddy]`
|
||||
|
||||
The name shouldl match the `buddy` property in the config file (_not_ the `name` property: that's the buddy directory name).
|
||||
|
||||
### Packaged buddies
|
||||
|
||||
1. **animalcrossing**: collect data from https://animalcrossing.fandom.com/wiki/ and randomly toot about a villager, including a link to the fandom and the birthday. Uses dirty scraping, no rate limit hit yet...
|
||||
|
@ -40,6 +46,7 @@ See `config.sample.js`. A config file should expose `buddies` as an array with t
|
|||
```js
|
||||
{
|
||||
name: "buddyname", // same as the dir name
|
||||
buddy: "my cool buddy", // unique buddy id
|
||||
instance: "https://mastodon.social", // where to post to
|
||||
oauthToken: "my-token" // the oauth token for that server/user to post the status with
|
||||
}
|
||||
|
@ -47,6 +54,8 @@ See `config.sample.js`. A config file should expose `buddies` as an array with t
|
|||
|
||||
Optional config flags can be used in the chat function if desired.
|
||||
|
||||
There's a sanity check implemented: at minimum, each config should have name, buddy, instance, and oauthToken present.
|
||||
|
||||
## How to get an OAuth token from a Masto?Pleroma instance?
|
||||
|
||||
I've prepared a few utility functions in `registerApp.js` for you. First, call `await register()`, which prints an URL to go to. Next, fill in the client id, secret, and returned token, after granting the app access to read and write. Then, call `await fetchToken()`. Paste that token in the config file. Done!
|
||||
|
|
12
src/chat.js
12
src/chat.js
|
@ -9,10 +9,10 @@ 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")
|
||||
let errs = []
|
||||
[ 'name', 'buddy', 'instance', 'oauthToken' ].forEach(prop => {
|
||||
if(!buddyConfig[prop]) errs.push(`No '${prop}' property found`)
|
||||
})
|
||||
|
||||
if(errs.length > 0) {
|
||||
console.error(`Whoops, a buddy is misconfigured: ${errs.join(', ')}. Exiting.`)
|
||||
|
@ -29,12 +29,12 @@ async function letBuddyChat(buddyConfig) {
|
|||
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)
|
||||
const config = buddies.find(b => b.buddy === args.buddy)
|
||||
if(!config) {
|
||||
console.error(`Whoops, you asked to let buddy "${args.buddy}" chat, but no config found? Exiting.`)
|
||||
process.exit(-1)
|
||||
|
|
|
@ -3,10 +3,12 @@
|
|||
|
||||
// which ones are active?
|
||||
const buddies = [{
|
||||
buddy: "acvillagers",
|
||||
name: "animalcrossing",
|
||||
instance: "https://mastodon.social",
|
||||
oauthToken: "my-token"
|
||||
}, {
|
||||
buddy: "gblegacy",
|
||||
name: "mobygames",
|
||||
instance: "https://botsin.space",
|
||||
oauthToken: "my-token-for-botsin-space",
|
||||
|
|
Loading…
Reference in New Issue