def execute(m, args = nil)
unless m.channel
m.reply "Use !rpg in a channel"
return
end
network = bot.config.server
channel = m.channel.name
user = m.user.nick
parsed = RpgGame.parse_command(args.to_s)
if parsed[:error]
themed_flood_safe_reply(m, parsed[:error])
return
end
data = RpgGame.load_player(network: network, channel: channel, user: user)
result = case parsed[:action]
when :start, :help
data = RpgGame.new_game
RpgGame.save_player(network: network, channel: channel, user: user, data: data)
{ message: RpgGame.format_room(data) }
when :choose
RpgGame.choose(data: data || RpgGame.new_game, choice: parsed[:choice])
when :status
{ message: data ? RpgGame.format_room(data) : RpgGame.usage_message }
else
{ message: RpgGame.usage_message }
end
if result[:error]
themed_flood_safe_reply(m, result[:error])
return
end
RpgGame.save_player(network: network, channel: channel, user: user, data: result[:data]) if result[:data]
themed_flood_safe_reply(m, result[:message])
end