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] if msg[:params][0] == Config[:client][:nick] then target = src_nick reply_prefix = "" else target = msg[:params][0] reply_prefix = "#{src_nick}: " end if message.split.first == Config[:client][:nick] + ":" then command = message.split[1] arguments = message.split[2..-1] else if message.split.first[0] == ":" then command = message.split.first[1..-1] arguments = message.split[1..-1] end end 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? ) }