custom_commands.rb: Syntax fixes

This commit is contained in:
Bill Niblock 2021-03-26 20:46:48 -04:00
parent 4a2490b872
commit 6416c76891

View file

@ -10,10 +10,13 @@ require 'json'
module Chronicle module Chronicle
module Addon module Addon
# Custom Commander handles all custom command management
#
# @param bot [Chronicle] The instance of Chronicle for this addon
class CustomCommander class CustomCommander
def self.register(bot) def self.register(bot)
addon_instance = new(bot) addon_instance = new(bot)
addon_command = ['addcommand','modcommand','remcommand'] addon_command = %w[addcommand modcommand remcommand]
[addon_instance, addon_command] [addon_instance, addon_command]
end end
@ -32,11 +35,11 @@ module Chronicle
cmd = message.content[:body].split(/\s+/)[1].gsub(/#{pfx}/, '') cmd = message.content[:body].split(/\s+/)[1].gsub(/#{pfx}/, '')
case cmd case cmd
when "addcommand" when 'addcommand'
cmd_add_usage cmd_add_usage
when "modcommand" when 'modcommand'
cmd_mod_usage cmd_mod_usage
when "remcommand" when 'remcommand'
cmd_rem_usage cmd_rem_usage
else else
cmd_custom_usage(cmd) cmd_custom_usage(cmd)
@ -54,18 +57,16 @@ module Chronicle
.gsub(/#{pfx}\w+\s*/, '') .gsub(/#{pfx}\w+\s*/, '')
.strip .strip
res = 'Invalid command' res = case cmd
when 'addcommand'
case cmd handle_addcommand(roomid, msgstr)
when "addcommand" when 'modcommand'
res = handle_addcommand(roomid, msgstr) handle_modcommand(roomid, msgstr)
when "modcommand" when 'remcommand'
res = handle_modcommand(roomid, msgstr) handle_remcommand(roomid, msgstr)
when "remcommand" else
res = handle_remcommand(roomid, msgstr) handle_runcommand(roomid, cmd)
else end
res = handle_runcommand(roomid, cmd)
end
room = @bot.client.ensure_room(roomid) room = @bot.client.ensure_room(roomid)
@ -211,12 +212,12 @@ module Chronicle
unless cc.save unless cc.save
@bot.scribe.info('CustomCommander') { @bot.scribe.info('CustomCommander') {
"Problem modifying: #{command}. Not saved." "Problem modifying: #{command}. Not saved."
} }
return cc.errors.objects.first.full_message return cc.errors.objects.first.full_message
end end
@bot.scribe.info('CustomCommander') { @bot.scribe.info('CustomCommander') {
"Custom command updated: #{command}" "Custom command updated: #{command}"
} }
@ -248,12 +249,12 @@ module Chronicle
unless cc.save unless cc.save
@bot.scribe.info('CustomCommander') { @bot.scribe.info('CustomCommander') {
"Duplicate command: #{command}. Not saved." "Duplicate command: #{command}. Not saved."
} }
return cc.errors.objects.first.full_message return cc.errors.objects.first.full_message
end end
@bot.scribe.info('CustomCommander') { @bot.scribe.info('CustomCommander') {
"Custom command saved: #{command}" "Custom command saved: #{command}"
} }