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