From 3b2586bac136086eb0cb1e577270a09549dc9101 Mon Sep 17 00:00:00 2001 From: fred Date: Tue, 11 Oct 2022 13:24:06 +0200 Subject: [PATCH] naive fradulent activity punishment --- coin.rb | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/coin.rb b/coin.rb index 4c803d7..5f0fd83 100644 --- a/coin.rb +++ b/coin.rb @@ -30,22 +30,37 @@ def get_coin_count(scoreboard, user) scoreboard[user] || 0 end -def increment_coin(scoreboard, user) +def increment_coin(user) + scoreboard = load_scoreboard() coins = get_coin_count(scoreboard, user) + 1 scoreboard[user] = coins File.write(SCOREBOARD, scoreboard.to_yaml) end +def empty_coin(user) + scoreboard = load_scoreboard() + scoreboard[user] = 0 + + File.write(SCOREBOARD, scoreboard.to_yaml) +end + def plural(string, count) "#{count} #{string}#{count != 1 ? 's' : ''}" end -bot.message(with_text: 'GET COIN' ) do |event| +bot.message(in: Integer(ENV['BOT_CHANNEL'])) do |event| + puts event.message + if event.message.attachments.count { |x| x.filename.scan(/coin*/).length > 0 } > 0 + event.respond "Oh no! Looks like you tried to post a fradulent coin! #{event.author.name}, your coin balance has now been emptied. Let that be a lesson for next time!" + empty_coin(event.author.id) + end +end + +bot.message(content: 'GET COIN' ) do |event| # update score if coin_state_active - scoreboard = load_scoreboard() - increment_coin(scoreboard, event.author.id) + increment_coin(event.author.id) coin_state_active = false