Created
January 14, 2015 21:44
-
-
Save SharaaEsper/d6c95b03d293ec083b26 to your computer and use it in GitHub Desktop.
why did I do this
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.sort.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 ddoes 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment