2022-02-04 18:48:09 -05:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
require 'bundler/setup'
|
|
|
|
require 'discordrb'
|
|
|
|
require 'yaml'
|
|
|
|
require 'mimemagic'
|
|
|
|
require 'down'
|
|
|
|
require 'fileutils'
|
|
|
|
require 'time'
|
|
|
|
require 'logger'
|
|
|
|
require 'astro/moon'
|
|
|
|
require './folder.rb'
|
|
|
|
|
|
|
|
logger = Logger.new(STDOUT)
|
|
|
|
logger.level = Logger::INFO
|
|
|
|
|
|
|
|
config_obj = YAML::load_file( './config.yaml' )
|
|
|
|
logger.info("loaded config")
|
|
|
|
bot = Discordrb::Commands::CommandBot.new token: config_obj["bot_token"], prefix: "!folder"
|
|
|
|
folder = Folder.new
|
|
|
|
config_obj['steves'].each do |steve|
|
|
|
|
folder.add_steve(steve)
|
|
|
|
end
|
|
|
|
|
|
|
|
bot.message(private: true,contains: "!folder fall") do |event|
|
|
|
|
if folder.steve?(event.user)
|
|
|
|
folder.curse(event.user)
|
|
|
|
mem = bot.member(config_obj['server_id'],event.user.id)
|
|
|
|
mem.set_nick("Geoff","This Steve has seperated himself from the Ideal Steve")
|
|
|
|
event.respond("May Snen have Mercy on your Soul")
|
|
|
|
else
|
|
|
|
event.respond("Oh that you could be so blessed as to have that option")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
bot.message(private: true,contains: "!folder rise") do |event|
|
|
|
|
if folder.steve?(event.user)
|
|
|
|
folder.bless(event.user)
|
|
|
|
mem = bot.member(config_obj['server_id'],event.user.id)
|
|
|
|
mem.set_nick("","Steve-ness restored")
|
|
|
|
event.respond("Welcome back to the winning team")
|
|
|
|
else
|
|
|
|
event.respond("Fat chance, non-Steve")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
bot.message(private: true, contains: "!folder help") do |event|
|
2022-02-05 15:32:14 -05:00
|
|
|
event.respond("Commands: rise,fall,help,status")
|
|
|
|
end
|
|
|
|
|
|
|
|
bot.message(private: true, contains: "!folder status") do |event|
|
|
|
|
event.respond("Stevefolder has #{folder.num_subs} submissions")
|
2022-02-04 18:48:09 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
bot.message(private: true) do |event|
|
2022-02-05 15:47:00 -05:00
|
|
|
sender = event.author.id
|
2022-02-04 18:48:09 -05:00
|
|
|
i = 1
|
|
|
|
event.message.attachments.each do |file|
|
|
|
|
res = MimeMagic.by_path(file.filename)
|
|
|
|
if res != nil
|
|
|
|
if res.image? or res.video?
|
|
|
|
download = Down.download(file.url)
|
|
|
|
FileUtils.mv(download.path, "./spool/#{download.original_filename}")
|
|
|
|
folder.submit(Submission.new("./spool/#{download.original_filename}",true,sender))
|
|
|
|
event.respond("Submission #{i} accepted")
|
|
|
|
i = i + 1
|
|
|
|
else
|
|
|
|
event.respond("File type #{res} not supported yet")
|
|
|
|
end
|
|
|
|
else
|
|
|
|
event.respond("Submission denied; attached file but I can't figure out the file type")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
urls = URI.extract(event.content)
|
|
|
|
urls.each do |url|
|
|
|
|
mime_guess = MimeMagic.by_extension(url)
|
|
|
|
if mime_guess != nil
|
|
|
|
if mime_guess.image? or mime_guess.video?
|
|
|
|
download = Down.download(file.url)
|
|
|
|
FileUtils.mv(download.path, "./spool/#{download.original_filename}")
|
|
|
|
folder.submit(Submission.new("./spool/#{download.original_filename}",true,sender))
|
|
|
|
end
|
|
|
|
else
|
|
|
|
folder.submit(Submission.new(url,false,sender))
|
|
|
|
end
|
|
|
|
event.respond("Submission #{i} accepted")
|
|
|
|
i= i+1
|
|
|
|
end
|
2022-02-05 15:32:14 -05:00
|
|
|
folder.update()
|
2022-02-04 18:48:09 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-02-07 12:33:52 -05:00
|
|
|
logger.info("Logging into discord")
|
2022-02-04 18:48:09 -05:00
|
|
|
bot.run(true)
|
2022-02-07 12:33:52 -05:00
|
|
|
logger.info("Starting bot main loop")
|
2022-02-04 18:48:09 -05:00
|
|
|
loop do
|
|
|
|
timer = Astro::Moon.phase.phase * (3600 * (1 + rand(3)))
|
|
|
|
logger.info("sleeping for #{timer} seconds")
|
|
|
|
sleep timer
|
|
|
|
t = Time.new
|
2022-02-04 19:22:06 -05:00
|
|
|
if t.hour < 9 and t.hour > 2
|
|
|
|
logger.info("skipping send cuz it's late")
|
2022-02-04 18:48:09 -05:00
|
|
|
next
|
|
|
|
end
|
|
|
|
sid,msg = folder.harass_steve()
|
|
|
|
if msg == nil
|
|
|
|
logger.info("no submissions ready")
|
|
|
|
next
|
|
|
|
end
|
2022-02-11 16:33:17 -05:00
|
|
|
steve = bot.user(sid)
|
2022-02-07 10:37:01 -05:00
|
|
|
if steve == nil
|
|
|
|
logger.warn("Tried to get Steve #{sid} but failed, skipping")
|
|
|
|
next
|
|
|
|
end
|
2022-02-04 18:48:09 -05:00
|
|
|
logger.info("sending submission #{msg.id}")
|
|
|
|
if msg.local
|
|
|
|
steve.send_file(File.open(msg.content,'r'))
|
2022-02-04 19:22:06 -05:00
|
|
|
File.delete(msg.content)
|
2022-02-04 18:48:09 -05:00
|
|
|
else
|
|
|
|
steve.pm(msg.content)
|
|
|
|
end
|
2022-02-05 15:32:14 -05:00
|
|
|
folder.update()
|
2022-02-04 18:48:09 -05:00
|
|
|
end
|