Add some code comments.
parent
e8d2f53b08
commit
f475f5b70c
|
@ -18,28 +18,41 @@ Dir.glob(File.dirname($0) + "/plugins/commands/*.rb") { |filename|
|
||||||
}
|
}
|
||||||
|
|
||||||
Client.register_trigger("PRIVMSG") { |msg|
|
Client.register_trigger("PRIVMSG") { |msg|
|
||||||
|
# who sent the message
|
||||||
src_nick = msg[:prefix].split('!').first
|
src_nick = msg[:prefix].split('!').first
|
||||||
|
# what was it
|
||||||
message = msg[:params][1]
|
message = msg[:params][1]
|
||||||
|
|
||||||
|
# Was the message sent directly to us...
|
||||||
if msg[:params][0] == Config[:client][:nick] then
|
if msg[:params][0] == Config[:client][:nick] then
|
||||||
target = src_nick
|
target = src_nick
|
||||||
reply_prefix = ""
|
reply_prefix = ""
|
||||||
|
# or to a channel (probably)
|
||||||
else
|
else
|
||||||
target = msg[:params][0]
|
target = msg[:params][0]
|
||||||
reply_prefix = "#{src_nick}: "
|
reply_prefix = "#{src_nick}: "
|
||||||
end
|
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
|
if message.split.first == Config[:client][:nick] + ":" then
|
||||||
command = message.split[1]
|
command = message.split[1]
|
||||||
arguments = message.split[2..-1]
|
arguments = message.split[2..-1]
|
||||||
else
|
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
|
if message.split.first[0] == ":" then
|
||||||
command = message.split.first[1..-1]
|
command = message.split.first[1..-1]
|
||||||
arguments = message.split[1..-1]
|
arguments = message.split[1..-1]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# don't do anything if there are no commands registered or this isn't a
|
||||||
|
# command call
|
||||||
Client.commands.each do |cmd|
|
Client.commands.each do |cmd|
|
||||||
|
# couldn't inline the if into second argument of Client.privmsg() call
|
||||||
if command.downcase == cmd[:keyword] then
|
if command.downcase == cmd[:keyword] then
|
||||||
Client.privmsg(target, reply_prefix + cmd[:code].call(arguments))
|
Client.privmsg(target, reply_prefix + cmd[:code].call(arguments))
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue