def submit_guess(network:, channel:, user:, guess:, api_key:, fetch: nil, store: RabbotDb, game_store: Game.default_store)
round = GameStore.load(plugin: PLUGIN, network: network, channel: channel, store: store)
return { error: "No Name Game active — !tm game to start." } unless round
yes = guess.to_s.downcase == "yes"
if TmConfig.configured?(key: api_key)
actual = TmSearch.registered?(round["name"], api_key: api_key, fetch: fetch)
else
actual = round["registered"]
end
won = yes == actual
GameStore.clear(plugin: PLUGIN, network: network, channel: channel, store: store)
answer_word = actual ? "YES" : "NO"
outcome_style = won ? STYLE_WIN : STYLE_LOSE
outcome_word = won ? "CORRECT" : "WRONG"
lines = [
IrcFormat.report_header(tag: "TM", title: "Name Game", style: STYLE_TITLE),
"#{user} guessed #{guess} — #{round['name']} is #{answer_word}",
IrcFormat.decorate(outcome_word, outcome_style)
]
if won
Game.credit_winnings(user, DEFAULT_PRIZE, store: game_store)
balance = Game.balance_for(user, store: game_store)
lines << "Prize #{DEFAULT_PRIZE} credits — balance #{balance}"
end
lines << IrcFormat.report_footer("IP Australia")
{ message: lines.join("\n") }
end