def execute(m, args = nil)
unless m.channel
m.reply "Use !budget in a channel"
return
end
network = bot.config.server
channel = m.channel.name
user = m.user.nick
parsed = BudgetGame.parse_command(args.to_s)
if parsed[:error]
flood_safe_reply(m, parsed[:error])
return
end
data = BudgetGame.load_player(network: network, channel: channel, user: user)
result = case parsed[:action]
when :new, :help
data = BudgetGame.new_scenario
BudgetGame.save_player(network: network, channel: channel, user: user, data: data)
{ message: BudgetGame.scenario_message(data) }
when :buy
BudgetGame.buy(data: data || {}, items_text: parsed[:items])
when :score
{ message: BudgetGame.format_score(data) }
else
{ message: BudgetGame.usage_message }
end
if result[:error]
flood_safe_reply(m, result[:error])
return
end
BudgetGame.save_player(network: network, channel: channel, user: user, data: result[:data]) if result[:data]
flood_safe_reply(m, result[:message])
end