From 09a7b4f637a34b196d641890b8bac62e127676b5 Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Thu, 5 Jan 2012 22:51:28 -0500 Subject: [PATCH 1/5] Break out handlers into a second file --- Baxter.rb | 83 +++++------------------------------------------------ handlers.rb | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 76 deletions(-) create mode 100644 handlers.rb diff --git a/Baxter.rb b/Baxter.rb index b4e694c..2d510fa 100755 --- a/Baxter.rb +++ b/Baxter.rb @@ -4,9 +4,13 @@ require 'open-uri' require 'nokogiri' require 'parseconfig' + $config = ParseConfig.new('credentials.cfg') $urlhelpers = Hash["c" => "Core", "p" => "Portals", "n" => "NetherPortals", "s" => "SignPortals", "a" => "Adventure"] $authrequired = true + +require './handlers.rb' + bot = Cinch::Bot.new do configure do |c| c.server = "irc.esper.net" @@ -14,6 +18,8 @@ c.user = $config.get_value('username') c.password = $config.get_value('password') c.channels = ARGV + + c.plugins.plugins = [WikiLink] end helpers do @@ -28,6 +34,7 @@ def issue(section, issue) end return url end + def wiki(sections, search) actualresults = [] sections.each do |section| @@ -67,82 +74,6 @@ def latest(plugins) return results[0..-3] end end - # TODO: Move these to a file - on :message, /^wiki$/i do |m| - if m.channel.opped?(m.user) || m.channel.voiced?(m.user) - m.reply "https://github.com/Multiverse/Multiverse-Core/wiki/" - end - end - - on :message, /^ci$/i do |m| - if m.channel.opped?(m.user) || m.channel.voiced?(m.user) - m.reply "http://ci.onarandombox.com/job/Multiverse-Core" - end - end - - on :message, /^forum$/i do |m| - if m.channel.opped?(m.user) || m.channel.voiced?(m.user) - m.reply "http://forums.bukkit.org/threads/3707/page-9999" - end - end - - on :message, /^latest$/i do |m| - if m.channel.opped?(m.user) || m.channel.voiced?(m.user) - m.reply(latest(nil)) - end - end - - on :message, "fish" do |m| - if m.user.authname == "fernferret" - m.reply "Hello master Fern..." - bot.logger.debug m.user - end - end - - on :message, /(hello|hi|greetings)\s*baxter/i do |m| - if m.channel.opped?(m.user) || m.channel.voiced?(m.user) - greetings = ["Hello", "Bonjour", "Hi", "Aloha", "Sup"] - m.reply(greetings[rand(greetings.size)] + " #{m.user.nick}!") - end - end - - on :message, "help" do |m| - m.user.send("Hi, My name is Baxter and I'm a super helpful bot.") - m.user.send("I'm here to help, but I'm currently being developed.") - m.user.send("Only OPs and VOICEs in #multiverse can use me for now!") - end - - on :message, /!issue-?([cpnsa])\s?#(\d+)/i do |m, type, issue| - if m.user.authname == "fernferret" - m.reply "Hello master Fern..." - m.reply(issue(type, issue)) - elsif m.channel.opped?(m.user) - m.reply "Hello cool person #{m.user.nick}!" - m.reply(issue(type, issue)) - elsif m.channel.voiced?(m.user) - m.reply "Hello super person #{m.user.nick}!" - m.reply(issue(type, issue)) - end - end - - on :message, /!wiki-?([cpnsa])\s?:(.+)/i do |m, type, page| - if m.channel.opped?(m.user) || m.channel.voiced?(m.user) - wikiresults = wiki([type], page) - wikiresults.each do |result| - m.reply(result) - end - end - end - - on :message, /!wiki\s?:(.+)/i do |m, page| - if m.channel.opped?(m.user) || m.channel.voiced?(m.user) - wikiresults = wiki(["c", "p", "n", "s"], page) - wikiresults.each do |result| - m.reply(result) - end - end - end end bot.start - diff --git a/handlers.rb b/handlers.rb new file mode 100644 index 0000000..c14cdb4 --- /dev/null +++ b/handlers.rb @@ -0,0 +1,81 @@ +class WikiLink + include Cinch::Plugin + + match "wiki" + + def execute(m) + bot.logger.debug "Someone said wiki" + if m.channel.opped?(m.user) || m.channel.voiced?(m.user) + m.reply "https://github.com/Multiverse/Multiverse-Core/wiki/" + end + end +end + +# on :message, /^ci$/i do |m| +# if m.channel.opped?(m.user) || m.channel.voiced?(m.user) +# m.reply "http://ci.onarandombox.com/job/Multiverse-Core" +# end +# end +# +# on :message, /^forum$/i do |m| +# if m.channel.opped?(m.user) || m.channel.voiced?(m.user) +# m.reply "http://forums.bukkit.org/threads/3707/page-9999" +# end +# end +# +# on :message, /^latest$/i do |m| +# if m.channel.opped?(m.user) || m.channel.voiced?(m.user) +# m.reply(latest(nil)) +# end +# end +# +# on :message, "fish" do |m| +# if m.user.authname == "fernferret" +# m.reply "Hello master Fern..." +# bot.logger.debug m.user +# end +# end +# +# on :message, /(hello|hi|greetings)\s*baxter/i do |m| +# if m.channel.opped?(m.user) || m.channel.voiced?(m.user) +# greetings = ["Hello", "Bonjour", "Hi", "Aloha", "Sup"] +# m.reply(greetings[rand(greetings.size)] + " #{m.user.nick}!") +# end +# end +# +# on :message, "help" do |m| +# m.user.send("Hi, My name is Baxter and I'm a super helpful bot.") +# m.user.send("I'm here to help, but I'm currently being developed.") +# m.user.send("Only OPs and VOICEs in #multiverse can use me for now!") +# end +# +# on :message, /!issue-?([cpnsa])\s?#(\d+)/i do |m, type, issue| +# if m.user.authname == "fernferret" +# m.reply "Hello master Fern..." +# m.reply(issue(type, issue)) +# elsif m.channel.opped?(m.user) +# m.reply "Hello cool person #{m.user.nick}!" +# m.reply(issue(type, issue)) +# elsif m.channel.voiced?(m.user) +# m.reply "Hello super person #{m.user.nick}!" +# m.reply(issue(type, issue)) +# end +# end +# +# on :message, /!wiki-?([cpnsa])\s?:(.+)/i do |m, type, page| +# if m.channel.opped?(m.user) || m.channel.voiced?(m.user) +# wikiresults = wiki([type], page) +# wikiresults.each do |result| +# m.reply(result) +# end +# end +# end +# +# on :message, /!wiki\s?:(.+)/i do |m, page| +# if m.channel.opped?(m.user) || m.channel.voiced?(m.user) +# wikiresults = wiki(["c", "p", "n", "s"], page) +# wikiresults.each do |result| +# m.reply(result) +# end +# end +# end From deb61f578641a4bdac547f0bb589ac4498acd101 Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Thu, 5 Jan 2012 23:27:06 -0500 Subject: [PATCH 2/5] Reimplement handlers as Cinch plugins Also compresses down wiki handlers into a single handler using regex magic and judicious ternary operators. (Told you it was refactor time.) --- Baxter.rb | 51 +----------- handlers.rb | 219 +++++++++++++++++++++++++++++++++++----------------- 2 files changed, 150 insertions(+), 120 deletions(-) diff --git a/Baxter.rb b/Baxter.rb index 2d510fa..327d71b 100755 --- a/Baxter.rb +++ b/Baxter.rb @@ -13,66 +13,19 @@ bot = Cinch::Bot.new do configure do |c| - c.server = "irc.esper.net" + c.server = "localhost" c.nick = "MV-Baxter" c.user = $config.get_value('username') c.password = $config.get_value('password') c.channels = ARGV - c.plugins.plugins = [WikiLink] + c.plugins.plugins = [CoreWiki, CI, Forum, Latest, Greetings, Help, Issue, Wiki] end helpers do # https://github.com/Multiverse/Multiverse-Core/issues/354 - def issue(section, issue) - actualsection = $urlhelpers[section] - url = "https://github.com/Multiverse/Multiverse-#{actualsection}/issues/#{CGI.escape(issue)}" - begin - doc = Nokogiri::HTML(open(url)) - rescue OpenURI::HTTPError - return "Sorry, issue ##{issue} didn't exist on #{actualsection}!" - end - return url - end - def wiki(sections, search) - actualresults = [] - sections.each do |section| - actualsection = $urlhelpers[section] - url = "https://github.com/Multiverse/Multiverse-#{actualsection}/wiki/_pages" - doc = Nokogiri::HTML(open(url)) - if doc == nil - return "Couldn't find the #{actualsection} wiki!!!" - end - things = doc.xpath("//div[@id='template']//ul//li//a") - pagelist = things.map{|link| [link.children.text, link['href']]} - pagelist.each do |result| - if(result[0].downcase.include?(CGI.escape(search))) - actualresults<<"http://github.com" + result[1] - end - end - end - if actualresults.count > 3 - return actualresults[0, 5]<<"..." - elsif actualresults.count == 0 - return ["No results found :("] - end - return actualresults - end - def latest(plugins) - if plugins == nil - plugins = ["c", "p", "n", "s", "a"] - end - results = "" - plugins.each do |plugin| - actual = $urlhelpers[plugin] - url = "http://ci.onarandombox.com/job/Multiverse-#{actual}/lastSuccessfulBuild/" - doc = Nokogiri::HTML(open(url)) - results<<"#{actual} " + doc.xpath("//h1").first.text.strip.gsub(/\s+\(.*\)/, ", ") - end - return results[0..-3] - end end end diff --git a/handlers.rb b/handlers.rb index c14cdb4..4d0219d 100644 --- a/handlers.rb +++ b/handlers.rb @@ -1,81 +1,158 @@ -class WikiLink +class CoreWiki include Cinch::Plugin - match "wiki" + match /wiki$/ def execute(m) - bot.logger.debug "Someone said wiki" if m.channel.opped?(m.user) || m.channel.voiced?(m.user) m.reply "https://github.com/Multiverse/Multiverse-Core/wiki/" end end end -# on :message, /^ci$/i do |m| -# if m.channel.opped?(m.user) || m.channel.voiced?(m.user) -# m.reply "http://ci.onarandombox.com/job/Multiverse-Core" -# end -# end -# -# on :message, /^forum$/i do |m| -# if m.channel.opped?(m.user) || m.channel.voiced?(m.user) -# m.reply "http://forums.bukkit.org/threads/3707/page-9999" -# end -# end -# -# on :message, /^latest$/i do |m| -# if m.channel.opped?(m.user) || m.channel.voiced?(m.user) -# m.reply(latest(nil)) -# end -# end -# -# on :message, "fish" do |m| -# if m.user.authname == "fernferret" -# m.reply "Hello master Fern..." -# bot.logger.debug m.user -# end -# end -# -# on :message, /(hello|hi|greetings)\s*baxter/i do |m| -# if m.channel.opped?(m.user) || m.channel.voiced?(m.user) -# greetings = ["Hello", "Bonjour", "Hi", "Aloha", "Sup"] -# m.reply(greetings[rand(greetings.size)] + " #{m.user.nick}!") -# end -# end -# -# on :message, "help" do |m| -# m.user.send("Hi, My name is Baxter and I'm a super helpful bot.") -# m.user.send("I'm here to help, but I'm currently being developed.") -# m.user.send("Only OPs and VOICEs in #multiverse can use me for now!") -# end -# -# on :message, /!issue-?([cpnsa])\s?#(\d+)/i do |m, type, issue| -# if m.user.authname == "fernferret" -# m.reply "Hello master Fern..." -# m.reply(issue(type, issue)) -# elsif m.channel.opped?(m.user) -# m.reply "Hello cool person #{m.user.nick}!" -# m.reply(issue(type, issue)) -# elsif m.channel.voiced?(m.user) -# m.reply "Hello super person #{m.user.nick}!" -# m.reply(issue(type, issue)) -# end -# end -# -# on :message, /!wiki-?([cpnsa])\s?:(.+)/i do |m, type, page| -# if m.channel.opped?(m.user) || m.channel.voiced?(m.user) -# wikiresults = wiki([type], page) -# wikiresults.each do |result| -# m.reply(result) -# end -# end -# end -# -# on :message, /!wiki\s?:(.+)/i do |m, page| -# if m.channel.opped?(m.user) || m.channel.voiced?(m.user) -# wikiresults = wiki(["c", "p", "n", "s"], page) -# wikiresults.each do |result| -# m.reply(result) -# end -# end -# end +class CI + include Cinch::Plugin + + match /ci$/ + + def execute(m) + if m.channel.opped?(m.user) || m.channel.voiced?(m.user) + m.reply "http://ci.onarandombox.com/job/Multiverse-Core" + end + end +end + +class Forum + include Cinch::Plugin + + match /forum$/ + + def execute(m) + if m.channel.opped?(m.user) || m.channel.voiced?(m.user) + m.reply "http://forums.bukkit.org/threads/3707/page-9999" + end + end +end + +class Latest + include Cinch::Plugin + + match /latest$/i + + def latest(plugins) + if plugins == nil + plugins = ["c", "p", "n", "s", "a"] + end + results = "" + plugins.each do |plugin| + actual = $urlhelpers[plugin] + url = "http://ci.onarandombox.com/job/Multiverse-#{actual}/lastSuccessfulBuild/" + doc = Nokogiri::HTML(open(url)) + results<<"#{actual} " + doc.xpath("//h1").first.text.strip.gsub(/\s+\(.*\)/, ", ") + end + return results[0..-3] + end + + def execute(m) + if m.channel.opped?(m.user) || m.channel.voiced?(m.user) + m.reply(self.latest(nil)) + end + end +end + +class Greetings + include Cinch::Plugin + + match /(hello|hi|greetings)\s*baxter/i + + def execute(m) + if m.channel.opped?(m.user) || m.channel.voiced?(m.user) + greetings = ["Hello", "Bonjour", "Hi", "Aloha", "Sup"] + m.reply(greetings[rand(greetings.size)] + " #{m.user.nick}!") + end + end +end + +class Help + include Cinch::Plugin + + match "help" + + def execute(m) + m.user.send("Hi, My name is Baxter and I'm a super helpful bot.") + m.user.send("I'm here to help, but I'm currently being developed.") + m.user.send("Only OPs and VOICEs in #multiverse can use me for now!") + end +end + +class Issue + include Cinch::Plugin + + match /issue-?([cpnsa])\s?#(\d+)/i + + def issue(section, issue) + actualsection = $urlhelpers[section] + url = "https://github.com/Multiverse/Multiverse-#{actualsection}/issues/#{CGI.escape(issue)}" + begin + doc = Nokogiri::HTML(open(url)) + rescue OpenURI::HTTPError + return "Sorry, issue ##{issue} didn't exist on #{actualsection}!" + end + return url + end + + def execute(m, type, issue) + if m.user.authname == "fernferret" + m.reply "Hello master Fern..." + m.reply(self.issue(type, issue)) + elsif m.channel.opped?(m.user) + m.reply "Hello cool person #{m.user.nick}!" + m.reply(self.issue(type, issue)) + elsif m.channel.voiced?(m.user) + m.reply "Hello super person #{m.user.nick}!" + m.reply(self.issue(type, issue)) + end + end +end + +class Wiki + include Cinch::Plugin + + match /wiki(?:-?([cpnsa]))?\s?:(.+)/i + + def wiki(sections, search) + actualresults = [] + sections.each do |section| + actualsection = $urlhelpers[section] + url = "https://github.com/Multiverse/Multiverse-#{actualsection}/wiki/_pages" + doc = Nokogiri::HTML(open(url)) + if doc == nil + return "Couldn't find the #{actualsection} wiki!!!" + end + things = doc.xpath("//div[@id='template']//ul//li//a") + pagelist = things.map{|link| [link.children.text, link['href']]} + pagelist.each do |result| + if(result[0].downcase.include?(CGI.escape(search))) + actualresults<<"http://github.com" + result[1] + end + end + end + if actualresults.count > 3 + return actualresults[0, 5]<<"..." + elsif actualresults.count == 0 + return ["No results found :("] + end + return actualresults + end + + def execute(m, type, page) + self.bot.logger.debug type + if m.channel.opped?(m.user) || m.channel.voiced?(m.user) + type = (type.nil? && ["c", "p", "n", "s"]) || [type] + wikiresults = wiki(type, page) + wikiresults.each do |result| + m.reply(result) + end + end + end +end From 9c50b82ee5c84067519db97626cec935666761bb Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Thu, 5 Jan 2012 23:30:13 -0500 Subject: [PATCH 3/5] Fix the server. Oops --- Baxter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Baxter.rb b/Baxter.rb index 327d71b..6388caf 100755 --- a/Baxter.rb +++ b/Baxter.rb @@ -13,7 +13,7 @@ bot = Cinch::Bot.new do configure do |c| - c.server = "localhost" + c.server = "irc.esper.net" c.nick = "MV-Baxter" c.user = $config.get_value('username') c.password = $config.get_value('password') From 31f994a52a140b4f19ddc5b41db94d75b27bc4cc Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Fri, 6 Jan 2012 17:09:55 -0500 Subject: [PATCH 4/5] Break out handlers into several files Also minor fixes for page scraping --- Baxter.rb | 16 ++--- handlers.rb | 158 ------------------------------------------ handlers/CI.rb | 11 +++ handlers/CoreWiki.rb | 11 +++ handlers/Forum.rb | 11 +++ handlers/Greetings.rb | 12 ++++ handlers/Help.rb | 11 +++ handlers/Issue.rb | 27 ++++++++ handlers/Latest.rb | 25 +++++++ handlers/Wiki.rb | 41 +++++++++++ 10 files changed, 156 insertions(+), 167 deletions(-) delete mode 100644 handlers.rb create mode 100644 handlers/CI.rb create mode 100644 handlers/CoreWiki.rb create mode 100644 handlers/Forum.rb create mode 100644 handlers/Greetings.rb create mode 100644 handlers/Help.rb create mode 100644 handlers/Issue.rb create mode 100644 handlers/Latest.rb create mode 100644 handlers/Wiki.rb diff --git a/Baxter.rb b/Baxter.rb index 6388caf..dd08874 100755 --- a/Baxter.rb +++ b/Baxter.rb @@ -9,23 +9,21 @@ $urlhelpers = Hash["c" => "Core", "p" => "Portals", "n" => "NetherPortals", "s" => "SignPortals", "a" => "Adventure"] $authrequired = true -require './handlers.rb' +$plugins = [] +Dir['./handlers/*.rb'].each do |f| + require f + $plugins << Kernel.const_get(File.basename(f, ".rb")) +end bot = Cinch::Bot.new do configure do |c| - c.server = "irc.esper.net" + c.server = "localhost" c.nick = "MV-Baxter" c.user = $config.get_value('username') c.password = $config.get_value('password') c.channels = ARGV - c.plugins.plugins = [CoreWiki, CI, Forum, Latest, Greetings, Help, Issue, Wiki] - end - - helpers do - # https://github.com/Multiverse/Multiverse-Core/issues/354 - - + c.plugins.plugins = $plugins end end diff --git a/handlers.rb b/handlers.rb deleted file mode 100644 index 4d0219d..0000000 --- a/handlers.rb +++ /dev/null @@ -1,158 +0,0 @@ -class CoreWiki - include Cinch::Plugin - - match /wiki$/ - - def execute(m) - if m.channel.opped?(m.user) || m.channel.voiced?(m.user) - m.reply "https://github.com/Multiverse/Multiverse-Core/wiki/" - end - end -end - -class CI - include Cinch::Plugin - - match /ci$/ - - def execute(m) - if m.channel.opped?(m.user) || m.channel.voiced?(m.user) - m.reply "http://ci.onarandombox.com/job/Multiverse-Core" - end - end -end - -class Forum - include Cinch::Plugin - - match /forum$/ - - def execute(m) - if m.channel.opped?(m.user) || m.channel.voiced?(m.user) - m.reply "http://forums.bukkit.org/threads/3707/page-9999" - end - end -end - -class Latest - include Cinch::Plugin - - match /latest$/i - - def latest(plugins) - if plugins == nil - plugins = ["c", "p", "n", "s", "a"] - end - results = "" - plugins.each do |plugin| - actual = $urlhelpers[plugin] - url = "http://ci.onarandombox.com/job/Multiverse-#{actual}/lastSuccessfulBuild/" - doc = Nokogiri::HTML(open(url)) - results<<"#{actual} " + doc.xpath("//h1").first.text.strip.gsub(/\s+\(.*\)/, ", ") - end - return results[0..-3] - end - - def execute(m) - if m.channel.opped?(m.user) || m.channel.voiced?(m.user) - m.reply(self.latest(nil)) - end - end -end - -class Greetings - include Cinch::Plugin - - match /(hello|hi|greetings)\s*baxter/i - - def execute(m) - if m.channel.opped?(m.user) || m.channel.voiced?(m.user) - greetings = ["Hello", "Bonjour", "Hi", "Aloha", "Sup"] - m.reply(greetings[rand(greetings.size)] + " #{m.user.nick}!") - end - end -end - -class Help - include Cinch::Plugin - - match "help" - - def execute(m) - m.user.send("Hi, My name is Baxter and I'm a super helpful bot.") - m.user.send("I'm here to help, but I'm currently being developed.") - m.user.send("Only OPs and VOICEs in #multiverse can use me for now!") - end -end - -class Issue - include Cinch::Plugin - - match /issue-?([cpnsa])\s?#(\d+)/i - - def issue(section, issue) - actualsection = $urlhelpers[section] - url = "https://github.com/Multiverse/Multiverse-#{actualsection}/issues/#{CGI.escape(issue)}" - begin - doc = Nokogiri::HTML(open(url)) - rescue OpenURI::HTTPError - return "Sorry, issue ##{issue} didn't exist on #{actualsection}!" - end - return url - end - - def execute(m, type, issue) - if m.user.authname == "fernferret" - m.reply "Hello master Fern..." - m.reply(self.issue(type, issue)) - elsif m.channel.opped?(m.user) - m.reply "Hello cool person #{m.user.nick}!" - m.reply(self.issue(type, issue)) - elsif m.channel.voiced?(m.user) - m.reply "Hello super person #{m.user.nick}!" - m.reply(self.issue(type, issue)) - end - end -end - -class Wiki - include Cinch::Plugin - - match /wiki(?:-?([cpnsa]))?\s?:(.+)/i - - def wiki(sections, search) - actualresults = [] - sections.each do |section| - actualsection = $urlhelpers[section] - url = "https://github.com/Multiverse/Multiverse-#{actualsection}/wiki/_pages" - doc = Nokogiri::HTML(open(url)) - if doc == nil - return "Couldn't find the #{actualsection} wiki!!!" - end - things = doc.xpath("//div[@id='template']//ul//li//a") - pagelist = things.map{|link| [link.children.text, link['href']]} - pagelist.each do |result| - if(result[0].downcase.include?(CGI.escape(search))) - actualresults<<"http://github.com" + result[1] - end - end - end - if actualresults.count > 3 - return actualresults[0, 5]<<"..." - elsif actualresults.count == 0 - return ["No results found :("] - end - return actualresults - end - - def execute(m, type, page) - self.bot.logger.debug type - if m.channel.opped?(m.user) || m.channel.voiced?(m.user) - type = (type.nil? && ["c", "p", "n", "s"]) || [type] - wikiresults = wiki(type, page) - wikiresults.each do |result| - m.reply(result) - end - end - end -end diff --git a/handlers/CI.rb b/handlers/CI.rb new file mode 100644 index 0000000..fcc7e07 --- /dev/null +++ b/handlers/CI.rb @@ -0,0 +1,11 @@ +class CI + include Cinch::Plugin + + match /ci$/ + + def execute(m) + if m.channel.opped?(m.user) || m.channel.voiced?(m.user) + m.reply "http://ci.onarandombox.com/job/Multiverse-Core" + end + end +end diff --git a/handlers/CoreWiki.rb b/handlers/CoreWiki.rb new file mode 100644 index 0000000..34ec35e --- /dev/null +++ b/handlers/CoreWiki.rb @@ -0,0 +1,11 @@ +class CoreWiki + include Cinch::Plugin + + match /wiki$/ + + def execute(m) + if m.channel.opped?(m.user) || m.channel.voiced?(m.user) + m.reply "https://github.com/Multiverse/Multiverse-Core/wiki/" + end + end +end diff --git a/handlers/Forum.rb b/handlers/Forum.rb new file mode 100644 index 0000000..f7fb1bc --- /dev/null +++ b/handlers/Forum.rb @@ -0,0 +1,11 @@ +class Forum + include Cinch::Plugin + + match /forum$/ + + def execute(m) + if m.channel.opped?(m.user) || m.channel.voiced?(m.user) + m.reply "http://forums.bukkit.org/threads/3707/page-9999" + end + end +end diff --git a/handlers/Greetings.rb b/handlers/Greetings.rb new file mode 100644 index 0000000..2e7cca3 --- /dev/null +++ b/handlers/Greetings.rb @@ -0,0 +1,12 @@ +class Greetings + include Cinch::Plugin + + match /(hello|hi|greetings)\s*baxter/i + + def execute(m) + if m.channel.opped?(m.user) || m.channel.voiced?(m.user) + greetings = ["Hello", "Bonjour", "Hi", "Aloha", "Sup"] + m.reply(greetings[rand(greetings.size)] + " #{m.user.nick}!") + end + end +end diff --git a/handlers/Help.rb b/handlers/Help.rb new file mode 100644 index 0000000..482a30b --- /dev/null +++ b/handlers/Help.rb @@ -0,0 +1,11 @@ +class Help + include Cinch::Plugin + + match "help" + + def execute(m) + m.user.send("Hi, My name is Baxter and I'm a super helpful bot.") + m.user.send("I'm here to help, but I'm currently being developed.") + m.user.send("Only OPs and VOICEs in #multiverse can use me for now!") + end +end diff --git a/handlers/Issue.rb b/handlers/Issue.rb new file mode 100644 index 0000000..9351e95 --- /dev/null +++ b/handlers/Issue.rb @@ -0,0 +1,27 @@ +class Issue + include Cinch::Plugin + + match /issue-?([cpnsa])\s?#(\d+)/i + + def issue(section, issue) + actualsection = $urlhelpers[section] + url = "https://github.com/Multiverse/Multiverse-#{actualsection}/issues/#{CGI.escape(issue)}" + begin + doc = Nokogiri::HTML(open(url)) + rescue OpenURI::HTTPError + return "Sorry, issue ##{issue} didn't exist on #{actualsection}!" + end + return url + end + + def execute(m, type, issue) + if m.user.authname == "fernferret" + m.reply "Hello master Fern..." + m.reply(self.issue(type, issue)) + elsif m.channel.opped?(m.user) + m.reply(self.issue(type, issue)) + elsif m.channel.voiced?(m.user) + m.reply(self.issue(type, issue)) + end + end +end diff --git a/handlers/Latest.rb b/handlers/Latest.rb new file mode 100644 index 0000000..108845c --- /dev/null +++ b/handlers/Latest.rb @@ -0,0 +1,25 @@ +class Latest + include Cinch::Plugin + + match /latest$/i + + def latest(plugins) + if plugins == nil + plugins = ["c", "p", "n", "s", "a"] + end + results = "" + plugins.each do |plugin| + actual = $urlhelpers[plugin] + url = "http://ci.onarandombox.com/job/Multiverse-#{actual}/lastSuccessfulBuild/" + doc = Nokogiri::HTML(open(url)) + results<<"#{actual} " + doc.xpath("//h1").first.text.strip.gsub(/\s+\(.*\)/, ", ") + end + return results[0..-3] + end + + def execute(m) + if m.channel.opped?(m.user) || m.channel.voiced?(m.user) + m.reply(self.latest(nil)) + end + end +end diff --git a/handlers/Wiki.rb b/handlers/Wiki.rb new file mode 100644 index 0000000..d7b1025 --- /dev/null +++ b/handlers/Wiki.rb @@ -0,0 +1,41 @@ +class Wiki + include Cinch::Plugin + + match /wiki(?:-?([cpnsa]))?\s?:(.+)/i + + def wiki(sections, search) + actualresults = [] + sections.each do |section| + actualsection = $urlhelpers[section] + url = "https://github.com/Multiverse/Multiverse-#{actualsection}/wiki/_pages" + doc = Nokogiri::HTML(open(url)) + if doc == nil + return ["Couldn't find the #{actualsection} wiki!!!"] + end + things = doc.xpath("//div[@id='wiki-content']//ul//li//a") + pagelist = things.map{|link| [link.children.text, link['href']]} + pagelist.each do |result| + if(result[0].downcase.include?(CGI.escape(search))) + actualresults<<"http://github.com" + result[1] + end + end + end + if actualresults.count > 3 + return actualresults[0, 5]<<"..." + elsif actualresults.count == 0 + return ["No results found :("] + end + return actualresults + end + + def execute(m, type, page) + type = (type.nil? && ["c", "p", "n", "s"]) || [type] + self.bot.logger.debug type + if m.channel.opped?(m.user) || m.channel.voiced?(m.user) + wikiresults = self.wiki(type, page) + wikiresults.each do |result| + m.reply(result) + end + end + end +end From 133336d4004a1b6bc05c962b95fdbb46c0ccce9a Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Fri, 6 Jan 2012 17:13:54 -0500 Subject: [PATCH 5/5] Fix the server again. Grrrr --- Baxter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Baxter.rb b/Baxter.rb index dd08874..10791bc 100755 --- a/Baxter.rb +++ b/Baxter.rb @@ -17,7 +17,7 @@ bot = Cinch::Bot.new do configure do |c| - c.server = "localhost" + c.server = "irc.esper.net" c.nick = "MV-Baxter" c.user = $config.get_value('username') c.password = $config.get_value('password')