cryptobanky #4
50
coin.rb
50
coin.rb
@ -10,9 +10,19 @@ PASTA='You know what? Im done, i am leaving, we were friendly talking about the
|
|||||||
COIN_EMOJI = '🪙'
|
COIN_EMOJI = '🪙'
|
||||||
BAG_EMOJI = '💰'
|
BAG_EMOJI = '💰'
|
||||||
|
|
||||||
$coin_state_active = false
|
COIN_STATE_IDLE = 0
|
||||||
|
COIN_STATE_ACTIVE = 1
|
||||||
|
COIN_STATE_MATH = 2
|
||||||
|
|
||||||
|
MATH_PROBLEM_COIN_GAIN = 3
|
||||||
|
|
||||||
|
$coin_state_active = COIN_STATE_IDLE
|
||||||
$coins_offered_today = 0
|
$coins_offered_today = 0
|
||||||
|
|
||||||
|
$mathproblem_op1 = 0
|
||||||
|
$mathproblem_op2 = 0
|
||||||
|
$mathproblem_operator = "+"
|
||||||
|
|
||||||
bot = Discordrb::Bot.new token: ENV['DISCORD_TOKEN']
|
bot = Discordrb::Bot.new token: ENV['DISCORD_TOKEN']
|
||||||
|
|
||||||
def get_seconds_to_midnight(time)
|
def get_seconds_to_midnight(time)
|
||||||
@ -60,7 +70,7 @@ def clean_name(input)
|
|||||||
input.tr '@', ''
|
input.tr '@', ''
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_coin(event)
|
def get_coin(event, amt = 1)
|
||||||
# update score
|
# update score
|
||||||
author = event.methods.include?(:author) ? event.author : event.user
|
author = event.methods.include?(:author) ? event.author : event.user
|
||||||
|
|
||||||
@ -68,13 +78,13 @@ def get_coin(event)
|
|||||||
if author.bot_account?
|
if author.bot_account?
|
||||||
event.respond "Bots don't get coins!"
|
event.respond "Bots don't get coins!"
|
||||||
end
|
end
|
||||||
$coin_state_active = false
|
$coin_state_active = COIN_STATE_IDLE
|
||||||
if(rand(100) == 47)
|
if(rand(100) == 47)
|
||||||
hyper_coin_amount = rand(100)
|
hyper_coin_amount = rand(100)
|
||||||
coins = increment_coin(event.author.id, hyper_coin_amount)
|
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!"
|
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
|
else
|
||||||
coins = increment_coin(author.id)
|
coins = increment_coin(author.id, amt)
|
||||||
event.respond "Nice catch, #{clean_name author.display_name}! You have #{plural('coin', coins)} now!"
|
event.respond "Nice catch, #{clean_name author.display_name}! You have #{plural('coin', coins)} now!"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -148,17 +158,45 @@ bot.reaction_add do |event|
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# math problem
|
||||||
|
bot.message(in: Integer(ENV['BOT_CHANNEL'])) do |event|
|
||||||
|
next unless $coin_state_active == COIN_STATE_MATH
|
||||||
|
|
||||||
|
result = eval("$mathproblem_op1 #{$mathproblem_operator} $mathproblem_op2")
|
||||||
|
user_result = Integer(event.message.content) rescue false
|
||||||
|
|
||||||
|
if result == user_result
|
||||||
|
get_coin(event, MATH_PROBLEM_COIN_GAIN)
|
||||||
|
else
|
||||||
|
event.respond "Nice try, but you're wrong!"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
bot.run(true)
|
bot.run(true)
|
||||||
|
|
||||||
loop do
|
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))
|
||||||
|
if rand(6) == 1
|
||||||
|
# math problem
|
||||||
|
|
||||||
# activate coin state
|
# activate coin state
|
||||||
$coin_state_active = true
|
$coin_state_active = COIN_STATE_MATH
|
||||||
|
|
||||||
|
$mathproblem_op1 = rand(10..150)
|
||||||
|
$mathproblem_op2 = rand(10..150)
|
||||||
|
$mathproblem_operator = rand(2) == 1 ? "+" : "-"
|
||||||
|
|
||||||
|
# send the math problem
|
||||||
|
bot.send_message(ENV['BOT_CHANNEL'], "Solve the following for #{MATH_PROBLEM_COIN_GAIN} coins: `#{$mathproblem_op1} #{$mathproblem_operator} #{mathproblem_op2}`")
|
||||||
|
else
|
||||||
|
# activate coin state
|
||||||
|
$coin_state_active = COIN_STATE_ACTIVE
|
||||||
# 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
|
end
|
||||||
|
|
||||||
|
$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))
|
||||||
|
Loading…
Reference in New Issue
Block a user