def self.dispatch(args_text, network:, channel:, admin_allowed:, store: RabbotDb)
parsed = LolcatCommand.parse(args_text)
return { error: parsed[:error] } if parsed[:error]
case parsed[:action]
when :help
{ reply: LolcatReport.help }
when :status
state = LolcatStore.load_state(network: network, channel: channel, store: store)
{ reply: LolcatReport.status(state: state) }
when :on
return { error: LolcatReport.denial } unless admin_allowed
LolcatStore.set_enabled!(true, network: network, channel: channel, store: store)
{ reply: LolcatReport.toggle_reply(enabled: true) }
when :off
return { error: LolcatReport.denial } unless admin_allowed
LolcatStore.set_enabled!(false, network: network, channel: channel, store: store)
{ reply: LolcatReport.toggle_reply(enabled: false) }
when :reset
return { error: LolcatReport.denial } unless admin_allowed
LolcatStore.reset!(network: network, channel: channel, store: store)
{ reply: LolcatReport.options_reply(argv: []) }
when :options
return { error: LolcatReport.denial } unless admin_allowed
LolcatStore.set_argv!(parsed[:argv], network: network, channel: channel, store: store)
{ reply: LolcatReport.options_reply(argv: parsed[:argv]) }
when :preview
state = LolcatStore.load_state(network: network, channel: channel, store: store)
{ reply: LolcatReport.preview(text: parsed[:text], argv: state[:argv]) }
else
{ error: LolcatCommand.usage_message }
end
end