Add 8ball command

This commit is contained in:
Bill Niblock 2021-02-07 20:45:54 -05:00
parent 18f56be754
commit faa62604ef
2 changed files with 44 additions and 2 deletions

View file

@ -12,13 +12,13 @@ productive fellow.
- Ping (returns Pong!; good for testing connectivity)
- Dice Roller (`!roll 2d4` -> `Roll: 2d4 ([2, 1]) ==> 3`)
- 8-ball (`!8ball Will I win the lottery?` --> `Try again later`)
- More to come!
## Planned Features
- [ ] Ad-hoc simple custom commands (`!addcommand hello Hey there!` --> `!hello` -->
`Hey there!`)
- [ ] 8-ball (`!8ball Will I win the lottery?` --> `Try again later`)
- [ ] Simple calculator (`!calc 8 + (9-10)` --> `Calc: 8 + (9 - 10) ==> 7`)
- [ ] Simple games (Blackjack, High/Low)
- [ ] A "mystery" game (Kind of like _Clue!_ or _Noir Syndrome_)
@ -40,6 +40,7 @@ You can run your own instance of Chronicle with a few steps:
5. Run `bundle exec chronicle -d <your-homeserver-address-here>
CHRONICLE_ACCESS_TOKEN`
6. Invite the bot user to a room, and `!ping` to make sure it's working!
7. Update the `allowed_commands` variable to add additional commands (for now).
# Contribute

View file

@ -8,8 +8,49 @@ module Chronicle
# @param message [Message object] The relevant message object
def handle_ping(client, message)
room = client.ensure_room message.room_id
room.send_notice('Pong!')
end
# 8-Ball: Give a random, vague response to a question
#
# @param client [Client object] The current Matrix client connection
# @param message [Message object] The relevant message object
def handle_8ball(client, message)
msgstr = message.content[:body]
.gsub(/!8ball\s*/, '')
.strip
room = client.ensure_room(message.room_id)
fates = [
'Resoundingly, yes.',
'Chances are good.',
'Signs point to yes.',
'Wheel.',
'It is worth the attempt.',
'Uncertainty clouds my sight.',
'Wheel and woe.',
'Neither wheel nor woe.',
'Concentrate, and ask again.',
'I cannot say for sure.',
'The fates do not know.',
"Why are you asking me? I'm just a bot.",
'Error: Fate API returned 404. Try again later.',
'Woe.',
'Chances are poor.',
'Signs point to no.',
'Very doubtful.',
'Absolutely no.'
]
res = if msgstr[-1] == '?'
fates.sample
else
'You must ask a question. Try again'
end
room.send_notice(res)
end
end
end