Both `!help` and `!listcommand` are handled by the bot itself, so take advantage of how the addons method calls work to implement both `matrix_command` and `help_command` on `self`. Add `help_command` to each currently enabled and functional addon
106 lines
2.7 KiB
Ruby
106 lines
2.7 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
|
|
def help_command(message)
|
|
room = @bot.client.ensure_room(message.room_id)
|
|
|
|
res = 'Returns "Pong!"'
|
|
res += "\nUsage: !ping"
|
|
|
|
room.send_notice(res)
|
|
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
|
|
def help_command(message)
|
|
room = @bot.client.ensure_room(message.room_id)
|
|
|
|
res = 'Questions the fates to determine an answer for your question.'
|
|
res += "\nUsage: !8ball QUESTION"
|
|
|
|
room.send_notice(res)
|
|
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
|