def handle(game_mod:, plugin:, network:, channel:, game:, parsed:, user:, channel_users:, rand: ->(max) { Random.rand(0...max) }, store: RabbotDb)
case parsed[:action]
when :help
{ message: game_mod.usage_message }
when :challenge
return { error: "A game is already active here." } if game && game["stage"] != "done"
result = AsyncDuel.challenge(
game: game,
challenger: user,
target: parsed[:target],
channel_users: channel_users
)
return result if result[:error]
save(plugin, network, channel, result[:game], store)
target = result[:game]["target"]
{ message: "#{user} challenges #{target} — !#{plugin} accept or decline" }
when :accept
result = AsyncDuel.accept(game: game, user: user)
return result if result[:error]
started = start_active(game_mod, result[:game], rand: rand)
save(plugin, network, channel, started[:game], store)
{ message: started[:message] }
when :decline
result = AsyncDuel.decline(game: game, user: user)
return result if result[:error]
clear(plugin, network, channel, store)
{ message: "Challenge declined.", cleared: true }
when :status
{ message: game_mod.format_status(game) }
else
{ passthrough: true }
end
end