forked from mud/bankerbot-rb
Merge pull request 'prevent coin gifting to coinbot' (#3) from feature/stop-coinbot-gifting into main
Reviewed-on: mud/bankerbot-rb#3
This commit is contained in:
commit
8245932e33
88
coin.rb
88
coin.rb
@ -9,8 +9,8 @@ SCOREBOARD = './scoreboard.yml'
|
|||||||
PASTA='You know what? Im done, i am leaving, we were friendly talking about the subject. This crossed the line of "ok killer of joy" to "no fun allowed"'
|
PASTA='You know what? Im done, i am leaving, we were friendly talking about the subject. This crossed the line of "ok killer of joy" to "no fun allowed"'
|
||||||
COIN_EMOJI = '🪙'
|
COIN_EMOJI = '🪙'
|
||||||
|
|
||||||
coin_state_active = false
|
$coin_state_active = false
|
||||||
coins_offered_today = 0
|
$coins_offered_today = 0
|
||||||
|
|
||||||
bot = Discordrb::Bot.new token: ENV['DISCORD_TOKEN']
|
bot = Discordrb::Bot.new token: ENV['DISCORD_TOKEN']
|
||||||
|
|
||||||
@ -59,6 +59,46 @@ def clean_name(input)
|
|||||||
input.tr '@', ''
|
input.tr '@', ''
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_coin(event)
|
||||||
|
# update score
|
||||||
|
author = event.methods.include?(:author) ? event.author : event.user
|
||||||
|
|
||||||
|
if $coin_state_active
|
||||||
|
if author.bot_account?
|
||||||
|
event.respond "Bots don't get coins!"
|
||||||
|
end
|
||||||
|
$coin_state_active = false
|
||||||
|
if(rand(100) == 47)
|
||||||
|
hyper_coin_amount = rand(100)
|
||||||
|
coins = increment_coin(event.author.id, hyper_coin_amount)
|
||||||
|
event.respond "What astounding luck!!! #{clean_name author.display_name}, you've just activated HYPER COIN EVENT and have received #{hyper_coin_amount} coins for a grand total of #{coins} coins!"
|
||||||
|
else
|
||||||
|
coins = increment_coin(author.id)
|
||||||
|
event.respond "Nice catch, #{clean_name author.display_name}! You have #{plural('coin', coins)} now!"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
event.respond "No coins for you, #{clean_name author.display_name}!"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def give_coin(event)
|
||||||
|
reactor_coins = get_coin_count(event.user.id)
|
||||||
|
if reactor_coins == 0
|
||||||
|
event.respond("Nice gesture, <@#{event.user.id}>, but you're broke! To get more coins, type the words `GET COIN` whenever I post the coin event message! But be quick, your friends are trying their best to get it before you do!")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if event.message.author == event.user
|
||||||
|
event.respond("<@#{event.user.id}>, you can't give coins to yourself!")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
increment_coin(event.message.author.id)
|
||||||
|
increment_coin(event.user.id, -1)
|
||||||
|
|
||||||
|
event.respond "How nice! <@#{event.message.author.id}> has received a coin from <@#{event.user.id}>!"
|
||||||
|
end
|
||||||
|
|
||||||
bot.message(in: Integer(ENV['BOT_CHANNEL'])) do |event|
|
bot.message(in: Integer(ENV['BOT_CHANNEL'])) do |event|
|
||||||
if event.message.attachments.count { |x| x.filename.scan(/coin*/).length > 0 } > 0
|
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! #{clean_name event.author.display_name}, your coin balance has now been emptied. Let that be a lesson for next time!"
|
event.respond "Oh no! Looks like you tried to post a fradulent coin! #{clean_name event.author.display_name}, your coin balance has now been emptied. Let that be a lesson for next time!"
|
||||||
@ -67,23 +107,7 @@ bot.message(in: Integer(ENV['BOT_CHANNEL'])) do |event|
|
|||||||
end
|
end
|
||||||
|
|
||||||
bot.message(content: 'GET COIN' ) do |event|
|
bot.message(content: 'GET COIN' ) do |event|
|
||||||
# update score
|
get_coin(event)
|
||||||
if coin_state_active
|
|
||||||
if event.author.bot_account?
|
|
||||||
event.respond "Bots don't get coins!"
|
|
||||||
end
|
|
||||||
coin_state_active = false
|
|
||||||
if(rand(100) == 47)
|
|
||||||
hyper_coin_amount = rand(100)
|
|
||||||
coins = increment_coin(event.author.id, hyper_coin_amount)
|
|
||||||
event.respond "What astounding luck!!! #{clean_name event.author.display_name}, you've just activated HYPER COIN EVENT and have received #{hyper_coin_amount} coins for a grand total of #{coins} coins!"
|
|
||||||
else
|
|
||||||
coins = increment_coin(event.author.id)
|
|
||||||
event.respond "Nice catch, #{clean_name event.author.display_name}! You have #{plural('coin', coins)} now!"
|
|
||||||
end
|
|
||||||
else
|
|
||||||
event.respond "No coins for you, #{clean_name event.author.display_name}!"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
bot.message(with_text: '/coins') do |event|
|
bot.message(with_text: '/coins') do |event|
|
||||||
@ -102,21 +126,13 @@ end
|
|||||||
|
|
||||||
bot.reaction_add do |event|
|
bot.reaction_add do |event|
|
||||||
next unless event.emoji.name == COIN_EMOJI
|
next unless event.emoji.name == COIN_EMOJI
|
||||||
reactor_coins = get_coin_count(event.user.id)
|
|
||||||
if reactor_coins == 0
|
if event.message.author.id == bot.bot_application.id
|
||||||
event.respond("Nice gesture, <@#{event.user.id}>, but you're broke! To get more coins, type the words `GET COIN` whenever I post the coin event message! But be quick, your friends are trying their best to get it before you do!")
|
get_coin(event)
|
||||||
next
|
else
|
||||||
|
give_coin(event)
|
||||||
end
|
end
|
||||||
|
|
||||||
if event.message.author == event.user
|
|
||||||
event.respond("<@#{event.user.id}>, you can't give coins to yourself!")
|
|
||||||
next
|
|
||||||
end
|
|
||||||
|
|
||||||
increment_coin(event.message.author.id)
|
|
||||||
increment_coin(event.user.id, -1)
|
|
||||||
|
|
||||||
event.respond "How nice! <@#{event.message.author.id}> has received a coin from <@#{event.user.id}>!"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
bot.run(true)
|
bot.run(true)
|
||||||
@ -125,16 +141,16 @@ loop do
|
|||||||
# sleep random amount of time between 1 and 4 hours
|
# sleep random amount of time between 1 and 4 hours
|
||||||
sleep(get_random_hours(1, 4))
|
sleep(get_random_hours(1, 4))
|
||||||
# activate coin state
|
# activate coin state
|
||||||
coin_state_active = true
|
$coin_state_active = true
|
||||||
# send coin GIF
|
# send coin GIF
|
||||||
bot.send_file(ENV['BOT_CHANNEL'], File.open('./coin.gif', 'r'))
|
bot.send_file(ENV['BOT_CHANNEL'], File.open('./coin.gif', 'r'))
|
||||||
coins_offered_today += 1
|
$coins_offered_today += 1
|
||||||
|
|
||||||
# if max coins per day has reached, sleep until midnight
|
# if max coins per day has reached, sleep until midnight
|
||||||
if coins_offered_today >= MAX_COINS_PER_DAY
|
if $coins_offered_today >= MAX_COINS_PER_DAY
|
||||||
sleep(get_seconds_to_midnight(Time.now))
|
sleep(get_seconds_to_midnight(Time.now))
|
||||||
sleep(get_random_hours(5, 11))
|
sleep(get_random_hours(5, 11))
|
||||||
coins_offered_today = 0
|
$coins_offered_today = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user