Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. require 'discordrb'
  2. require 'nokogiri'
  3. require 'active_support/core_ext/hash/conversions'
  4. require 'time'
  5. require 'mysql2'
  6.  
  7. bot = Discordrb::Bot.new email: 'keevon+wedbot@gmail.com', password: 'wedbot', parse_self: true
  8.  
  9. def client
  10. Mysql2::Client.new(:host => "localhost", :username => "wedbot", :password => "wedbot", :database => "wedbot", :encoding => "utf8mb4")
  11. end
  12.  
  13. def eight_ball
  14. ["It is certain",
  15. "It is decidedly so",
  16. "Without a doubt",
  17. "Yes, definitely",
  18. "You may rely on it",
  19. "As I see it, yes",
  20. "Most likely",
  21. "Outlook good",
  22. "Yes",
  23. "Signs point to yes",
  24. "Reply hazy try again",
  25. "Ask again later",
  26. "Better not tell you now",
  27. "Cannot predict now",
  28. "Concentrate and ask again",
  29. "Don't count on it",
  30. "My reply is no",
  31. "My sources say no",
  32. "Outlook not so good",
  33. "Very doubtful"]
  34. end
  35.  
  36. bot.message(starting_with: "!quote") do |event|
  37. msg = event.content
  38. msg.strip!
  39. id = nil
  40. word = nil
  41. if (msg =~ /\A!quote (\d+)\z/) == 0
  42. id = $1.to_i
  43. result = client.query("SELECT * FROM quotes WHERE quote_id = #{id}")
  44. elsif (msg =~ /\A!quote (.+)\z/) == 0
  45. word = $1.to_s.downcase
  46. result = client.query("SELECT * FROM quotes where LOWER(text) like \"%#{word}%\" ORDER BY RAND() LIMIT 1")
  47. elsif msg == "!quote"
  48. result = client.query("SELECT * FROM quotes ORDER BY RAND() LIMIT 1")
  49. else
  50. result = nil
  51. end
  52.  
  53. if result.nil?
  54. # do nothing
  55. elsif result.count == 0
  56. if (!id.nil?)
  57. event.respond "Quote #{id} not found"
  58. elsif (!word.nil?)
  59. event.respond "No #{word} found"
  60. else
  61. event.respond "No quotes found"
  62. end
  63. else
  64. quote = result.first
  65. time = quote["submitted"]
  66. event.respond %Q{
  67. ##{quote['quote_id']} by #{quote["submitter"]} [#{time.strftime "%-m/%e/%y %-l:%M%p"}]
  68. ```
  69. #{quote["text"][0..1899]}
  70. ```
  71. }
  72. end
  73. end
  74.  
  75. bot.message(starting_with: "!addquote") do |event|
  76. msg = event.content
  77. msg.slice!("!addquote")
  78. msg.strip!
  79. query = "INSERT INTO unverified_quotes (submitter, submitted, text) VALUES ('#{event.author.username}', FROM_UNIXTIME(#{event.timestamp.to_i}), '#{client.escape msg}')"
  80. client.query(query)
  81. event.respond "Quote submitted for approval"
  82. end
  83.  
  84. bot.message(starting_with: "!topic") do |event|
  85. msg = event.content
  86. msg.slice!("!topic")
  87. msg.strip!
  88. event.channel.topic = msg
  89. end
  90.  
  91. bot.message(starting_with: "!chatname") do |event|
  92. msg = event.content
  93. msg.slice!("!chatname")
  94. msg.strip!
  95. event.channel.name = msg
  96. end
  97.  
  98. bot.message(starting_with: "!8ball") do |event|
  99. msg = event.content
  100. msg.slice!("!8ball")
  101. msg.strip!
  102. if msg == ""
  103. event.respond "Please ask a question"
  104. return
  105. end
  106.  
  107. msgs = eight_ball
  108. if event.author.username == "Keevon"
  109. msgs.push "Try a hot dog"
  110. elsif event.author.username == "Lowclock"
  111. msgs.push "Smoke weed everyday"
  112. elsif event.author.username == "Dogs"
  113. msgs.push "Do a couple jabs"
  114. elsif event.author.username == "tarns"
  115. msgs.push "Please be quiet, here's a magic card"
  116. elsif event.author.username == "Tumps"
  117. msgs.push "Sorry Urien's never coming out"
  118. elsif event.author.username == "Funzo"
  119. msgs.push "I don't talk to banboys"
  120. elsif event.author.username == "andy"
  121. msgs.push "Anything for you, andy"
  122. end
  123. event.respond msgs.sample
  124. end
  125.  
  126. bot.message(contains: "http") do |event|
  127. break if event.author.id == 171862674836029440 #Don't quote yourself
  128. break if event.channel == 262025945492226048 #nothing from linktown
  129. break if event.channel == 181887763346489344 #or magicchat
  130. break if event.channel == 181887815695466497 #or ffrkchat
  131. break if event.channel == 172593637283201024 #or musicchat
  132. event.message.pin #Pin the message
  133. bot.send_message(262025945492226048, "#{event.author.username} in #{event.channel.name}\n#{event.content}")
  134. end
  135.  
  136. bot.message(with_text: "") do |event|
  137. break if event.author.id != 171862674836029440 #Don't try to delete other people's pin notifications
  138. event.message.delete #Deletes the notification
  139. end
  140.  
  141. bot.run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement