lib/robit/plugins/alias_nick.rb in robit-1.0.5 vs lib/robit/plugins/alias_nick.rb in robit-1.0.6
- old
+ new
@@ -6,11 +6,11 @@
# Like a downcase, de-camelcaser:
# test => test
# Test => test
# OpsOnly => ops_only
def downcase_and_snakify
- self.gsub(/\s+/,'').gsub(/([A-Z])/, '_\1').delete('@').sub(/^_/, '').downcase
+ self.gsub(/\s+/,'').gsub(/([A-Z])/, '_\1').gsub('-','_').delete('@').sub(/^_/, '').downcase
end
end
@@ -69,24 +69,25 @@
def handle_notification from, mentions, message
puts 'handle_notification from=%s mentions=%s message=%s' % [
from.inspect, mentions.inspect, message.inspect
]
+ return if from.include? reply_to.connection.config.nick # self
+
tos = mentions.select { |m| db.keys.include? m }
tos.each do |to|
rooms = db[to]
+ rroom, hroom = nil, nil
rooms.each do |name|
- rroom, hroom = nil, nil
-
if name =~ /^@/
- rroom = robut_room name
- raise if rroom.nil?
- hroom = hipchat_room rroom.name
- raise if hroom.nil?
+ rroom = robut_room name unless rroom
+ next if rroom.nil?
+ hroom = hipchat_room rroom.name unless hroom
+ next if hroom.nil?
end
subject = '%s mentioned "%s" in "%s"' % [
from, name, current_room
]
@@ -100,11 +101,17 @@
else
handle_email_notification subject, notification, name
end
end
- reply "Notified #{to_sentence rooms}." unless rooms.empty?
+ if rroom.nil?
+ reply "Sorry, I'm having trouble accessing the HipChat room..."
+ elsif rooms.empty?
+ reply "Sorry, I'm having trouble accessing HipChat rooms..."
+ else
+ reply "Notified #{to_sentence rooms}."
+ end
end
end
def handle_hipchat_notification notification, hroom
@@ -171,10 +178,11 @@
end
def robut_room name
robut_room = reply_to.connection.rooms.select do |r|
- r.name =~ /^\d+_#{name.downcase_and_snakify}@/
+ room_name = r.name.gsub('-','_')
+ room_name =~ /^\d+_#{name.downcase_and_snakify}@/
end.shift
end
def hipchat_room name
\ No newline at end of file