forked from mud/bankerbot-rb
offer coin up to a max, between 1 and 4 hours
This commit is contained in:
parent
6b586596ae
commit
ed0f5d33e7
24
coin.rb
24
coin.rb
@ -2,9 +2,12 @@ require 'dotenv/load'
|
|||||||
require 'yaml'
|
require 'yaml'
|
||||||
require 'discordrb'
|
require 'discordrb'
|
||||||
|
|
||||||
|
|
||||||
|
MAX_COINS_PER_DAY = 3
|
||||||
COIN_TIMEOUT = 15
|
COIN_TIMEOUT = 15
|
||||||
SCOREBOARD = './scoreboard.yml'
|
SCOREBOARD = './scoreboard.yml'
|
||||||
coin_state_active = false
|
coin_state_active = false
|
||||||
|
coins_offered_today = 0
|
||||||
|
|
||||||
bot = Discordrb::Bot.new token: ENV['DISCORD_TOKEN']
|
bot = Discordrb::Bot.new token: ENV['DISCORD_TOKEN']
|
||||||
|
|
||||||
@ -13,9 +16,10 @@ def get_seconds_to_midnight(time)
|
|||||||
return t2 - time
|
return t2 - time
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_random_duration(time)
|
def get_random_hours(min, max)
|
||||||
max = get_seconds_to_midnight(time)
|
min_hours = min * 60 * 60
|
||||||
return rand(0..max)
|
max_hours = max * 60* 60
|
||||||
|
return rand(min_hours..max_hours)
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_scoreboard()
|
def load_scoreboard()
|
||||||
@ -62,14 +66,20 @@ bot.run(true)
|
|||||||
loop do
|
loop do
|
||||||
# activate coin state
|
# activate coin state
|
||||||
coin_state_active = true
|
coin_state_active = true
|
||||||
|
|
||||||
|
# sleep random amount of time between 1 and 4 hours
|
||||||
|
sleep(get_random_hours(1, 4))
|
||||||
|
|
||||||
# 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
|
||||||
|
sleep(1)
|
||||||
|
|
||||||
# sleep until midnight to reset cycle
|
# if max coins per day has reached, sleep until midnight
|
||||||
|
if coins_offered_today >= MAX_COINS_PER_DAY
|
||||||
sleep(get_seconds_to_midnight(Time.now))
|
sleep(get_seconds_to_midnight(Time.now))
|
||||||
#
|
coins_offered_today = 0
|
||||||
# sleep until random time from now to next midnight
|
end
|
||||||
sleep(get_random_duration(Time.now))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
bot.join()
|
bot.join()
|
||||||
|
Loading…
Reference in New Issue
Block a user