parent
ebc76fe8a3
commit
1b1df5dd41
2
Gemfile
2
Gemfile
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
source 'https://rubygems.org'
|
source 'https://rubygems.org'
|
||||||
gem 'discordrb'
|
gem 'discordrb'
|
||||||
gem 'rufus-scheduler'
|
gem 'rufus-scheduler'
|
||||||
|
|
53
bot.rb
53
bot.rb
|
@ -1,34 +1,61 @@
|
||||||
#!/bin/env ruby
|
#!/bin/env ruby
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'discordrb'
|
require 'discordrb'
|
||||||
require 'rufus-scheduler'
|
require 'rufus-scheduler'
|
||||||
|
|
||||||
# fetches a random quote from quotes
|
# fetches a random quote from quotes
|
||||||
def random_quote(quotes)
|
def random_quote(quotes)
|
||||||
quote = "**Quote of the Day**"
|
entry = quotes.keys.sample
|
||||||
quote << "```"
|
quote = "**Quote of the Day**\n"
|
||||||
quotes.sample.split("\n")[2..].each { | line | quote << line.delete("^") + "\n" }
|
quote << "From the #{quotes[entry][:tech]}: #{entry}\n"
|
||||||
quote << "```"
|
quote << '```'
|
||||||
|
quote << quotes[entry][:quote]
|
||||||
|
quote << '```'
|
||||||
end
|
end
|
||||||
|
|
||||||
token = File.read("./token").strip
|
# map quote types
|
||||||
|
def get_quote_type(tech)
|
||||||
|
case tech
|
||||||
|
when /TECH/
|
||||||
|
'Technology'
|
||||||
|
when /HELPFAC/
|
||||||
|
'Base Facility'
|
||||||
|
when /PROJECT/
|
||||||
|
'Secret Project'
|
||||||
|
when /OPENING/
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# preserves whitespace intention for quotes, expects array of strings, one line per element
|
||||||
|
def make_pretty_quote(quote)
|
||||||
|
quote.map { |line| line.gsub('^^', " \n").gsub('^', "\n") }.join.strip
|
||||||
|
end
|
||||||
|
|
||||||
|
token = File.read('./token').strip
|
||||||
bot = Discordrb::Bot.new token: token
|
bot = Discordrb::Bot.new token: token
|
||||||
quotes = File.read("Game Files/blurbsx.txt").split("##")
|
raw_quotes = File.read('Game Files/blurbsx.txt').split('##')
|
||||||
quotes.delete_at(0) # Remove empty first item
|
raw_quotes.delete_at(0) # Remove empty first item
|
||||||
scheduler = Rufus::Scheduler.new
|
scheduler = Rufus::Scheduler.new
|
||||||
start_time = Rufus::Scheduler.parse('12:30') # what time of day the message should send
|
start_time = Rufus::Scheduler.parse('12:30') # what time of day the message should send
|
||||||
# start tomorrow if start_time has passed
|
# start tomorrow if start_time has passed
|
||||||
start_time += Rufus::Scheduler.parse('1d') if start_time < Time.now
|
start_time += Rufus::Scheduler.parse('1d') if start_time < Time.now
|
||||||
|
quotes = {}
|
||||||
|
raw_quotes.each do |quote|
|
||||||
|
quote = quote.split("\n")
|
||||||
|
tech_and_text = { tech: get_quote_type(quote[1]), quote: make_pretty_quote(quote[2..]) }
|
||||||
|
quotes.store(quote[0], tech_and_text)
|
||||||
|
end
|
||||||
|
quotes.freeze
|
||||||
|
|
||||||
scheduler.every '1d', first_at: start_time do
|
scheduler.every '1d', first_at: start_time do
|
||||||
bot.send_message(852541842511495210, random_quote(quotes))
|
bot.send_message(852_541_842_511_495_210, random_quote(quotes))
|
||||||
end
|
end
|
||||||
|
|
||||||
bot.message(with_text: 'Ping!') do |event|
|
bot.message(with_text: 'Ping!') do |event|
|
||||||
|
|
||||||
event.respond random_quote(quotes)
|
event.respond random_quote(quotes)
|
||||||
pp bot
|
pp bot
|
||||||
end
|
end
|
||||||
|
|
||||||
bot.run
|
|
||||||
|
|
||||||
|
bot.run
|
||||||
|
|
Loading…
Reference in New Issue