Compare commits
No commits in common. "main" and "7d987643d7f696caffb3049a580e1133d674fa06" have entirely different histories.
main
...
7d987643d7
190
coin.rb
190
coin.rb
@ -2,26 +2,9 @@ require 'dotenv/load'
|
|||||||
require 'yaml'
|
require 'yaml'
|
||||||
require 'discordrb'
|
require 'discordrb'
|
||||||
|
|
||||||
|
|
||||||
MAX_COINS_PER_DAY = 999
|
|
||||||
COIN_TIMEOUT = 15
|
COIN_TIMEOUT = 15
|
||||||
SCOREBOARD = './scoreboard.yml'
|
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"'
|
coin_state_active = false
|
||||||
COIN_EMOJI = '🪙'
|
|
||||||
BAG_EMOJI = '💰'
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
$mathproblem_op1 = 0
|
|
||||||
$mathproblem_op2 = 0
|
|
||||||
$mathproblem_operator = "+"
|
|
||||||
|
|
||||||
bot = Discordrb::Bot.new token: ENV['DISCORD_TOKEN']
|
bot = Discordrb::Bot.new token: ENV['DISCORD_TOKEN']
|
||||||
|
|
||||||
@ -30,180 +13,63 @@ def get_seconds_to_midnight(time)
|
|||||||
return t2 - time
|
return t2 - time
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_random_hours(min, max)
|
def get_random_duration(time)
|
||||||
min_hours = min * 60 * 60
|
max = get_seconds_to_midnight(time)
|
||||||
max_hours = max * 60* 60
|
return rand(0..max)
|
||||||
return rand(min_hours..max_hours)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_scoreboard()
|
def load_scoreboard()
|
||||||
YAML::load_file(SCOREBOARD) || {}
|
YAML::load_file(SCOREBOARD) || {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_coin_count(user)
|
def get_coin_count(scoreboard, user)
|
||||||
scoreboard = load_scoreboard()
|
|
||||||
scoreboard[user] || 0
|
scoreboard[user] || 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def increment_coin(user, amount=1)
|
def increment_coin(scoreboard, user)
|
||||||
scoreboard = load_scoreboard()
|
coins = get_coin_count(scoreboard, user) + 1
|
||||||
coins = get_coin_count(user) + amount
|
|
||||||
scoreboard[user] = coins
|
scoreboard[user] = coins
|
||||||
|
|
||||||
File.write(SCOREBOARD, scoreboard.to_yaml)
|
File.write(SCOREBOARD, scoreboard.to_yaml)
|
||||||
|
|
||||||
return coins
|
|
||||||
end
|
|
||||||
|
|
||||||
def empty_coin(user)
|
|
||||||
scoreboard = load_scoreboard()
|
|
||||||
scoreboard[user] = 0
|
|
||||||
|
|
||||||
File.write(SCOREBOARD, scoreboard.to_yaml)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def plural(string, count)
|
def plural(string, count)
|
||||||
"#{count} #{string}#{count != 1 ? 's' : ''}"
|
"#{count} #{string}#{count > 1 ? 's' : ''}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def clean_name(input)
|
bot.message(with_text: 'GET COIN' ) do |event|
|
||||||
input.tr '@', ''
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_coin(event, amt = 1)
|
|
||||||
# update score
|
# update score
|
||||||
author = event.methods.include?(:author) ? event.author : event.user
|
if coin_state_active
|
||||||
|
scoreboard = load_scoreboard()
|
||||||
|
increment_coin(scoreboard, event.author.id)
|
||||||
|
|
||||||
if $coin_state_active != 0
|
coin_state_active = false
|
||||||
if author.bot_account?
|
|
||||||
event.respond "Bots don't get coins!"
|
coins = get_coin_count(scoreboard, event.author.id)
|
||||||
end
|
event.respond "Nice catch, #{event.author.name}! You have #{plural('coin', coins)} now!"
|
||||||
$coin_state_active = COIN_STATE_IDLE
|
|
||||||
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, amt)
|
|
||||||
event.respond "Nice catch, #{clean_name author.display_name}! You have #{plural('coin', coins)} now!"
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
event.respond "No coins for you, #{clean_name author.display_name}!"
|
event.respond "No coins for you, #{event.author.name}!"
|
||||||
end
|
end
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
coin_amount = 0
|
|
||||||
if event.emoji.name == COIN_EMOJI
|
|
||||||
coin_amount = 1
|
|
||||||
elsif event.emoji.name == BAG_EMOJI
|
|
||||||
coin_amount = 5
|
|
||||||
end
|
|
||||||
|
|
||||||
if reactor_coins < coin_amount
|
|
||||||
coin_amount = reactor_coins
|
|
||||||
end
|
|
||||||
|
|
||||||
increment_coin(event.message.author.id, coin_amount)
|
|
||||||
increment_coin(event.user.id, -coin_amount)
|
|
||||||
|
|
||||||
event.respond "How nice! <@#{event.message.author.id}> has received #{plural('coin', coin_amount)} from <@#{event.user.id}>!"
|
|
||||||
end
|
|
||||||
|
|
||||||
bot.message(in: Integer(ENV['BOT_CHANNEL'])) do |event|
|
|
||||||
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!"
|
|
||||||
empty_coin(event.author.id)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
bot.message(content: 'GET COIN' ) do |event|
|
|
||||||
get_coin(event)
|
|
||||||
end
|
|
||||||
|
|
||||||
bot.message(with_text: '/coins') do |event|
|
bot.message(with_text: '/coins') do |event|
|
||||||
coins = get_coin_count(event.author.id)
|
coins = get_coin_count(load_scoreboard(), event.author.id)
|
||||||
event.respond "#{clean_name event.author.display_name}, you have #{plural('coin', coins)}!"
|
event.respond "#{event.author.name}, you have #{plural('coin', coins)}!"
|
||||||
end
|
|
||||||
|
|
||||||
bot.message(with_text: '!leave') do |event|
|
|
||||||
event.respond PASTA
|
|
||||||
end
|
|
||||||
|
|
||||||
bot.message(with_text: 'boobs', in: Integer(ENV['CUM_CHANNEL'])) do |event|
|
|
||||||
next if not ENV['CUM_CHANNEL']
|
|
||||||
event.respond "# OHHHHHH IM GONNA CUM"
|
|
||||||
end
|
|
||||||
|
|
||||||
bot.reaction_add do |event|
|
|
||||||
next unless [COIN_EMOJI, BAG_EMOJI].include? event.emoji.name
|
|
||||||
|
|
||||||
if event.message.author.id == bot.bot_application.id
|
|
||||||
get_coin(event)
|
|
||||||
else
|
|
||||||
give_coin(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)
|
|
||||||
elsif user_result.is_a? Integer
|
|
||||||
event.respond "Nice try, but you're wrong!"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
bot.run(true)
|
bot.run(true)
|
||||||
|
|
||||||
loop do
|
loop do
|
||||||
# sleep random amount of time between 1 and 4 hours
|
# sleep until random time from now to midnight
|
||||||
sleep(get_random_hours(1, 4))
|
# sleep(get_random_duration(Time.now))
|
||||||
if rand(6) == 1
|
|
||||||
# math problem
|
|
||||||
|
|
||||||
# activate coin state
|
# activate coin state
|
||||||
$coin_state_active = COIN_STATE_MATH
|
coin_state_active = true
|
||||||
|
# send coin GIF
|
||||||
|
bot.send_file(ENV['BOT_CHANNEL'], File.open('./coin.gif', 'r'))
|
||||||
|
|
||||||
$mathproblem_op1 = rand(10..150)
|
# sleep until midnight to reset cycle
|
||||||
$mathproblem_op2 = rand(10..150)
|
sleep(get_seconds_to_midnight(Time.now))
|
||||||
$mathproblem_operator = rand(2) == 1 ? "+" : "-"
|
|
||||||
|
|
||||||
# send the math problem
|
|
||||||
bot.send_file(ENV['BOT_CHANNEL'], File.open('./block.gif', 'r'))
|
|
||||||
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
|
|
||||||
bot.send_file(ENV['BOT_CHANNEL'], File.open('./coin.gif', 'r'))
|
|
||||||
end
|
|
||||||
|
|
||||||
$coins_offered_today += 1
|
|
||||||
# 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_random_hours(5, 11))
|
|
||||||
$coins_offered_today = 0
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
bot.join()
|
bot.join()
|
||||||
|
Loading…
Reference in New Issue
Block a user