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.
This commit is contained in:
parent
69a22c8a22
commit
22c9590816
4 changed files with 41 additions and 55 deletions
|
@ -32,22 +32,16 @@ module Chronicle
|
|||
pfx = @bot.cmd_prefix
|
||||
cmd = message.content[:body].split(/\s+/)[1].gsub(/#{pfx}/, '')
|
||||
|
||||
res = 'Invalid command'
|
||||
|
||||
case cmd
|
||||
when "addcommand"
|
||||
res = cmd_add_usage
|
||||
cmd_add_usage
|
||||
when "modcommand"
|
||||
res = cmd_mod_usage
|
||||
cmd_mod_usage
|
||||
when "remcommand"
|
||||
res = cmd_rem_usage
|
||||
cmd_rem_usage
|
||||
else
|
||||
res = cmd_custom_usage(cmd)
|
||||
cmd_custom_usage(cmd)
|
||||
end
|
||||
|
||||
room = @bot.client.ensure_room(message.room_id)
|
||||
|
||||
room.send_notice(res)
|
||||
end
|
||||
|
||||
# Handle a command from the Matrix protocol
|
||||
|
|
|
@ -17,15 +17,10 @@ module Chronicle
|
|||
|
||||
# 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 = 'Rolls dice, and provides a result'
|
||||
res += "\nUsage: !roll DICE"
|
||||
res += "\nExample: !roll 3d6"
|
||||
|
||||
room.send_notice(res)
|
||||
# @param message [Message object] The relevant message object (Unused)
|
||||
def help_command(_)
|
||||
'Rolls dice, and provides a result' \
|
||||
"\nUsage: !roll DICE\nExample: !roll 3d6"
|
||||
end
|
||||
|
||||
# Handle a command from the Matrix protocol
|
||||
|
|
|
@ -17,14 +17,10 @@ module Chronicle
|
|||
|
||||
# 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)
|
||||
# @param message [Message object] The relevant message object (Unused)
|
||||
def help_command(_)
|
||||
'Returns "Pong!"' \
|
||||
"\nUsage: !ping"
|
||||
end
|
||||
|
||||
# Handle a command from the Matrix protocol
|
||||
|
@ -52,14 +48,10 @@ module Chronicle
|
|||
|
||||
# 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)
|
||||
# @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
|
||||
|
|
|
@ -31,18 +31,25 @@ module Chronicle
|
|||
# Chronicle Bot for Matrix
|
||||
module Matrix
|
||||
# Begin the beast
|
||||
def self.start(args)
|
||||
unless args.length >= 2
|
||||
raise "Usage: #{$PROGRAM_NAME} [-d] homeserver_url access_token"
|
||||
def self.start
|
||||
unless ENV["CHRONICLE_HOMESERVER"]
|
||||
raise "Export your homeserver URL to CHRONICLE_HOMESERVER"
|
||||
end
|
||||
|
||||
if args.first == '-d'
|
||||
unless ENV["CHRONICLE_ACCESS_TOKEN"]
|
||||
raise "Export your access token to CHRONICLE_ACCESS_TOKEN"
|
||||
end
|
||||
|
||||
if ENV["CHRONICLE_DEBUG"]
|
||||
Thread.abort_on_exception = true
|
||||
MatrixSdk.debug!
|
||||
args.shift
|
||||
end
|
||||
|
||||
bot = ChronicleBot.new args[0], args[1]
|
||||
bot = ChronicleBot.new(
|
||||
ENV["CHRONICLE_HOMESERVER"],
|
||||
ENV["CHRONICLE_ACCESS_TOKEN"]
|
||||
)
|
||||
|
||||
bot.run
|
||||
end
|
||||
|
||||
|
@ -59,7 +66,7 @@ module Chronicle
|
|||
@allowed_commands = {}
|
||||
|
||||
register_commands
|
||||
available_commands(self, ['listcommands', 'help'])
|
||||
available_commands(self, %w[listcommands help])
|
||||
end
|
||||
|
||||
# All available commands
|
||||
|
@ -93,12 +100,10 @@ module Chronicle
|
|||
|
||||
case cmd
|
||||
when 'listcommands'
|
||||
res = '!listcommands: List available commands managed by this bot'
|
||||
'!listcommands: List available commands managed by this bot'
|
||||
else
|
||||
res = 'Try !listcommands or !help'
|
||||
'Try !listcommands or !help'
|
||||
end
|
||||
|
||||
res
|
||||
end
|
||||
|
||||
# Handle a command from the Matrix protocol
|
||||
|
@ -110,19 +115,19 @@ module Chronicle
|
|||
|
||||
res = 'Invalid command'
|
||||
|
||||
case cmd
|
||||
when 'listcommands'
|
||||
res = 'Currently available commands: '
|
||||
res += @all_commands.keys.join(', ')
|
||||
when 'help'
|
||||
res = if message.content[:body].split(/\s+/).count <= 1
|
||||
res = case cmd
|
||||
when 'listcommands'
|
||||
"Currently available commands: #{@all_commands.keys.sort.join(', ')}"
|
||||
when 'help'
|
||||
if message.content[:body].split(/\s+/).count <= 1
|
||||
'!help: Get help for a specific command' \
|
||||
"\nUsage: !help COMMAND"
|
||||
else
|
||||
second_cmd = message.content[:body].split(/\s+/)[1].gsub(/#{pfx}/, '')
|
||||
res = @all_commands[second_cmd.strip].help_command(message)
|
||||
second_cmd = message.content[:body].split(/\s+/)[1]
|
||||
.gsub(/#{pfx}/, '')
|
||||
@all_commands[second_cmd.strip].help_command(message)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
room = @client.ensure_room(message.room_id)
|
||||
room.send_notice(res)
|
||||
|
|
Loading…
Reference in a new issue