The commands plugin now does something somewhat useful.

master
Robert "ar" Gerus 2013-06-05 00:26:55 +02:00
parent f2cf9388b9
commit e8d2f53b08
2 changed files with 25 additions and 2 deletions

View File

@ -1,5 +1,22 @@
include EventMachine::IRC::Commands
# yay, monkey patching
class Repost
attr_accessor :commands
def register_command(keyword, &code)
# Yes, that's a copy-paste of the register_trigger method and that
# violates DRY. I feel a bit bad about it, but not that much.
self.commands = [] if self.triggers.nil?
self.commands << {:keyword => keyword, :code => code}
end
end
Dir.glob(File.dirname($0) + "/plugins/commands/*.rb") { |filename|
load filename
}
Client.register_trigger("PRIVMSG") { |msg|
src_nick = msg[:prefix].split('!').first
message = msg[:params][1]
@ -22,6 +39,9 @@ Client.register_trigger("PRIVMSG") { |msg|
end
end
Client.privmsg(target, "#{reply_prefix}command: #{command} arguments: #{arguments.join(' ')}") if not command.nil?
Client.commands.each do |cmd|
if command.downcase == cmd[:keyword] then
Client.privmsg(target, reply_prefix + cmd[:code].call(arguments))
end
end if not ( Client.commands.nil? or command.nil? )
}

3
plugins/commands/echo.rb Normal file
View File

@ -0,0 +1,3 @@
Client.register_command("echo") { |args|
args.join(' ')
}