def execute(m, args = nil)
unless m.channel
m.reply "Use !pitch in a channel"
return
end
network = bot.config.server
channel = m.channel.name
user = m.user.nick
parsed = PitchGame.parse_command(args.to_s)
game = AsyncDuelHandler.load(PitchGame::PLUGIN, network, channel, RabbotDb)
if parsed[:error]
themed_flood_safe_reply(m, parsed[:error])
return
end
unless %i[pitch vote].include?(parsed[:action])
handled = AsyncDuelHandler.handle(
game_mod: PitchGame,
plugin: PitchGame::PLUGIN,
network: network,
channel: channel,
game: game,
parsed: parsed,
user: user,
channel_users: m.channel.users.keys
)
unless handled[:passthrough]
themed_flood_safe_reply(m, handled[:message] || handled[:error])
AsyncDuelHandler.clear(PitchGame::PLUGIN, network, channel, RabbotDb) if handled[:cleared]
return
end
end
result = case parsed[:action]
when :pitch
PitchGame.submit_pitch(game: game, user: user, text: parsed[:text])
when :vote
PitchGame.submit_vote(game: game, user: user, choice: parsed[:choice])
else
{ message: PitchGame.usage_message }
end
if result[:error]
themed_flood_safe_reply(m, result[:error])
return
end
AsyncDuelHandler.save(PitchGame::PLUGIN, network, channel, result[:game], RabbotDb) if result[:game]
themed_flood_safe_reply(m, result[:message])
end