Sha256: 20ab07c7b48cf0b8fbff7b2a083d47552cb4d4e8c823eee4ee05826f28f9fa1c
Contents?: true
Size: 1.9 KB
Versions: 1
Compression:
Stored size: 1.9 KB
Contents
class SlackSmartBot def save_stats(method, data: {}) if config.stats begin require 'csv' if !File.exist?("#{config.stats_path}.#{Time.now.strftime("%Y-%m")}.log") CSV.open("#{config.stats_path}.#{Time.now.strftime("%Y-%m")}.log", 'wb') do |csv| csv << ['date','bot_channel', 'bot_channel_id', 'dest_channel', 'dest_channel_id', 'type_message', 'user_name', 'user_id', 'text', 'command', 'files'] end end if data.empty? data = { dest: Thread.current[:dest], typem: Thread.current[:typem], user: Thread.current[:user], files: Thread.current[:files?], command: Thread.current[:command], routine: Thread.current[:routine] } end if method.to_s == 'ruby_code' and data.files command_txt = 'ruby' else command_txt = data.command end command_txt.gsub!(/```.+```/m,'```CODE```') command_txt = "#{command_txt[0..99]}..." if command_txt.size > 100 if data.routine user_name = "routine/#{data.user.name}" user_id = "routine/#{data.user.id}" else user_name = data.user.name user_id = data.user.id end CSV.open("#{config.stats_path}.#{Time.now.strftime("%Y-%m")}.log", "a+") do |csv| csv << [Time.now, config.channel, @channel_id, @channels_name[data.dest], data.dest, data.typem, user_name, user_id, command_txt, method, data.files] end rescue Exception => exception @logger.fatal "There was a problem on the stats" @logger.fatal exception end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
slack-smart-bot-1.10.0 | lib/slack/smart-bot/utils/save_stats.rb |