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 = "SERVAR"
- c.channels = ["#TMH"]
- c.password = "PASSWARD"
- 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)
- d20 = Rand.new(19)
- 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 [<quoteID>]. This gives a random quote from the database, or gives the quote for <quoteID>"
- 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 [<coreID>]. This gives a random core ticket from the database, or the core ticket for <coreID>."
- elsif query == "twsscheck"
- 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."
- elsif query == "twsschange"
- m.reply "Usage: !twsschange <threshold>. This changes the threshold to <threshold>, 1 being the most sensitive, 10 being the least."
- elsif query == "countquotes"
- m.reply "Usage: !countquotes. Counts the number of quotes available in the !quote DB"
- elsif query == "dice"
- m.reply "Usage: !dice <20>, This rolls a die of the specified type."
- else
- m.reply "Current commands are !help, !nick, !register, !op, !quote, !addquote, !countquotes, !reparsequotedb, !core, !twsscheck, !twsschange, !dice. Use !help <command> for more information."
- end
- end
- on :message, /^!dice ?(.*)/ do |m, query|
- if query.to_s == "20"
- num = d20.next
- m.reply "#{m.user.nick}, you rolled a #{num.to_i + 1} on a d20"
- else
- num = d20.next
- m.reply "#{m.user.nick}, you rolled a #{num.to_i + 1} on a d20"
- 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, /^!grepquote ?(.*)/ do |m, query|
- yml = YAML.load_file 'quotes.yml'
- if query.empty?
- m.reply "You need to specify a search string."
- else
- yml.each_pair do |key, value|
- if value.downcase =~ /#{query.downcase}/
- m.reply "Match Found. ID: #{key}, Quote: #{value}"
- end
- end
- 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] = query
- file.write(yml.to_yaml)
- end
- r.size = yml.size
- m.reply "Quote had been added as Quote ID #{size}!"
- 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
- r.size = yml.size
- m.reply "Reparsed DB"
- end
- on :message, /!countquotes/ do |m|
- yml = YAML.load_file 'quotes.yml'
- m.reply "There are currently #{yml.count} quotes in the quote 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
- end
- bot.start
Add Comment
Please, Sign In to add comment