Fix over-complicated syntax
Look, I started this project not knowing anything about Ruby, okay? :)master
parent
2cf1c9316e
commit
f987c780f7
|
@ -54,9 +54,12 @@ module Vrobot4::Module
|
|||
# @param argv [Array] array of string arguments
|
||||
# @return [Boolean] if this should block further command callbacks
|
||||
def on_command m, cnam, argv
|
||||
if (cmd = get_cmd m, cnam)
|
||||
begin; cmd.run(m, argv)
|
||||
rescue; m.reply "Error:", $!.to_s; end
|
||||
if (cmd = all_cmds(m)[cnam])
|
||||
begin
|
||||
cmd.run(m, argv)
|
||||
rescue
|
||||
m.reply "Error:", $!.to_s
|
||||
end
|
||||
true
|
||||
else
|
||||
false
|
||||
|
@ -70,14 +73,6 @@ module Vrobot4::Module
|
|||
@commands.select {|name, cmd| cmd.usable_in? m}
|
||||
end
|
||||
|
||||
# Gets a command by name in a specified context.
|
||||
# @param m [Vrobot4::Server::Message] message for context
|
||||
# @return [Vrobot4::Module::Command] command if found, nil if not
|
||||
def get_cmd m, name
|
||||
cmds = all_cmds(m)
|
||||
cmds[name] if cmds.key? name
|
||||
end
|
||||
|
||||
protected
|
||||
# Registers a command into this module.
|
||||
# @param fn [Symbol] name of method to add
|
||||
|
|
|
@ -23,10 +23,10 @@ class Mod_Fun < Vrobot4::Module::Module
|
|||
register :c_what, "what", "What the fuck did you just fucking say about"
|
||||
end
|
||||
|
||||
def c_carmack m, argv; m.reply "m" * (rand(24) + 5) ; end
|
||||
def c_revenant m, argv; m.reply "A" * (rand(24) + 3) ; end
|
||||
def c_wan m, argv; m.reply "wan! " * (rand(10) + 1) ; end
|
||||
def c_nyan m, argv; m.reply "nyan " * (rand(10) + 1) + "~"; end
|
||||
def c_carmack (m, argv) m.reply "m" * (rand(24) + 5) end
|
||||
def c_revenant(m, argv) m.reply "A" * (rand(24) + 3) end
|
||||
def c_wan (m, argv) m.reply "wan! " * (rand(10) + 1) end
|
||||
def c_nyan (m, argv) m.reply "nyan " * (rand(10) + 1) + "~" end
|
||||
|
||||
def c_box m, argv
|
||||
str = argv.join(" ")
|
||||
|
|
|
@ -105,12 +105,12 @@ module Vrobot4::Server
|
|||
# [:reply] Method that sends a message to the specified channel.
|
||||
# [:reply_b] Method that sends a large message to the specified channel.
|
||||
def initialize(**info)
|
||||
@msg = info[:msg] if info.key? :msg
|
||||
@user = info[:user] if info.key? :user
|
||||
@chan = info[:chan] if info.key? :chan
|
||||
@serv = info[:serv] if info.key? :serv
|
||||
@reply = info[:reply] if info.key? :reply
|
||||
@reply_b = info[:reply_b] if info.key? :reply_b
|
||||
@msg = info[:msg]
|
||||
@user = info[:user]
|
||||
@chan = info[:chan]
|
||||
@serv = info[:serv]
|
||||
@reply = info[:reply]
|
||||
@reply_b = info[:reply_b]
|
||||
end
|
||||
|
||||
# Sends a message to the channel this message originated from.
|
||||
|
@ -142,7 +142,7 @@ module Vrobot4::Server
|
|||
mt[:servflags] and mt[:servflags] !~ flags
|
||||
raise ArgumentError, "Module " + mod + " not valid for this server"
|
||||
end
|
||||
@modules << mt[:type].new(@info.key?(mod) ? @info[mod] : nil)
|
||||
@modules << mt[:type].new(@info[mod])
|
||||
end
|
||||
|
||||
# Drops a module from the load list.
|
||||
|
|
|
@ -15,11 +15,8 @@ class Sv_Discord < Vrobot4::Server::AudioServer
|
|||
def initialize info
|
||||
super
|
||||
|
||||
if info.key? "admins"; @ops = info["admins"]
|
||||
else; @ops = []; end
|
||||
|
||||
if info.key? "halfop"; @hop = info["halfop"]
|
||||
else; @hop = []; end
|
||||
@ops = info["admins"] or []
|
||||
@hop = info["halfop"] or []
|
||||
|
||||
@bot = Discordrb::Bot.new \
|
||||
token: info["apikey"],
|
||||
|
@ -91,7 +88,7 @@ class Sv_Discord < Vrobot4::Server::AudioServer
|
|||
@mprm[:chan][mod][perm["channel"]] = true
|
||||
elsif perm.key? "roles"
|
||||
@mprm[:role][mod] = perm["roles"]
|
||||
else
|
||||
elsif perm.key? "enable"
|
||||
@mprm[:glob][mod] = perm["enable"]
|
||||
end
|
||||
end
|
||||
|
@ -104,8 +101,7 @@ class Sv_Discord < Vrobot4::Server::AudioServer
|
|||
|
||||
# Returns true if the channel is enabled, false otherwise.
|
||||
def [] chan
|
||||
(@cprm.key? chan.name and @cprm[chan.name]) or
|
||||
(@cprm.key? chan.real.id and @cprm[chan.real.id])
|
||||
@cprm[chan.name] or @cprm[chan.real.id]
|
||||
end
|
||||
|
||||
# Sets a channel's permission on/off.
|
||||
|
|
Loading…
Reference in New Issue