From 09591b03d12df84c45dd7125ed8db69ba6bdd84b Mon Sep 17 00:00:00 2001 From: Marrub Date: Sun, 24 Feb 2019 06:01:46 -0500 Subject: [PATCH] split quote/fun modules --- source/modules/fun.rb | 31 +------------------------------ source/modules/qdb.rb | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 30 deletions(-) create mode 100644 source/modules/qdb.rb diff --git a/source/modules/fun.rb b/source/modules/fun.rb index 9b51d2f..fc3c3c6 100644 --- a/source/modules/fun.rb +++ b/source/modules/fun.rb @@ -1,12 +1,7 @@ -require 'open-uri' -require 'json' - class Mod_Fun < Vrobot4::Module::Module def self.type() "Fun" end Vrobot4::Module.add_module_type self - QDB = "http://greyserv.net/qdb" - def initialize info super register :c_carmack, "carmack", "mmmmmmmmmm" @@ -16,7 +11,6 @@ class Mod_Fun < Vrobot4::Module::Module register :c_box, "box", "S H I T P O S T I N G" register :c_zdoom, "zdoom", "ZDoom™" register :c_marble, "marble", "mararuaruaruaruarb" - register :c_quote, "quote", "Queries the Doominati Quote Database." register :c_what, "what", "What the fuck did you just fucking say about" end @@ -40,7 +34,7 @@ class Mod_Fun < Vrobot4::Module::Module end def c_marble m, argv - check_args argv, "", "N" + check_args argv, "N" if argv.empty? then n = 20 else n = argv.to_i end @@ -57,29 +51,6 @@ class Mod_Fun < Vrobot4::Module::Module m.reply text end - def c_quote m, argv - if argv.empty? - q, num = nil, nil - max = JSON.parse(open(QDB + "/interface.cgi").read)["numQuotes"] - loop do - num = rand(max) + 1 - q = open(QDB + "/q/" + num.to_s).read - break unless m.serv.flags.include? "L" and - (q.lines.count > 4 or q.length > 1000) - end - m.reply_b "Quote %i:\n" % [num] + q - elsif Vrobot4.is_num? argv - m.reply_b open(QDB + "/q/" + argv.to_i.to_s).read - else - raise ArgumentError, "Invalid query" if argv.include? ?& - q = URI.escape argv - info = JSON.parse(open(QDB + "/interface.cgi?query=" + q).read) - raise ArgumentError, "No results" unless info["searchResults"].any? - res = info["searchResults"].sample - m.reply_b "Quote %i:\n" % [res] + open(QDB + "/q/" + res.to_s).read - end - end - def c_what m, argv if m.serv.flags.include? ?L m.reply "What the fuck did you just fucking say about me, you little bitch?" diff --git a/source/modules/qdb.rb b/source/modules/qdb.rb new file mode 100644 index 0000000..83f0ac0 --- /dev/null +++ b/source/modules/qdb.rb @@ -0,0 +1,39 @@ +require 'open-uri' +require 'json' + +class Mod_QDB < Vrobot4::Module::Module + def self.type() "QDB" end + Vrobot4::Module.add_module_type self + + QDB = "http://greyserv.net/qdb" + + def initialize info + super + register :c_quote, "quote", "Queries the Doominati Quote Database." + end + + def c_quote m, argv + if argv.empty? + q, num = nil, nil + max = JSON.parse(open(QDB + "/interface.cgi").read)["numQuotes"] + loop do + num = rand(max) + 1 + q = open(QDB + "/q/" + num.to_s).read + break unless m.serv.flags.include? "L" and + (q.lines.count > 4 or q.length > 1000) + end + m.reply_b "Quote %i:\n" % [num] + q + elsif Vrobot4.is_num? argv + m.reply_b open(QDB + "/q/" + argv.to_i.to_s).read + else + raise ArgumentError, "Invalid query" if argv.include? ?& + q = URI.escape argv + info = JSON.parse(open(QDB + "/interface.cgi?query=" + q).read) + raise ArgumentError, "No results" unless info["searchResults"].any? + res = info["searchResults"].sample + m.reply_b "Quote %i:\n" % [res] + open(QDB + "/q/" + res.to_s).read + end + end +end + +## EOF