Add some code comments.

This commit is contained in:
Robert "ar" Gerus 2013-06-05 00:48:50 +02:00
parent e8d2f53b08
commit f475f5b70c

View file

@ -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