Guest User

Untitled

a guest
Apr 21st, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.27 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.  
  13. #create the bot object
  14. bot = Cinch::Bot.new do
  15.   configure do |c|
  16.  
  17.     #IRC configuration
  18.     c.server = "SERVER"
  19.     c.channels = ["#TMH"]
  20.     c.password = "PASSWORD"
  21.     c.user = "Superbot"
  22.     c.nick = "Superbot"
  23.     c.port = "6697"
  24.     c.ssl.use = "true"
  25.  
  26.   end
  27.  
  28.    tempyaml = YAML.load_file 'quotes.yml'
  29.    r = Rand.new(tempyaml.size)
  30.    tempyaml2 = YAML.load_file 'core.yml'
  31.    c = Rand.new(tempyaml2.size)
  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. This gives a random quote from the database."
  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. This gives a random core ticket from the database."
  48.         else
  49.                 m.reply "Current commands are !help, !nick, !register, !op, !quote, !addquote, !reparsequotedb, !core. Use !help <command> for more information."
  50.         end
  51.  
  52.   end
  53.  
  54.  
  55.  
  56.  
  57.  
  58.   on :message, /^!core ?(.*)/ do |m, query|
  59.         yml = YAML.load_file 'core.yml'
  60.         if ! query.empty?
  61.                 if  yml[query.to_i].nil?
  62.                         num = c.next
  63.                         m.reply "ID #{query} not found, generating random instead."
  64.                         m.reply "ID #{num}: #{yml[num]}"
  65.                 else
  66.                         m.reply "ID #{query}: #{yml[query.to_i]}"
  67.                 end
  68.         else
  69.                 num = c.next
  70.                 m.reply "ID #{num}: #{yml[num]}"
  71.         end
  72.  
  73.   end
  74.  
  75.  
  76.  
  77.  
  78.   on :message, /^!quote ?(.*)/ do |m, query|
  79.     yml = YAML.load_file 'quotes.yml'
  80.     if ! query.empty?
  81.         if  yml[query.to_i].nil?
  82.             num = r.next
  83.             m.reply "Quote ID #{query.to_i} not found, generating random instead."
  84.             m.reply "Quote ID #{num}: #{yml[num]}"
  85.         else
  86.             m.reply "Quote ID #{query.to_i}: #{yml[query.to_i]}"
  87.         end
  88.     else
  89.                 num = r.next
  90.                 m.reply "Quote ID #{num}: #{yml[num]}"
  91.     end
  92.  
  93.   end
  94.  
  95.  
  96.   on :message, /^!addquote (.*)/ do |m, query|
  97.     yml = YAML.load_file 'quotes.yml'
  98.     size = yml.size
  99.     File.open("quotes.yml", "w") do |file|
  100.             yml[size + 1] = query
  101.                 file.write(yml.to_yaml)
  102.         end
  103.     r.size = yml.size
  104.     m.reply "Quote had been added as Quote ID #{size +1}!"
  105.   end
  106.  
  107.   on :message,/!reparsequotedb/ do |m|
  108.     yml = YAML.load_file 'quotes.yml'
  109.     yml2 = {}
  110.     File.open("quotes.yml", "w") do |file|
  111.         yml.keys.each_with_index do |var,i|
  112.             yml2[i] = yml[var]         
  113.         end
  114.         file.write(yml2.to_yaml)
  115.     end
  116.     m.reply "Reparsed DB"
  117.   end
  118.            
  119.        
  120.  
  121.  
  122.   on :message, /^!nick ?(.*)/ do |m, query|  #match !nick <anything>(including nothing)
  123.         yml = YAML.load_file 'nicks.yml'
  124.     if ! query.empty?       #Make sure they gave us a nick
  125.             if yml[query.downcase].nil?     #We need to downcase so that it matches the yaml, this makes our life easier.
  126.                     m.reply "Nick #{query} does not exist"
  127.             else
  128.                     m.reply "#{query} is #{ yml[query.downcase]}"
  129.         end
  130.     else
  131.         m.reply "Usage: !nick <nickname>. This displays the name associated with the IRC nickname"
  132.         end
  133.  
  134.   end
  135.  
  136.  
  137.  
  138.   on :message, /^!register ?(.*)/ do |m, query|
  139.         yml = YAML.load_file 'nicks.yml'
  140.     array = query.split     #This splits every word of the query into part of an array, this makes it easier to work with.
  141.     if ! array[0].nil? && ! array[1].nil?       #We want to make sure that they gave us the correct syntax
  142.             if array[0].downcase != m.user.nick.downcase
  143.                     m.reply "#{m.user.nick}, You must be currently using the nickname you wish to register."
  144.         elsif   yml.has_key? array[0].downcase
  145.             m.reply "#{array[0]} is already registered, you derp"
  146.             elsif ! yml.has_key? array[0].downcase
  147.                     File.open("nicks.yml", "w") do |file|
  148.                         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.
  149.                         file.write(yml.to_yaml)
  150.             end
  151.                     m.reply "#{query} registered as #{array[1..array.count].join(' ')}!"
  152.        
  153.         else
  154.             m.reply "OOPS Something dun fucked up"          #We should never see this, but we want to know if we do.
  155.             end
  156.     else
  157.         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."
  158.     end
  159.   end
  160.  
  161.   on :message, /^!op (.*)/ do |m, query|
  162.     array = query.split
  163.     puts "#{array[0]} #{array[1]}"
  164.     yml = YAML.load_file 'ops.yml'
  165.     if ! array[0].nil? && ! array[1].nil?
  166.         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
  167.             bot.channels[0].op(m.user)
  168.         else
  169.             m.reply "Username/Password Mismatch"        #We don't really care what went wrong with their user or pass, just that something did.
  170.         end
  171.     else
  172.         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."
  173.     end
  174.   end
  175.  
  176.  
  177.   on :message, /^[^!](.*)/ do |m|
  178.     if TWSS(m.message)
  179.         m.reply "#{m.user.nick}, That's what she said"
  180.     end
  181.   end
  182.  
  183. end
  184. bot.start
Add Comment
Please, Sign In to add comment