def self.dispatch_command(args_text, user: nil, fetch: nil, network: nil, channel: nil, store: RabbotDb, channel_users: [])
parsed = parse_command(args_text)
return { error: parsed[:error] } if parsed[:error]
return { reply: help_reply } if parsed[:action] == :help
case parsed[:action]
when :population
{ reply: AbsPopulation.format_population(parsed[:city], fetch: fetch) }
when :showdown
return { error: "Use !abs showdown in a channel." } unless network && channel
game = AsyncDuelHandler.load(AbsShowdown::PLUGIN, network, channel, store)
unless %i[guess].include?(parsed[:sub][:action])
handled = AsyncDuelHandler.handle(
game_mod: AbsShowdown,
plugin: AbsShowdown::PLUGIN,
network: network,
channel: channel,
game: game,
parsed: parsed[:sub],
user: user.to_s,
channel_users: channel_users
)
unless handled[:passthrough]
AsyncDuelHandler.clear(AbsShowdown::PLUGIN, network, channel, store) if handled[:cleared]
return handled[:error] ? { error: handled[:error] } : { reply: handled[:message] }
end
end
result = case parsed[:sub][:action]
when :guess
AbsShowdown.submit_guess(game: game, user: user.to_s, value: parsed[:sub][:value])
else
{ message: AbsShowdown.usage_message }
end
return { error: result[:error] } if result[:error]
if result[:game]
if result[:done]
AsyncDuelHandler.clear(AbsShowdown::PLUGIN, network, channel, store)
else
AsyncDuelHandler.save(AbsShowdown::PLUGIN, network, channel, result[:game], store)
end
end
{ reply: result[:message] }
else
{ reply: help_reply }
end
end