Add some code comments.
This commit is contained in:
parent
e8d2f53b08
commit
f475f5b70c
1 changed files with 13 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue