Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/ruby
- #Requires for different parts of the bot
- require 'rubygems'
- require 'cinch'
- require 'yaml'
- require 'digest/md5'
- require './random.rb'
- require 'twss'
- #create the bot object
- bot = Cinch::Bot.new do
- configure do |c|
- #IRC configuration
- c.server = "SERVER"
- c.channels = ["#TMH"]
- c.password = "PASSWORD"
- c.user = "Superbot"
- c.nick = "Superbot"
- c.port = "6697"
- c.ssl.use = "true"
- end
- tempyaml = YAML.load_file 'quotes.yml'
- r = Rand.new(tempyaml.size)
- tempyaml2 = YAML.load_file 'core.yml'
- c = Rand.new(tempyaml2.size)
- on :message, /^!help ?(.*)?/ do |m, query| #Match !help, including it by itself
- if query == "nick"
- m.reply "Usage: !nick <nickname>. This displays the name associated with the IRC nickname"
- elsif query == "register"
- 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."
- elsif query == "op"
- 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."
- elsif query == "quote"
- m.reply "Usage: !quote. This gives a random quote from the database."
- elsif query == "addquote"
- 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."
- elsif query == "reparsequotedb"
- m.reply "Usage: !reparsequotedb. This reparses the quote DB in case you had to delete a quote."
- elsif query == "core"
- m.reply "Usage: !core. This gives a random core ticket from the database."
- else
- m.reply "Current commands are !help, !nick, !register, !op, !quote, !addquote, !reparsequotedb, !core. Use !help <command> for more information."
- end
- end
- on :message, /^!core ?(.*)/ do |m, query|
- yml = YAML.load_file 'core.yml'
- if ! query.empty?
- if yml[query.to_i].nil?
- num = c.next
- m.reply "ID #{query} not found, generating random instead."
- m.reply "ID #{num}: #{yml[num]}"
- else
- m.reply "ID #{query}: #{yml[query.to_i]}"
- end
- else
- num = c.next
- m.reply "ID #{num}: #{yml[num]}"
- end
- end
- on :message, /^!quote ?(.*)/ do |m, query|
- yml = YAML.load_file 'quotes.yml'
- if ! query.empty?
- if yml[query.to_i].nil?
- num = r.next
- m.reply "Quote ID #{query.to_i} not found, generating random instead."
- m.reply "Quote ID #{num}: #{yml[num]}"
- else
- m.reply "Quote ID #{query.to_i}: #{yml[query.to_i]}"
- end
- else
- num = r.next
- m.reply "Quote ID #{num}: #{yml[num]}"
- end
- end
- on :message, /^!addquote (.*)/ do |m, query|
- yml = YAML.load_file 'quotes.yml'
- size = yml.size
- File.open("quotes.yml", "w") do |file|
- yml[size + 1] = query
- file.write(yml.to_yaml)
- end
- r.size = yml.size
- m.reply "Quote had been added as Quote ID #{size +1}!"
- end
- on :message,/!reparsequotedb/ do |m|
- yml = YAML.load_file 'quotes.yml'
- yml2 = {}
- File.open("quotes.yml", "w") do |file|
- yml.keys.each_with_index do |var,i|
- yml2[i] = yml[var]
- end
- file.write(yml2.to_yaml)
- end
- m.reply "Reparsed DB"
- end
- on :message, /^!nick ?(.*)/ do |m, query| #match !nick <anything>(including nothing)
- yml = YAML.load_file 'nicks.yml'
- if ! query.empty? #Make sure they gave us a nick
- if yml[query.downcase].nil? #We need to downcase so that it matches the yaml, this makes our life easier.
- m.reply "Nick #{query} does not exist"
- else
- m.reply "#{query} is #{ yml[query.downcase]}"
- end
- else
- m.reply "Usage: !nick <nickname>. This displays the name associated with the IRC nickname"
- end
- end
- on :message, /^!register ?(.*)/ do |m, query|
- yml = YAML.load_file 'nicks.yml'
- array = query.split #This splits every word of the query into part of an array, this makes it easier to work with.
- if ! array[0].nil? && ! array[1].nil? #We want to make sure that they gave us the correct syntax
- if array[0].downcase != m.user.nick.downcase
- m.reply "#{m.user.nick}, You must be currently using the nickname you wish to register."
- elsif yml.has_key? array[0].downcase
- m.reply "#{array[0]} is already registered, you derp"
- elsif ! yml.has_key? array[0].downcase
- File.open("nicks.yml", "w") do |file|
- 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.
- file.write(yml.to_yaml)
- end
- m.reply "#{query} registered as #{array[1..array.count].join(' ')}!"
- else
- m.reply "OOPS Something dun fucked up" #We should never see this, but we want to know if we do.
- end
- else
- 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."
- end
- end
- on :message, /^!op (.*)/ do |m, query|
- array = query.split
- puts "#{array[0]} #{array[1]}"
- yml = YAML.load_file 'ops.yml'
- if ! array[0].nil? && ! array[1].nil?
- 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
- bot.channels[0].op(m.user)
- else
- m.reply "Username/Password Mismatch" #We don't really care what went wrong with their user or pass, just that something did.
- end
- else
- 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."
- end
- end
- on :message, /^[^!](.*)/ do |m|
- if TWSS(m.message)
- m.reply "#{m.user.nick}, That's what she said"
- end
- end
- end
- bot.start
Add Comment
Please, Sign In to add comment