Add minor code clean-up
parent
a52e788a3f
commit
64bacccb8b
|
@ -1,5 +1,5 @@
|
||||||
module Vrobot4
|
module Vrobot4
|
||||||
Version = '4.00'.freeze
|
Version = "4.00".freeze
|
||||||
|
|
||||||
@@debug = 0
|
@@debug = 0
|
||||||
def self.debug= set; @@debug = set; end
|
def self.debug= set; @@debug = set; end
|
||||||
|
@ -9,11 +9,14 @@ module Vrobot4
|
||||||
if (lv != :DEBUG || @@debug >= 1) &&
|
if (lv != :DEBUG || @@debug >= 1) &&
|
||||||
(lv != :DEBUGV || @@debug >= 2)
|
(lv != :DEBUGV || @@debug >= 2)
|
||||||
puts "[" + lv.to_s.ljust(6) + "] " + text.join(" ")
|
puts "[" + lv.to_s.ljust(6) + "] " + text.join(" ")
|
||||||
|
true
|
||||||
|
else
|
||||||
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.is_num? s
|
def self.is_num? str
|
||||||
/\A[-+]?[0-9]*\.?[0-9]+\Z/ === s
|
/\A[-+]?[0-9]*\.?[0-9]+\Z/ === str
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -30,13 +30,11 @@ module Vrobot4
|
||||||
thrds.each {|th| th.join}
|
thrds.each {|th| th.join}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.main cfgname
|
def self.main cfg
|
||||||
cfg = nil
|
|
||||||
|
|
||||||
log :INFO, "vrobot version", Version
|
log :INFO, "vrobot version", Version
|
||||||
|
|
||||||
begin
|
begin
|
||||||
cfg = YAML.load IO.read(cfgname)
|
cfg = YAML.load cfg.read
|
||||||
rescue
|
rescue
|
||||||
log :ERROR, "error reading bot config:", $!
|
log :ERROR, "error reading bot config:", $!
|
||||||
return
|
return
|
||||||
|
@ -59,6 +57,6 @@ module Vrobot4
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Vrobot4.main "bot.yml"
|
Vrobot4.main open("bot.yml")
|
||||||
|
|
||||||
## EOF
|
## EOF
|
||||||
|
|
|
@ -64,7 +64,7 @@ module Vrobot4::Server
|
||||||
Vrobot4.debug = argv[0].to_i
|
Vrobot4.debug = argv[0].to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
def onCommand m, cnam, argv
|
def on_command m, cnam, argv
|
||||||
Vrobot4.log :DEBUGV, "command", cnam.to_s, argv.to_s
|
Vrobot4.log :DEBUGV, "command", cnam.to_s, argv.to_s
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,6 +33,7 @@ class Mod_DoomRLA < Vrobot4::Module::Module
|
||||||
def c_weaponinfo m, argv
|
def c_weaponinfo m, argv
|
||||||
name = argv.join(" ")
|
name = argv.join(" ")
|
||||||
w = @winfo.select {|wep| wep if wep["Name"].casecmp? name}[0]
|
w = @winfo.select {|wep| wep if wep["Name"].casecmp? name}[0]
|
||||||
|
raise ArgumentError, "Weapon not found" if w == nil
|
||||||
t = "%s %s damage\n" % [w["Damage"], w["DamageType"]]
|
t = "%s %s damage\n" % [w["Damage"], w["DamageType"]]
|
||||||
t << "%s shots\n" % [w["Shots"]] if w["Shots"].to_i > 1
|
t << "%s shots\n" % [w["Shots"]] if w["Shots"].to_i > 1
|
||||||
t << "Uses %s %s\n" % [w["AmmoUsage"], w["AmmoType"]] \
|
t << "Uses %s %s\n" % [w["AmmoUsage"], w["AmmoType"]] \
|
||||||
|
@ -53,10 +54,12 @@ class Mod_DoomRLA < Vrobot4::Module::Module
|
||||||
|
|
||||||
def c_monsterinfo m, argv
|
def c_monsterinfo m, argv
|
||||||
name = argv.join(" ")
|
name = argv.join(" ")
|
||||||
@minfo.select do |mon|
|
mi = @minfo.select do |mon|
|
||||||
mon if mon["Name"].casecmp? name or
|
mon if mon["Name"].casecmp? name or
|
||||||
mon["Tags"].split(", ").include? name
|
mon["Tags"].split(", ").include? name
|
||||||
end .first(3).each do |w|
|
end
|
||||||
|
raise ArgumentError, "No monsters found" if mi == nil
|
||||||
|
mi.first(3).each do |w|
|
||||||
t = "%i Health\n" % [w["Health"]]
|
t = "%i Health\n" % [w["Health"]]
|
||||||
t << "Resistances: %s\n" % [w["Resistances"]]
|
t << "Resistances: %s\n" % [w["Resistances"]]
|
||||||
t << "Drops: %s\n" % [w["ItemDrops"]] if w["ItemDrops"]
|
t << "Drops: %s\n" % [w["ItemDrops"]] if w["ItemDrops"]
|
||||||
|
|
|
@ -64,7 +64,8 @@ class Mod_Fun < Vrobot4::Module::Module
|
||||||
argv = argv.join(" ")
|
argv = argv.join(" ")
|
||||||
if argv.length == 0
|
if argv.length == 0
|
||||||
max = JSON.parse(open(QDB + "/interface.cgi").read)["numQuotes"]
|
max = JSON.parse(open(QDB + "/interface.cgi").read)["numQuotes"]
|
||||||
m.reply_b open(QDB + "/q/" + (rand(max) + 1).to_s).read
|
num = rand(max) + 1
|
||||||
|
m.reply_b "Quote %i:\n" % [num] + open(QDB + "/q/" + num.to_s).read
|
||||||
elsif Vrobot4.is_num? argv
|
elsif Vrobot4.is_num? argv
|
||||||
m.reply_b open(QDB + "/q/" + argv.to_i.to_s).read
|
m.reply_b open(QDB + "/q/" + argv.to_i.to_s).read
|
||||||
else
|
else
|
||||||
|
@ -73,7 +74,7 @@ class Mod_Fun < Vrobot4::Module::Module
|
||||||
info = JSON.parse(open(QDB + "/interface.cgi?query=" + q).read)
|
info = JSON.parse(open(QDB + "/interface.cgi?query=" + q).read)
|
||||||
res = info["searchResults"].sample
|
res = info["searchResults"].sample
|
||||||
raise ArgumentError, "no results found" unless res
|
raise ArgumentError, "no results found" unless res
|
||||||
m.reply_b open(QDB + "/q/" + res.to_s).read
|
m.reply_b "Quote %i:\n" % [res] + open(QDB + "/q/" + res.to_s).read
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,12 +8,11 @@ module Vrobot4::Module
|
||||||
@roles = /[#{roles}]/
|
@roles = /[#{roles}]/
|
||||||
end
|
end
|
||||||
|
|
||||||
def usable_in? m, type
|
def usable_in? m
|
||||||
|
type = @function.owner
|
||||||
role = m.user.roles
|
role = m.user.roles
|
||||||
mprm = m.serv.mprm
|
mprm = m.serv.mprm
|
||||||
retm = true
|
retm, retc, retr = true, false, false
|
||||||
retc = false
|
|
||||||
retr = false
|
|
||||||
retm = mprm[:glob][type] if mprm[:glob].key? type
|
retm = mprm[:glob][type] if mprm[:glob].key? type
|
||||||
retc = mprm[:chan][type][m.chan] if mprm[:chan].key? type
|
retc = mprm[:chan][type][m.chan] if mprm[:chan].key? type
|
||||||
retr = mprm[:role][type].scan /[#{role}]/ if mprm[:role].key? type
|
retr = mprm[:role][type].scan /[#{role}]/ if mprm[:role].key? type
|
||||||
|
@ -32,26 +31,27 @@ module Vrobot4::Module
|
||||||
Vrobot4.log :DEBUG, "initialized", self.to_s
|
Vrobot4.log :DEBUG, "initialized", self.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def register fn, cnam, help, roles: "v"
|
def register fn, cnam, help = nil, roles: "v"
|
||||||
|
help = "No help available for this command." if help == nil
|
||||||
@commands[cnam] = Command.new(self.method(fn), help, roles).freeze
|
@commands[cnam] = Command.new(self.method(fn), help, roles).freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def onMessage m
|
def on_message m
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def onCommand m, cnam, argv
|
def on_command m, cnam, argv
|
||||||
if (cmd = get_cmd m, cnam)
|
if (cmd = get_cmd m, cnam)
|
||||||
begin; cmd.run(m, argv)
|
begin; cmd.run(m, argv)
|
||||||
rescue; m.reply "Error:", $!.to_s; end
|
rescue; m.reply "Error:", $!.to_s; end
|
||||||
return true
|
true
|
||||||
else
|
else
|
||||||
return false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def all_cmds m
|
def all_cmds m
|
||||||
@commands.select {|name, cmd| cmd.usable_in? m, self.class}
|
@commands.select {|name, cmd| cmd.usable_in? m}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_cmd m, name
|
def get_cmd m, name
|
||||||
|
|
|
@ -59,12 +59,12 @@ module Vrobot4::Server
|
||||||
@modules.each {|mod| yield mod}
|
@modules.each {|mod| yield mod}
|
||||||
end
|
end
|
||||||
|
|
||||||
def onMessage m
|
def on_message m
|
||||||
@modules.each {|mod| break if mod.onMessage m}
|
@modules.each {|mod| break if mod.on_message m}
|
||||||
end
|
end
|
||||||
|
|
||||||
def onCommand m, cnam, argv
|
def on_command m, cnam, argv
|
||||||
@modules.each {|mod| break if mod.onCommand m, cnam, argv}
|
@modules.each {|mod| break if mod.on_command m, cnam, argv}
|
||||||
end
|
end
|
||||||
|
|
||||||
def type
|
def type
|
||||||
|
|
|
@ -58,9 +58,9 @@ class Sv_Discord < Vrobot4::Server::AudioServer
|
||||||
if m.msg.start_with? '.'
|
if m.msg.start_with? '.'
|
||||||
argv = m.msg.split
|
argv = m.msg.split
|
||||||
cnam = argv.shift[1..-1]
|
cnam = argv.shift[1..-1]
|
||||||
onCommand m, cnam, argv
|
on_command m, cnam, argv
|
||||||
else
|
else
|
||||||
onMessage m
|
on_message m
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue