chronicle_bot/lib/addons/utils.rb
Bill Niblock 22c9590816 Update help_command logic
The `help_command` method for each addon/the bot were not returning the
help message, but were instead sending the help messages themselves.
Update the logic to simply return the help message string.
2021-02-16 23:13:46 -05:00

98 lines
2.5 KiB
Ruby

# frozen_string_literal: true
module Chronicle
module Addon
# Ping - Pong. Useful for testing
class Ping
def self.register(bot)
addon_instance = new(bot)
addon_command = ['ping']
[addon_instance, addon_command]
end
def initialize(bot)
@bot = bot
end
# Provide help information for this command
#
# @param message [Message object] The relevant message object (Unused)
def help_command(_)
'Returns "Pong!"' \
"\nUsage: !ping"
end
# Handle a command from the Matrix protocol
#
# @param message [Message object] The relevant message object
def matrix_command(message)
room = @bot.client.ensure_room(message.room_id)
room.send_notice('Pong!')
end
end
# 8-Ball: Give a random, vague response to a question
class Eightball
def self.register(bot)
addon_instance = new(bot)
addon_command = ['8ball']
[addon_instance, addon_command]
end
def initialize(bot)
@bot = bot
end
# Provide help information for this command
#
# @param message [Message object] The relevant message object (Unused)
def help_command(_)
'Questions the fates to determine an answer for your question.' \
"\nUsage: !8ball QUESTION"
end
# Handle a command from the Matrix protocol
#
# @param message [Message object] The relevant message object
def matrix_command(message)
msgstr = message.content[:body]
.gsub(/!8ball\s*/, '')
.strip
room = @bot.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
end