From f475f5b70c4b7b557614f2b4461edea11c084416 Mon Sep 17 00:00:00 2001 From: "Robert \"ar\" Gerus" Date: Wed, 5 Jun 2013 00:48:50 +0200 Subject: [PATCH] Add some code comments. --- plugins/commands.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plugins/commands.rb b/plugins/commands.rb index 7789d41..25e9904 100644 --- a/plugins/commands.rb +++ b/plugins/commands.rb @@ -18,28 +18,41 @@ Dir.glob(File.dirname($0) + "/plugins/commands/*.rb") { |filename| } Client.register_trigger("PRIVMSG") { |msg| + # who sent the message src_nick = msg[:prefix].split('!').first + # what was it message = msg[:params][1] + # Was the message sent directly to us... if msg[:params][0] == Config[:client][:nick] then target = src_nick reply_prefix = "" + # or to a channel (probably) else target = msg[:params][0] reply_prefix = "#{src_nick}: " end + # 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 command = message.split[1] arguments = message.split[2..-1] else + # did the message start with a :? + # If so, use everything after ":" from the first word as a command and + # all the other words as arguments array if message.split.first[0] == ":" then command = message.split.first[1..-1] arguments = message.split[1..-1] end end + # don't do anything if there are no commands registered or this isn't a + # 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 Client.privmsg(target, reply_prefix + cmd[:code].call(arguments)) end