Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'discordrb'
- require 'nokogiri'
- require 'active_support/core_ext/hash/conversions'
- require 'time'
- require 'mysql2'
- bot = Discordrb::Bot.new email: 'keevon+wedbot@gmail.com', password: 'wedbot', parse_self: true
- def client
- Mysql2::Client.new(:host => "localhost", :username => "wedbot", :password => "wedbot", :database => "wedbot", :encoding => "utf8mb4")
- end
- def eight_ball
- ["It is certain",
- "It is decidedly so",
- "Without a doubt",
- "Yes, definitely",
- "You may rely on it",
- "As I see it, yes",
- "Most likely",
- "Outlook good",
- "Yes",
- "Signs point to yes",
- "Reply hazy try again",
- "Ask again later",
- "Better not tell you now",
- "Cannot predict now",
- "Concentrate and ask again",
- "Don't count on it",
- "My reply is no",
- "My sources say no",
- "Outlook not so good",
- "Very doubtful"]
- end
- bot.message(starting_with: "!quote") do |event|
- msg = event.content
- msg.strip!
- id = nil
- word = nil
- if (msg =~ /\A!quote (\d+)\z/) == 0
- id = $1.to_i
- result = client.query("SELECT * FROM quotes WHERE quote_id = #{id}")
- elsif (msg =~ /\A!quote (.+)\z/) == 0
- word = $1.to_s.downcase
- result = client.query("SELECT * FROM quotes where LOWER(text) like \"%#{word}%\" ORDER BY RAND() LIMIT 1")
- elsif msg == "!quote"
- result = client.query("SELECT * FROM quotes ORDER BY RAND() LIMIT 1")
- else
- result = nil
- end
- if result.nil?
- # do nothing
- elsif result.count == 0
- if (!id.nil?)
- event.respond "Quote #{id} not found"
- elsif (!word.nil?)
- event.respond "No #{word} found"
- else
- event.respond "No quotes found"
- end
- else
- quote = result.first
- time = quote["submitted"]
- event.respond %Q{
- ##{quote['quote_id']} by #{quote["submitter"]} [#{time.strftime "%-m/%e/%y %-l:%M%p"}]
- ```
- #{quote["text"][0..1899]}
- ```
- }
- end
- end
- bot.message(starting_with: "!addquote") do |event|
- msg = event.content
- msg.slice!("!addquote")
- msg.strip!
- query = "INSERT INTO unverified_quotes (submitter, submitted, text) VALUES ('#{event.author.username}', FROM_UNIXTIME(#{event.timestamp.to_i}), '#{client.escape msg}')"
- client.query(query)
- event.respond "Quote submitted for approval"
- end
- bot.message(starting_with: "!topic") do |event|
- msg = event.content
- msg.slice!("!topic")
- msg.strip!
- event.channel.topic = msg
- end
- bot.message(starting_with: "!chatname") do |event|
- msg = event.content
- msg.slice!("!chatname")
- msg.strip!
- event.channel.name = msg
- end
- bot.message(starting_with: "!8ball") do |event|
- msg = event.content
- msg.slice!("!8ball")
- msg.strip!
- if msg == ""
- event.respond "Please ask a question"
- return
- end
- msgs = eight_ball
- if event.author.username == "Keevon"
- msgs.push "Try a hot dog"
- elsif event.author.username == "Lowclock"
- msgs.push "Smoke weed everyday"
- elsif event.author.username == "Dogs"
- msgs.push "Do a couple jabs"
- elsif event.author.username == "tarns"
- msgs.push "Please be quiet, here's a magic card"
- elsif event.author.username == "Tumps"
- msgs.push "Sorry Urien's never coming out"
- elsif event.author.username == "Funzo"
- msgs.push "I don't talk to banboys"
- elsif event.author.username == "andy"
- msgs.push "Anything for you, andy"
- end
- event.respond msgs.sample
- end
- bot.message(contains: "http") do |event|
- break if event.author.id == 171862674836029440 #Don't quote yourself
- break if event.channel == 262025945492226048 #nothing from linktown
- break if event.channel == 181887763346489344 #or magicchat
- break if event.channel == 181887815695466497 #or ffrkchat
- break if event.channel == 172593637283201024 #or musicchat
- event.message.pin #Pin the message
- bot.send_message(262025945492226048, "#{event.author.username} in #{event.channel.name}\n#{event.content}")
- end
- bot.message(with_text: "") do |event|
- break if event.author.id != 171862674836029440 #Don't try to delete other people's pin notifications
- event.message.delete #Deletes the notification
- end
- bot.run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement