lib/slack/smart-bot/treat_message.rb in slack-smart-bot-1.2.0 vs lib/slack/smart-bot/treat_message.rb in slack-smart-bot-1.3.0
- old
+ new
@@ -1,8 +1,12 @@
class SlackSmartBot
def treat_message(data)
- data.text = CGI.unescapeHTML(data.text)
+ begin
+ data.text = CGI.unescapeHTML(data.text) unless data.text.to_s.match(/\A\s*\z/)
+ rescue
+ @logger.warn "Impossible to unescape the data.text:#{data.text}"
+ end
if config[:testing] and config.on_master_bot
open("#{config.path}/buffer.log", "a") { |f|
f.puts "|#{data.channel}|#{data.user}|#{data.text}"
}
end
@@ -28,18 +32,26 @@
if @channel_id == channel_rules
data.text = $4
typem = :on_call
end
elsif dest == @master_bot_id
- if config.on_master_bot #only to be treated on master mot channel
+ if config.on_master_bot #only to be treated on master bot channel
typem = :on_master
end
elsif @bots_created.key?(dest)
if @channel_id == dest #only to be treated by the bot on the channel
typem = :on_bot
end
elsif dest[0] == "D" #Direct message
- if config.on_master_bot #only to be treated by master bot
+ get_rules_imported()
+ if @rules_imported.key?(data.user) && @rules_imported[data.user].key?(data.user) and
+ @bots_created.key?(@rules_imported[data.user][data.user])
+ if @channel_id == @rules_imported[data.user][data.user]
+ #only to be treated by the channel we are 'using'
+ typem = :on_dm
+ end
+ elsif config.on_master_bot
+ #only to be treated by master bot
typem = :on_dm
end
elsif dest[0] == "C" or dest[0] == "G"
#only to be treated on the channel of the bot. excluding running ruby
if !config.on_master_bot and @bots_created.key?(@channel_id) and @bots_created[@channel_id][:extended].include?(@channels_name[dest]) and