Advertisement
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'
- #create the bot object
- bot = Cinch::Bot.new do
- configure do |c|
- #IRC configuration
- c.server = "irc.failverse.com"
- c.channels = ["#TMH"]
- c.password = "omgzpassword"
- c.user = "Superbot"
- c.nick = "Superbot"
- c.port = "6697"
- c.ssl.use = "true"
- 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, /^!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 == "issue"
- m.reply "Usage: !issue shows the current issues we are having. Subcommands: List, ID. Use !issue help <subcommand> for more information. See Also: !issueadm help"
- elsif query == "issueadm"
- m.reply "Usage: !issueadm <command> <issueid> [<notename> <notes>]. current commands: Addnote, Addissue, Delnote, Delissue. See !issueadm help <command> for more information on usage."
- else
- m.reply "Current commands are !help, !nick, !register, !op, !issue, !issueaadm. Use !help nick/register/op/issue/issueadm for more information."
- 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
- yml = YAML.load_file 'ops.yml'
- if ! array[0].nil? && ! array[1].nil?
- if Digest::MD5.hexdigest(array[0]) == yml[array[1].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, /^!issue[^adm] ?(.*)/ do |m, query| #[^adm] is there so !issueadm does not match.
- array = query.split
- if ! array[0].nil?
- if array[0].downcase == "help"
- if ! array[1].nil?
- if array[1].downcase == "list"
- m.reply "Usage: !issue list shows the IDs of all current issues. You can use these numbers with !issue id to get more information"
- elsif array[1].downcase == "id"
- m.reply "Usage: !issue id <id> Lists all notes regarding the issue of the ID specified. Use !issue list to get the current list of IDs"
- else
- m.reply "Usage: !issue shows the current issues we are having. Subcommands: List, ID. Use !help <subcommand> for more information. See Also: !issueadm help"
- end
- else
- m.reply "Usage: !issue shows the current issues we are having. Subcommands: List, ID. Use !issue help <subcommand> for more information. See Also: !issueadm help"
- end
- elsif array[0].downcase == "list"
- yml = YAML.load_file 'list.yml'
- yml.keys.each do |var| #Basic for/each loop so the bot can give us the entire list.
- m.reply "#{var}: #{yml[var]}"
- end
- elsif array[0].downcase == "id"
- yml = YAML.load_file 'issues.yml'
- if ! yml.has_key? array[1].to_i
- m.reply "ID #{array[1]} does not exist, use !issue list to get the current IDs of issues."
- else
- m.reply "Issue #{array[1]}:"
- yml[array[1].to_i].keys.each do |var|
- m.reply "#{var}: #{yml[array[1].to_i][var]}" #The bot will automatically split if the IRC character limit is reached, so we just need to fetch it
- end
- end
- else
- m.reply "Usage: !issue shows the current issues we are having. Subcommands: List, ID. Use !issue help <subcommand> for more information. See Also: !issueadm help"
- end
- else
- m.reply "Usage: !issue shows the current issues we are having. Subcommands: List, ID. Use !issue help <subcommand> for more information. See Also: !issueadm help"
- end
- end
- on :message, /^!issueadm (.*)/ do |m, query|
- array = query.split
- yml = YAML.load_file 'issues.yml'
- if ! array[0].nil?
- if array[0].downcase == "help"
- if ! array[1].nil?
- if array[1].downcase == "addnote"
- m.reply "Usage: !issueadm addnote <issueid> <notename> <note>. Please note that you can not use a noteid already in use for this issue."
- elsif array[1].downcase == "addissue"
- m.reply "Usage: !issueadm addissue <issueid> <issuename>. Please note, the issueid must be numerical and not aleady exist. The <issuename> will be added as the title"
- elsif array[1].downcase == "delnote"
- m.reply "Usage: !issueadm delnote <issueid> <notename>. Note you must be OPed to delete notes."
- elsif array[1].downcase == "delissue"
- m.reply "Usage: !issueadm delissue <issueid>. Note you must be OPed to delete issues."
- end
- else
- m.reply "Usage: !issueadm <command> <issueid> [<notename> <notes>]. current commands: Addnote, Addissue, Delnote, Delissue. See !issueadm help <command> for more information on usage."
- end
- elsif array[0].downcase == "addnote"
- if ! array[1].nil? && ! array[2].nil? && ! array[3].nil?
- if ! yml.has_key? array[1].to_i
- m.reply "Issue does not exist, use !issue list to get the issue ID."
- elsif yml[array[1].to_i].has_key? array[2].downcase
- m.reply "Note Name already exists, use !issue id <issueid> to see current notes."
- else
- File.open("issues.yml", "w") do |file|
- yml[array[1].to_i][array[2].to_s.downcase] = array[3..array.count].join(' ') #Make sure to join it back together so the yaml is written correctly
- file.write(yml.to_yaml)
- end
- m.reply "Note #{array[2]} Added."
- end
- else
- m.reply "Usage: !issueadm addnote <issueid> <notename> <note>. Please note that you can not use a noteid already in use for this issue."
- end
- elsif array[0].downcase == "addissue"
- if ! array[1].nil? && ! array[2].nil?
- if array[1].to_i == 0 or yml.has_key? array[1].to_i # to_i returns 0 if there is no numerical value at the start, so we just don't allow 0 for the sake of laziness
- m.reply "Issue either already exists, you used a non-numerical ID, or you used an ID of 0."
- else
- yml2 = YAML.load_file 'list.yml'
- File.open("list.yml", "w") do |file|
- yml2[array[1].to_i] = array[2..array.count].join(' ')
- file.write(yml2.to_yaml)
- end
- File.open("issues.yml", "w") do |file|
- yml[array[1].to_i] = {"Title" => array[2..array.count].join(' ')} #Make sure the issues yaml is written correctly so we can append to it.
- file.write(yml.to_yaml)
- end
- m.reply "Issue #{array[1]} Added."
- end
- else
- m.reply "Usage: !issueadm addissue <issueid> <issuename>. Please note, the issueid must be numerical and not aleady exist. The <issuename> will be added as the title"
- end
- elsif array[0].downcase == "delnote"
- if ! bot.channels[0].opped? m.user.nick
- m.reply "You must be Opped in order to use this command."
- else
- if ! array[1].nil? && ! array[2].nil?
- if ! yml.has_key? array[1].to_i
- m.reply "Issue does not exist, use !issue list to get the issue ID."
- elsif ! yml[array[1].to_i].has_key? array[2].downcase
- m.reply "Note does not exist, use !issue id <ID> to see the current notes."
- else
- File.open("issues.yml", "w") do |file|
- yml[array[1].to_i].delete(array[2].downcase)
- file.write(yml.to_yaml)
- end
- m.reply "Note #{array[2]} has been deleted."
- end
- else
- m.reply "Usage: !issueadm delnote <issueid> <notename>. Note you must be Opped to delete notes."
- end
- end
- elsif array[0].downcase == "delissue"
- yml2 = YAML.load_file('list.yml')
- if ! bot.channels[0].opped? m.user.nick
- m.reply "You must be Opped in order to use this command."
- else
- if !array[1].nil?
- if ! yml.has_key? array[1].to_i and ! yml2.has_key? array[1].to_i
- m.reply "Issue due not exist, use !issue list to get the issue ID."
- else
- File.open("issues.yml", "w") do |file|
- yml.delete(array[1].to_i)
- file.write(yml.to_yaml)
- end
- File.open("list.yml", "w") do |file|
- yml2.delete(array[1].to_i)
- file.write(yml2.to_yaml)
- end
- m.reply "Issue has been Deleted."
- end
- else
- m.reply "Usage: !issueadm delissue <issueid>. Note you must be OPed to delete issues."
- end
- end
- end
- end
- end
- end
- bot.start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement