Fix commands plugin.
parent
fd8108e0e5
commit
953f73edd2
|
@ -5,11 +5,7 @@ class Repost
|
|||
attr_accessor :commands
|
||||
|
||||
def register_command(keyword, &code)
|
||||
begin
|
||||
access_level = Config[:commands][keyword.to_sym][:access_level].nil? ? 5 : Config[keyword.to_sym][:access_level]
|
||||
rescue NoMethodError
|
||||
access_level = 5
|
||||
end
|
||||
access_level = Config.lookup("commands::#{keyword}::access_level", 5)
|
||||
|
||||
self.commands = [] if self.commands.nil?
|
||||
self.commands << {
|
||||
|
@ -46,7 +42,7 @@ Client.register_trigger("PRIVMSG", "commands") { |msg|
|
|||
message = msg[:params][1]
|
||||
|
||||
# Was the message sent directly to us...
|
||||
if msg[:params][0] == Config[:client][:nick] then
|
||||
if msg[:params][0] == Config.lookup("client::nick", "repost", msg[:scope]) then
|
||||
target = src_nick
|
||||
reply_prefix = ""
|
||||
# or to a channel (probably)
|
||||
|
@ -58,7 +54,7 @@ Client.register_trigger("PRIVMSG", "commands") { |msg|
|
|||
# Did the message contain our nick with ":" "completion character"?
|
||||
# If so, use the second word as a command and everything else as arguments
|
||||
# array
|
||||
if message.split.first == Config[:client][:nick] + ":" then
|
||||
if message.split.first == Config.lookup("client::nick", "repost", msg[:scope]) + ":" then
|
||||
command = message.split[1]
|
||||
arguments = message.split[2..-1]
|
||||
else
|
||||
|
@ -80,8 +76,9 @@ Client.register_trigger("PRIVMSG", "commands") { |msg|
|
|||
# command call
|
||||
Client.commands.each do |cmd|
|
||||
# couldn't inline the if into second argument of Client.privmsg() call
|
||||
if command.downcase == cmd[:keyword] then
|
||||
next if cmd[:access_level] > Client.access_level(msg[:prefix], target)
|
||||
if command.downcase == cmd[:keyword] and
|
||||
cmd[:access_level] <= Config.lookup("access_level", 0, msg[:scope]) and
|
||||
not Config.lookup("commands::disabled", [], msg[:scope]).include? cmd[:keyword] then
|
||||
retval = cmd[:code].call(arguments)
|
||||
# if the command returned a String, we want to show it
|
||||
Client.privmsg(target, reply_prefix + retval) if retval.instance_of? String
|
||||
|
|
Loading…
Reference in New Issue