Guest User

Untitled

a guest
Oct 17th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.59 KB | None | 0 0
  1. #!/usr/local/bin/ruby
  2.  
  3.  
  4. #Requires for different parts of the bot
  5. require 'rubygems'
  6. require 'cinch'
  7. require 'yaml'
  8. require 'digest/md5'
  9. require './random.rb'
  10. require 'twss'
  11.  
  12. #create the bot object
  13. bot = Cinch::Bot.new do
  14.   configure do |c|
  15.  
  16.     #IRC configuration
  17.     c.server = "SERVAR"
  18.     c.channels = ["#TMH"]
  19.     c.password = "PASSWARD"
  20.     c.user = "Superbot"
  21.     c.nick = "Superbot"
  22.     c.port = "6697"
  23.     c.ssl.use = "true"
  24.  
  25.   end
  26.  
  27.    tempyaml = YAML.load_file 'quotes.yml'
  28.    r = Rand.new(tempyaml.size)
  29.    tempyaml2 = YAML.load_file 'core.yml'
  30.    c = Rand.new(tempyaml2.size)
  31.    d20 = Rand.new(19)
  32.  
  33.   on :message, /^!help ?(.*)?/ do |m, query|    #Match !help, including it by itself
  34.         if query == "nick"
  35.                 m.reply "Usage: !nick <nickname>. This displays the name associated with the IRC nickname"
  36.         elsif query == "register"
  37.                 m.reply "Usage: !register <nickname> <name>. This registers you with this bot so the !nick command will work for others. Please note you must currently be using this nickname."
  38.         elsif query == "op"
  39.                 m.reply "Usage: !op <username> <password>. This will have the bot OP you. Note, this command works on any message but you should probably private message me so you don't tell everyone your password."
  40.     elsif query == "quote"
  41.         m.reply "Usage: !quote [<quoteID>]. This gives a random quote from the database, or gives the quote for <quoteID>"
  42.     elsif query == "addquote"
  43.         m.reply "Usage: !addquote <quote>. This adds a quote to the bot's database. One line only! I swear to god if I have to clean up quotes I'll hurt you."
  44.     elsif query == "reparsequotedb"
  45.         m.reply "Usage: !reparsequotedb. This reparses the quote DB in case you had to delete a quote."
  46.     elsif query == "core"
  47.         m.reply "Usage: !core [<coreID>]. This gives a random core ticket from the database, or the core ticket for <coreID>."
  48.     elsif query == "twsscheck"
  49.         m.reply "Usage: !twsscheck. Replies with the current TWSS threshold. It is on a scale from 1-10, one being the most sensitive and 10 being the least."
  50.     elsif query == "twsschange"
  51.         m.reply "Usage: !twsschange <threshold>. This changes the threshold to <threshold>, 1 being the most sensitive, 10 being the least."
  52.     elsif query == "countquotes"
  53.         m.reply "Usage: !countquotes. Counts the number of quotes available in the !quote DB"
  54.     elsif query == "dice"
  55.         m.reply "Usage: !dice <20>, This rolls a die of the specified type."
  56.         else
  57.                 m.reply "Current commands are !help, !nick, !register, !op, !quote, !addquote, !countquotes, !reparsequotedb, !core, !twsscheck, !twsschange, !dice. Use !help <command> for more information."
  58.         end
  59.  
  60.   end
  61.  
  62.  
  63.  
  64.  
  65.  
  66. on :message, /^!dice ?(.*)/ do |m, query|
  67.     if query.to_s == "20"
  68.         num = d20.next
  69.         m.reply "#{m.user.nick}, you rolled a #{num.to_i + 1} on a d20"
  70.     else
  71.         num = d20.next
  72.         m.reply "#{m.user.nick}, you rolled a #{num.to_i + 1} on a d20"
  73.     end
  74. end
  75.  
  76.  
  77.  
  78.   on :message, /^!core ?(.*)/ do |m, query|
  79.         yml = YAML.load_file 'core.yml'
  80.         if ! query.empty?
  81.                 if  yml[query.to_i].nil?
  82.                         num = c.next
  83.                         m.reply "ID #{query} not found, generating random instead."
  84.                         m.reply "ID #{num}: #{yml[num]}"
  85.                 else
  86.                         m.reply "ID #{query}: #{yml[query.to_i]}"
  87.                 end
  88.         else
  89.                 num = c.next
  90.                 m.reply "ID #{num}: #{yml[num]}"
  91.         end
  92.  
  93.   end
  94.  
  95.  
  96.  
  97.  
  98.   on :message, /^!quote ?(.*)/ do |m, query|
  99.     yml = YAML.load_file 'quotes.yml'
  100.     if ! query.empty?
  101.         if  yml[query.to_i].nil?
  102.             num = r.next
  103.             m.reply "Quote ID #{query.to_i} not found, generating random instead."
  104.             m.reply "Quote ID #{num}: #{yml[num]}"
  105.         else
  106.             m.reply "Quote ID #{query.to_i}: #{yml[query.to_i]}"
  107.         end
  108.     else
  109.                 num = r.next
  110.                 m.reply "Quote ID #{num}: #{yml[num]}"
  111.     end
  112.  
  113.   end
  114.  
  115.  
  116.  
  117.   on :message, /^!grepquote ?(.*)/ do |m, query|
  118.     yml = YAML.load_file 'quotes.yml'
  119.     if query.empty?
  120.         m.reply "You need to specify a search string."
  121.     else
  122.         yml.each_pair do |key, value|
  123.             if value.downcase =~ /#{query.downcase}/
  124.                 m.reply "Match Found. ID: #{key}, Quote: #{value}"
  125.             end
  126.         end
  127.     end
  128.   end
  129.  
  130.  
  131.   on :message, /^!addquote (.*)/ do |m, query|
  132.     yml = YAML.load_file 'quotes.yml'
  133.     size = yml.size
  134.     File.open("quotes.yml", "w") do |file|
  135.             yml[size] = query
  136.                 file.write(yml.to_yaml)
  137.         end
  138.     r.size = yml.size
  139.     m.reply "Quote had been added as Quote ID #{size}!"
  140.   end
  141.  
  142.   on :message,/!reparsequotedb/ do |m|
  143.     yml = YAML.load_file 'quotes.yml'
  144.     yml2 = {}
  145.     File.open("quotes.yml", "w") do |file|
  146.         yml.keys.each_with_index do |var,i|
  147.             yml2[i] = yml[var]         
  148.         end
  149.         file.write(yml2.to_yaml)
  150.     end
  151.     r.size = yml.size
  152.     m.reply "Reparsed DB"
  153.   end
  154.            
  155.        
  156.   on :message, /!countquotes/ do |m|
  157.     yml = YAML.load_file 'quotes.yml'
  158.     m.reply "There are currently #{yml.count} quotes in the quote DB."
  159.   end
  160.  
  161.   on :message, /^!nick ?(.*)/ do |m, query|  #match !nick <anything>(including nothing)
  162.         yml = YAML.load_file 'nicks.yml'
  163.     if ! query.empty?       #Make sure they gave us a nick
  164.             if yml[query.downcase].nil?     #We need to downcase so that it matches the yaml, this makes our life easier.
  165.                     m.reply "Nick #{query} does not exist"
  166.             else
  167.                     m.reply "#{query} is #{ yml[query.downcase]}"
  168.         end
  169.     else
  170.         m.reply "Usage: !nick <nickname>. This displays the name associated with the IRC nickname"
  171.         end
  172.  
  173.   end
  174.  
  175.  
  176.  
  177.   on :message, /^!register ?(.*)/ do |m, query|
  178.         yml = YAML.load_file 'nicks.yml'
  179.     array = query.split     #This splits every word of the query into part of an array, this makes it easier to work with.
  180.     if ! array[0].nil? && ! array[1].nil?       #We want to make sure that they gave us the correct syntax
  181.             if array[0].downcase != m.user.nick.downcase
  182.                     m.reply "#{m.user.nick}, You must be currently using the nickname you wish to register."
  183.         elsif   yml.has_key? array[0].downcase
  184.             m.reply "#{array[0]} is already registered, you derp"
  185.             elsif ! yml.has_key? array[0].downcase
  186.                     File.open("nicks.yml", "w") do |file|
  187.                         yml[array[0].downcase] = array[1..array.count].join(' ') #This makes it so that if they used a multipart name (such as first last) it joins it together.
  188.                         file.write(yml.to_yaml)
  189.             end
  190.                     m.reply "#{query} registered as #{array[1..array.count].join(' ')}!"
  191.        
  192.         else
  193.             m.reply "OOPS Something dun fucked up"          #We should never see this, but we want to know if we do.
  194.             end
  195.     else
  196.         m.reply "Usage: !register <nickname> <name>. This registers you with this bot so the !nick command will work for others. Please note you must currently be using this nickname."
  197.     end
  198.   end
  199.  
  200.   on :message, /^!op (.*)/ do |m, query|
  201.     array = query.split
  202.     puts "#{array[0]} #{array[1]}"
  203.     yml = YAML.load_file 'ops.yml'
  204.     if ! array[0].nil? && ! array[1].nil?
  205.         if Digest::MD5.hexdigest(array[1]) ==  yml[array[0].downcase]   #Hash the password then check against the yaml to see if they supplied the correct one
  206.             bot.channels[0].op(m.user)
  207.         else
  208.             m.reply "Username/Password Mismatch"        #We don't really care what went wrong with their user or pass, just that something did.
  209.         end
  210.     else
  211.         m.reply "Usage: !op <username> <password>. This will have the bot OP you. Note, this command only works any message but you should probably private message me so you don't tell everyone your password."
  212.     end
  213.   end
  214.  
  215.  
  216.  
  217.  
  218. end
  219. bot.start
Add Comment
Please, Sign In to add comment