slack-smart-bot 1.9.2 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +109 -11
- data/lib/slack/smart-bot/comm/ask.rb +55 -49
- data/lib/slack/smart-bot/comm/dont_understand.rb +1 -1
- data/lib/slack/smart-bot/comm/event_hello.rb +7 -3
- data/lib/slack/smart-bot/comm/get_channel_members.rb +9 -4
- data/lib/slack/smart-bot/comm/get_channels.rb +31 -16
- data/lib/slack/smart-bot/comm/get_user_info.rb +12 -8
- data/lib/slack/smart-bot/comm/get_users.rb +24 -0
- data/lib/slack/smart-bot/comm/react.rb +19 -2
- data/lib/slack/smart-bot/comm/respond.rb +217 -72
- data/lib/slack/smart-bot/comm/respond_direct.rb +2 -3
- data/lib/slack/smart-bot/comm/respond_thread.rb +5 -0
- data/lib/slack/smart-bot/comm/send_file.rb +38 -34
- data/lib/slack/smart-bot/comm/send_msg_channel.rb +27 -22
- data/lib/slack/smart-bot/comm/send_msg_user.rb +58 -33
- data/lib/slack/smart-bot/comm/unreact.rb +22 -18
- data/lib/slack/smart-bot/comm.rb +2 -0
- data/lib/slack/smart-bot/commands/general/add_announcement.rb +32 -0
- data/lib/slack/smart-bot/commands/general/bot_help.rb +59 -32
- data/lib/slack/smart-bot/commands/general/bot_stats.rb +10 -9
- data/lib/slack/smart-bot/commands/general/bot_status.rb +2 -4
- data/lib/slack/smart-bot/commands/general/bye_bot.rb +0 -7
- data/lib/slack/smart-bot/commands/general/delete_announcement.rb +34 -0
- data/lib/slack/smart-bot/commands/general/delete_share.rb +34 -0
- data/lib/slack/smart-bot/commands/general/hi_bot.rb +16 -11
- data/lib/slack/smart-bot/commands/general/leaderboard.rb +200 -0
- data/lib/slack/smart-bot/commands/general/see_announcements.rb +113 -0
- data/lib/slack/smart-bot/commands/general/see_favorite_commands.rb +54 -0
- data/lib/slack/smart-bot/commands/general/see_shares.rb +41 -0
- data/lib/slack/smart-bot/commands/general/see_statuses.rb +78 -0
- data/lib/slack/smart-bot/commands/general/share_messages.rb +58 -0
- data/lib/slack/smart-bot/commands/general/stop_using_rules.rb +11 -6
- data/lib/slack/smart-bot/commands/general/suggest_command.rb +30 -0
- data/lib/slack/smart-bot/commands/general/use_rules.rb +7 -7
- data/lib/slack/smart-bot/commands/general_bot_commands.rb +243 -0
- data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +2 -5
- data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +32 -11
- data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +2 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +4 -2
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_routine.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +2 -3
- data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +6 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/see_result_routine.rb +32 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +4 -2
- data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +4 -2
- data/lib/slack/smart-bot/commands/on_bot/admin/start_routine.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb +2 -0
- data/lib/slack/smart-bot/commands/on_bot/admin_master/react_to.rb +32 -0
- data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +24 -0
- data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +2 -4
- data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +2 -4
- data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +2 -4
- data/lib/slack/smart-bot/commands/on_bot/repl.rb +5 -7
- data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +2 -4
- data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +4 -5
- data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +3 -5
- data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +2 -4
- data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +45 -12
- data/lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb +4 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +2 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +1 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +32 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +38 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +8 -0
- data/lib/slack/smart-bot/commands/on_master/create_bot.rb +27 -14
- data/lib/slack/smart-bot/commands.rb +16 -0
- data/lib/slack/smart-bot/listen.rb +1 -3
- data/lib/slack/smart-bot/process.rb +212 -74
- data/lib/slack/smart-bot/process_first.rb +118 -37
- data/lib/slack/smart-bot/treat_message.rb +313 -248
- data/lib/slack/smart-bot/utils/build_help.rb +3 -3
- data/lib/slack/smart-bot/utils/create_routine_thread.rb +81 -46
- data/lib/slack/smart-bot/utils/get_bots_created.rb +4 -1
- data/lib/slack/smart-bot/utils/get_help.rb +58 -68
- data/lib/slack/smart-bot/utils/get_shares.rb +12 -0
- data/lib/slack/smart-bot/utils/has_access.rb +12 -0
- data/lib/slack/smart-bot/utils/save_stats.rb +2 -0
- data/lib/slack/smart-bot/utils/save_status.rb +52 -0
- data/lib/slack/smart-bot/utils.rb +3 -0
- data/lib/slack-smart-bot.rb +45 -4
- data/lib/slack-smart-bot_general_commands.rb +46 -0
- data/lib/slack-smart-bot_general_rules.rb +5 -2
- data/lib/slack-smart-bot_rules.rb +43 -17
- data/whats_new.txt +32 -20
- metadata +24 -2
| @@ -9,8 +9,8 @@ class SlackSmartBot | |
| 9 9 | 
             
                else
         | 
| 10 10 | 
             
                  return help_message
         | 
| 11 11 | 
             
                end
         | 
| 12 | 
            -
             | 
| 13 12 | 
             
                files.each do |t|
         | 
| 13 | 
            +
             | 
| 14 14 | 
             
                  if Dir.exist?(t)
         | 
| 15 15 | 
             
                    res = build_help(t, expanded)
         | 
| 16 16 | 
             
                    help_message[:master][t.scan(/\/(\w+)$/).join.to_sym] = res[:master]
         | 
| @@ -50,8 +50,8 @@ class SlackSmartBot | |
| 50 50 | 
             
                          elsif !explanation_done and line.match?(/^\s+[^`].+\s*/i)
         | 
| 51 51 | 
             
                            resf += "\n#{line}"
         | 
| 52 52 | 
             
                            explanation_done = true
         | 
| 53 | 
            -
                          elsif !example_done and line.match?(/^\s*_.+_\s | 
| 54 | 
            -
                            resf += "\n     Example: #{line}"
         | 
| 53 | 
            +
                          elsif !example_done and line.match?(/^\s*>?\s*_.+_\s*$/i)
         | 
| 54 | 
            +
                            resf += "\n     Example: #{line.gsub(/^\s*>/,'')}"
         | 
| 55 55 | 
             
                            example_done = true
         | 
| 56 56 | 
             
                          end
         | 
| 57 57 | 
             
                        end
         | 
| @@ -1,11 +1,15 @@ | |
| 1 1 | 
             
            class SlackSmartBot
         | 
| 2 2 |  | 
| 3 | 
            -
              def create_routine_thread(name)
         | 
| 3 | 
            +
              def create_routine_thread(name, hroutine)
         | 
| 4 4 | 
             
                t = Thread.new do
         | 
| 5 5 | 
             
                  while @routines.key?(@channel_id) and @routines[@channel_id].key?(name)
         | 
| 6 6 | 
             
                    @routines[@channel_id][name][:thread] = Thread.current
         | 
| 7 7 | 
             
                    started = Time.now
         | 
| 8 8 | 
             
                    if @status == :on and @routines[@channel_id][name][:status] == :on
         | 
| 9 | 
            +
                      if !@routines[@channel_id][name].key?(:creator_id) or @routines[@channel_id][name][:creator_id].to_s == ''
         | 
| 10 | 
            +
                        user_info = @users.select{|u| u.name == @routines[@channel_id][name][:creator]}[-1]
         | 
| 11 | 
            +
                        @routines[@channel_id][name][:creator_id] = user_info.id unless user_info.nil? or user_info.empty?
         | 
| 12 | 
            +
                      end
         | 
| 9 13 | 
             
                      @logger.info "Routine: #{@routines[@channel_id][name].inspect}"
         | 
| 10 14 | 
             
                      if @routines[@channel_id][name][:file_path].match?(/\.rb$/i)
         | 
| 11 15 | 
             
                        ruby = "ruby "
         | 
| @@ -16,63 +20,84 @@ class SlackSmartBot | |
| 16 20 | 
             
                      if @routines[@channel_id][name][:at] == "" or
         | 
| 17 21 | 
             
                         (@routines[@channel_id][name][:at] != "" and @routines[@channel_id][name][:running] and
         | 
| 18 22 | 
             
                          @routines[@channel_id][name][:next_run] != "" and Time.now.to_s >= @routines[@channel_id][name][:next_run])
         | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
                           | 
| 22 | 
            -
                           | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
                             | 
| 27 | 
            -
                             | 
| 28 | 
            -
                             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
                               | 
| 23 | 
            +
                          
         | 
| 24 | 
            +
                        if !@routines[@channel_id][name].key?(:dayweek) or 
         | 
| 25 | 
            +
                          (@routines[@channel_id][name].key?(:dayweek) and @routines[@channel_id][name][:dayweek].to_s!='weekday' and @routines[@channel_id][name][:dayweek].to_s!='weekend') or
         | 
| 26 | 
            +
                          (@routines[@channel_id][name].key?(:dayweek) and @routines[@channel_id][name][:dayweek].to_s=='weekday' and Date.today.wday>=1 and Date.today.wday<=5) or
         | 
| 27 | 
            +
                          (@routines[@channel_id][name].key?(:dayweek) and @routines[@channel_id][name][:dayweek].to_s=='weekend' and (Date.today.wday==6 or Date.today.wday==0)) 
         | 
| 28 | 
            +
                          File.delete "#{config.path}/routines/#{@channel_id}/#{name}_output.txt" if File.exists?("#{config.path}/routines/#{@channel_id}/#{name}_output.txt")
         | 
| 29 | 
            +
                          if @routines[@channel_id][name][:file_path] != ""
         | 
| 30 | 
            +
                            process_to_run = "#{ruby}#{Dir.pwd}#{@routines[@channel_id][name][:file_path][1..-1]}"
         | 
| 31 | 
            +
                            process_to_run = ("cd #{project_folder} &&" + process_to_run) if defined?(project_folder)
         | 
| 32 | 
            +
                            data = {
         | 
| 33 | 
            +
                              dest: @routines[@channel_id][name][:dest],
         | 
| 34 | 
            +
                              typem: 'routine_file',
         | 
| 35 | 
            +
                              user: {id: @routines[@channel_id][name][:creator_id], name: @routines[@channel_id][name][:creator]},
         | 
| 36 | 
            +
                              files: false,
         | 
| 37 | 
            +
                              command: @routines[@channel_id][name][:file_path],
         | 
| 38 | 
            +
                              routine: true,
         | 
| 39 | 
            +
                              routine_name: name,
         | 
| 40 | 
            +
                              routine_type: hroutine[:routine_type]
         | 
| 41 | 
            +
                            }
         | 
| 42 | 
            +
                            save_stats(name, data: data)
         | 
| 43 | 
            +
                            stdout, stderr, status = Open3.capture3(process_to_run)
         | 
| 44 | 
            +
                            if !@routines[@channel_id][name][:silent]
         | 
| 45 | 
            +
                              unless config.on_maintenance
         | 
| 46 | 
            +
                                if @routines[@channel_id][name][:dest]!=@channel_id
         | 
| 47 | 
            +
                                  respond "routine from <##{@channel_id}> *`#{name}`*: #{@routines[@channel_id][name][:file_path]}", @routines[@channel_id][name][:dest]
         | 
| 48 | 
            +
                                else
         | 
| 49 | 
            +
                                  respond "routine *`#{name}`*: #{@routines[@channel_id][name][:file_path]}", @routines[@channel_id][name][:dest]
         | 
| 50 | 
            +
                                end
         | 
| 51 | 
            +
                              end
         | 
| 52 | 
            +
                            end
         | 
| 53 | 
            +
                            if hroutine[:routine_type].to_s!='bgroutine'
         | 
| 54 | 
            +
                              if stderr == ""
         | 
| 55 | 
            +
                                unless stdout.match?(/\A\s*\z/)
         | 
| 56 | 
            +
                                  respond stdout, @routines[@channel_id][name][:dest]
         | 
| 57 | 
            +
                                end
         | 
| 58 | 
            +
                              else
         | 
| 59 | 
            +
                                respond "#{stdout} #{stderr}", @routines[@channel_id][name][:dest]
         | 
| 60 | 
            +
                              end
         | 
| 36 61 | 
             
                            else
         | 
| 37 | 
            -
                               | 
| 62 | 
            +
                              File.write("#{config.path}/routines/#{@channel_id}/#{name}_output.txt", stdout.to_s+stderr.to_s, mode: "a+")
         | 
| 38 63 | 
             
                            end
         | 
| 39 | 
            -
                           | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 64 | 
            +
                          else #command
         | 
| 65 | 
            +
                            if !@routines[@channel_id][name][:silent] and !config.on_maintenance
         | 
| 66 | 
            +
                              if @routines[@channel_id][name][:dest]!=@channel_id
         | 
| 67 | 
            +
                                respond "routine from <##{@channel_id}> *`#{name}`*: #{@routines[@channel_id][name][:command]}", @routines[@channel_id][name][:dest]
         | 
| 68 | 
            +
                              else
         | 
| 69 | 
            +
                                respond "routine *`#{name}`*: #{@routines[@channel_id][name][:command]}", @routines[@channel_id][name][:dest]
         | 
| 70 | 
            +
                              end
         | 
| 43 71 | 
             
                            end
         | 
| 44 | 
            -
             | 
| 45 | 
            -
                             | 
| 72 | 
            +
                            started = Time.now
         | 
| 73 | 
            +
                            data = { channel: @channel_id,
         | 
| 74 | 
            +
                              dest: @routines[@channel_id][name][:dest],
         | 
| 75 | 
            +
                              user: @routines[@channel_id][name][:creator_id],
         | 
| 76 | 
            +
                              text: @routines[@channel_id][name][:command],
         | 
| 77 | 
            +
                              files: nil,
         | 
| 78 | 
            +
                              routine: true,
         | 
| 79 | 
            +
                              routine_name: name,
         | 
| 80 | 
            +
                              routine_type: hroutine[:routine_type] }
         | 
| 81 | 
            +
                            treat_message(data)
         | 
| 46 82 | 
             
                          end
         | 
| 47 | 
            -
             | 
| 48 | 
            -
                          if !@routines[@channel_id] | 
| 49 | 
            -
                             | 
| 50 | 
            -
                              respond "routine from <##{@channel_id}> *`#{name}`*: #{@routines[@channel_id][name][:command]}", @routines[@channel_id][name][:dest]
         | 
| 51 | 
            -
                            else
         | 
| 52 | 
            -
                              respond "routine *`#{name}`*: #{@routines[@channel_id][name][:command]}", @routines[@channel_id][name][:dest]
         | 
| 53 | 
            -
                            end
         | 
| 83 | 
            +
                          # in case the routine was deleted while running the process
         | 
| 84 | 
            +
                          if !@routines.key?(@channel_id) or !@routines[@channel_id].key?(name)
         | 
| 85 | 
            +
                            Thread.exit
         | 
| 54 86 | 
             
                          end
         | 
| 55 | 
            -
                           | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 59 | 
            -
                            text: @routines[@channel_id][name][:command],
         | 
| 60 | 
            -
                            files: nil,
         | 
| 61 | 
            -
                            routine: true }
         | 
| 62 | 
            -
                          treat_message(data)
         | 
| 87 | 
            +
                          @routines[@channel_id][name][:last_run] = started.to_s
         | 
| 88 | 
            +
                        elsif (@routines[@channel_id][name].key?(:dayweek) and @routines[@channel_id][name][:dayweek].to_s=='weekday' and (Date.today.wday==6 or Date.today.wday==0)) or
         | 
| 89 | 
            +
                          (@routines[@channel_id][name].key?(:dayweek) and @routines[@channel_id][name][:dayweek].to_s=='weekend' and Date.today.wday>=1 and Date.today.wday<=5) 
         | 
| 90 | 
            +
                          @routines[@channel_id][name][:last_run] = started.to_s
         | 
| 63 91 | 
             
                        end
         | 
| 64 | 
            -
                        # in case the routine was deleted while running the process
         | 
| 65 | 
            -
                        if !@routines.key?(@channel_id) or !@routines[@channel_id].key?(name)
         | 
| 66 | 
            -
                          Thread.exit
         | 
| 67 | 
            -
                        end
         | 
| 68 | 
            -
                        @routines[@channel_id][name][:last_run] = started.to_s
         | 
| 69 92 | 
             
                      end
         | 
| 70 93 | 
             
                      if @routines[@channel_id][name][:last_run] == "" and @routines[@channel_id][name][:next_run] != "" #for the first create_routine of one routine with at
         | 
| 71 94 | 
             
                        elapsed = 0
         | 
| 72 95 | 
             
                        require "time"
         | 
| 73 96 | 
             
                        every_in_seconds = Time.parse(@routines[@channel_id][name][:next_run]) - Time.now
         | 
| 74 97 | 
             
                      elsif @routines[@channel_id][name][:at] != "" #coming from start after pause for 'at'
         | 
| 75 | 
            -
                        if @routines[@channel_id][name].key?(:dayweek) and @routines[@channel_id][name][:dayweek].to_s!=''
         | 
| 98 | 
            +
                        if @routines[@channel_id][name].key?(:dayweek) and @routines[@channel_id][name][:dayweek].to_s!=''and 
         | 
| 99 | 
            +
                          @routines[@channel_id][name][:dayweek].to_s!='weekend' and @routines[@channel_id][name][:dayweek].to_s!='weekday'
         | 
| 100 | 
            +
                          
         | 
| 76 101 | 
             
                          day = @routines[@channel_id][name][:dayweek]
         | 
| 77 102 | 
             
                          days = ['sunday','monday','tuesday','wednesday','thursday','friday','saturday']
         | 
| 78 103 | 
             
                          incr = days.index(day) - Time.now.wday
         | 
| @@ -83,6 +108,16 @@ class SlackSmartBot | |
| 83 108 | 
             
                          end
         | 
| 84 109 | 
             
                          days = incr/(24*60*60)
         | 
| 85 110 | 
             
                          weekly = true
         | 
| 111 | 
            +
                        elsif @routines[@channel_id][name].key?(:dayweek) and @routines[@channel_id][name][:dayweek].to_s!='' and 
         | 
| 112 | 
            +
                          @routines[@channel_id][name][:dayweek].to_s=='weekend'
         | 
| 113 | 
            +
                          
         | 
| 114 | 
            +
                          weekly = false
         | 
| 115 | 
            +
                          days = 0
         | 
| 116 | 
            +
                        elsif @routines[@channel_id][name].key?(:dayweek) and @routines[@channel_id][name][:dayweek].to_s!='' and 
         | 
| 117 | 
            +
                          @routines[@channel_id][name][:dayweek].to_s=='weekday'
         | 
| 118 | 
            +
                          
         | 
| 119 | 
            +
                          weekly = false
         | 
| 120 | 
            +
                          days = 0
         | 
| 86 121 | 
             
                        else
         | 
| 87 122 | 
             
                          days = 0
         | 
| 88 123 | 
             
                          weekly = false
         | 
| @@ -1,7 +1,9 @@ | |
| 1 1 | 
             
            class SlackSmartBot
         | 
| 2 2 | 
             
              def get_bots_created
         | 
| 3 3 | 
             
                if File.exist?(config.file_path.gsub(".rb", "_bots.rb"))
         | 
| 4 | 
            +
                  
         | 
| 4 5 | 
             
                  if !defined?(@datetime_bots_created) or @datetime_bots_created != File.mtime(config.file_path.gsub(".rb", "_bots.rb"))
         | 
| 6 | 
            +
                
         | 
| 5 7 | 
             
                    file_conf = IO.readlines(config.file_path.gsub(".rb", "_bots.rb")).join
         | 
| 6 8 | 
             
                    if file_conf.to_s() == ""
         | 
| 7 9 | 
             
                      @bots_created = {}
         | 
| @@ -16,8 +18,9 @@ class SlackSmartBot | |
| 16 18 | 
             
                        @extended_from[ch] = [] unless @extended_from.key?(ch)
         | 
| 17 19 | 
             
                        @extended_from[ch] << k
         | 
| 18 20 | 
             
                      end
         | 
| 21 | 
            +
                      v[:rules_file] ||= ''
         | 
| 19 22 | 
             
                      v[:rules_file].gsub!(/^\./, '')
         | 
| 20 | 
            -
                    end
         | 
| 23 | 
            +
                    end            
         | 
| 21 24 | 
             
                  end
         | 
| 22 25 | 
             
                end
         | 
| 23 26 | 
             
              end
         | 
| @@ -1,10 +1,10 @@ | |
| 1 1 | 
             
            class SlackSmartBot
         | 
| 2 | 
            -
              def get_help(rules_file, dest, from, only_rules, expanded)
         | 
| 2 | 
            +
              def get_help(rules_file, dest, from, only_rules, expanded, descriptions: true, only_normal_user: false)
         | 
| 3 3 | 
             
                order = {
         | 
| 4 | 
            -
                  general: [:whats_new, :hi_bot, :bye_bot, :bot_help, :bot_status, :use_rules, :stop_using_rules, :bot_stats],
         | 
| 4 | 
            +
                  general: [:whats_new, :hi_bot, :bye_bot, :bot_help, :suggest_command, :bot_status, :use_rules, :stop_using_rules, :bot_stats, :leaderboard],
         | 
| 5 5 | 
             
                  on_bot: [:ruby_code, :repl, :get_repl, :run_repl, :delete_repl, :see_repls, :add_shortcut, :delete_shortcut, :see_shortcuts],
         | 
| 6 6 | 
             
                  on_bot_admin: [:extend_rules, :stop_using_rules_on, :start_bot, :pause_bot, :add_routine,
         | 
| 7 | 
            -
                    :see_routines, :start_routine, :pause_routine, :remove_routine, :run_routine]
         | 
| 7 | 
            +
                    :see_routines, :start_routine, :pause_routine, :remove_routine, :see_result_routine, :run_routine]
         | 
| 8 8 | 
             
                }
         | 
| 9 9 | 
             
                if config.masters.include?(from)
         | 
| 10 10 | 
             
                  user_type = :master # master admin
         | 
| @@ -13,6 +13,7 @@ class SlackSmartBot | |
| 13 13 | 
             
                else
         | 
| 14 14 | 
             
                  user_type = :normal #normal user
         | 
| 15 15 | 
             
                end
         | 
| 16 | 
            +
                
         | 
| 16 17 | 
             
                # channel_type: :bot, :master_bot, :direct, :extended, :external
         | 
| 17 18 | 
             
                if dest[0] == "D"
         | 
| 18 19 | 
             
                  channel_type = :direct
         | 
| @@ -24,6 +25,15 @@ class SlackSmartBot | |
| 24 25 | 
             
                  channel_type = :bot
         | 
| 25 26 | 
             
                end
         | 
| 26 27 |  | 
| 28 | 
            +
                if Thread.current[:typem] == :on_pg or Thread.current[:typem] == :on_pub
         | 
| 29 | 
            +
                  channel_type = :external
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                if only_normal_user
         | 
| 33 | 
            +
                  user_type = :normal 
         | 
| 34 | 
            +
                  channel_type = :bot
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 27 37 | 
             
                @help_messages_expanded ||= build_help("#{__dir__}/../commands", true)
         | 
| 28 38 | 
             
                @help_messages_not_expanded ||= build_help("#{__dir__}/../commands", false)
         | 
| 29 39 | 
             
                if only_rules
         | 
| @@ -33,7 +43,6 @@ class SlackSmartBot | |
| 33 43 | 
             
                else
         | 
| 34 44 | 
             
                  help = @help_messages_not_expanded.deep_copy[user_type]
         | 
| 35 45 | 
             
                end
         | 
| 36 | 
            -
             | 
| 37 46 | 
             
                if rules_file != ""
         | 
| 38 47 | 
             
                  help[:rules_file] = build_help(config.path+rules_file, expanded)[user_type].values.join("\n") + "\n"
         | 
| 39 48 |  | 
| @@ -55,6 +64,11 @@ class SlackSmartBot | |
| 55 64 | 
             
                    help[:rules_file] += rhelp[user_type].values.join("\n") + "\n"
         | 
| 56 65 | 
             
                  end
         | 
| 57 66 | 
             
                end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                help[:general_commands_file] = build_help("#{__dir__}/../commands/general_bot_commands.rb", expanded)[user_type].values.join("\n") + "\n" unless only_rules
         | 
| 69 | 
            +
                if File.exists?(config.path + '/rules/general_commands.rb') and !only_rules
         | 
| 70 | 
            +
                  help[:general_commands_file] += build_help(config.path+'/rules/general_commands.rb', expanded)[user_type].values.join("\n") + "\n"
         | 
| 71 | 
            +
                end
         | 
| 58 72 | 
             
                help = remove_hash_keys(help, :admin_master) unless user_type == :master
         | 
| 59 73 | 
             
                help = remove_hash_keys(help, :admin) unless user_type == :admin or user_type == :master
         | 
| 60 74 | 
             
                help = remove_hash_keys(help, :on_master) unless channel_type == :master_bot
         | 
| @@ -62,7 +76,7 @@ class SlackSmartBot | |
| 62 76 | 
             
                help = remove_hash_keys(help, :on_dm) unless channel_type == :direct
         | 
| 63 77 | 
             
                txt = ""
         | 
| 64 78 |  | 
| 65 | 
            -
                if (channel_type == :bot or channel_type == :master_bot) and expanded
         | 
| 79 | 
            +
                if (channel_type == :bot or channel_type == :master_bot) and expanded and descriptions
         | 
| 66 80 | 
             
                  txt += "===================================
         | 
| 67 81 | 
             
                  For the Smart Bot start listening to you say *hi bot*
         | 
| 68 82 | 
             
                  To run a command on demand even when the Smart Bot is not listening to you:
         | 
| @@ -73,11 +87,11 @@ class SlackSmartBot | |
| 73 87 | 
             
                        *^THE_COMMAND*
         | 
| 74 88 | 
             
                        *!!THE_COMMAND*\n"
         | 
| 75 89 | 
             
                end
         | 
| 76 | 
            -
                if channel_type == :direct and expanded
         | 
| 90 | 
            +
                if channel_type == :direct and expanded and descriptions
         | 
| 77 91 | 
             
                  txt += "===================================
         | 
| 78 92 | 
             
                  When on a private conversation with the Smart Bot, I'm always listening to you.\n"
         | 
| 79 93 | 
             
                end
         | 
| 80 | 
            -
                unless channel_type == :master_bot or channel_type == :extended or !expanded
         | 
| 94 | 
            +
                unless channel_type == :master_bot or channel_type == :extended or !expanded or !descriptions
         | 
| 81 95 | 
             
                  txt += "===================================
         | 
| 82 96 | 
             
                  *Commands from Channels without a bot:*
         | 
| 83 97 | 
             
                  ----------------------------------------------
         | 
| @@ -86,16 +100,22 @@ class SlackSmartBot | |
| 86 100 | 
             
                    It will run the supplied command using the rules on the channel supplied.
         | 
| 87 101 | 
             
                    You need to join the specified channel to be able to use those rules.
         | 
| 88 102 | 
             
                    Also you can use this command to call another bot from a channel with a running bot.
         | 
| 89 | 
            -
             | 
| 103 | 
            +
                  \n"
         | 
| 104 | 
            +
                  txt +="
         | 
| 90 105 | 
             
                  The commands you will be able to use from a channel without a bot: 
         | 
| 91 106 | 
             
                  *bot rules*, *ruby CODE*, *add shortcut NAME: COMMAND*, *delete shortcut NAME*, *see shortcuts*, *shortcut NAME*
         | 
| 92 107 | 
             
                  *And all the specific rules of the Channel*\n"
         | 
| 93 108 | 
             
                end
         | 
| 94 109 |  | 
| 95 | 
            -
                if help.key?(:general)
         | 
| 96 | 
            -
                   | 
| 97 | 
            -
                     | 
| 98 | 
            -
             | 
| 110 | 
            +
                if help.key?(:general) and channel_type != :external and channel_type != :extended
         | 
| 111 | 
            +
                  if descriptions
         | 
| 112 | 
            +
                    if channel_type == :direct
         | 
| 113 | 
            +
                      txt += "===================================
         | 
| 114 | 
            +
                      *General commands:*\n"
         | 
| 115 | 
            +
                    else
         | 
| 116 | 
            +
                      txt += "===================================
         | 
| 117 | 
            +
                      *General commands even when the Smart Bot is not listening to you:*\n"
         | 
| 118 | 
            +
                    end
         | 
| 99 119 | 
             
                  end
         | 
| 100 120 | 
             
                  order.general.each do |o|
         | 
| 101 121 | 
             
                    txt += help.general[o]
         | 
| @@ -105,19 +125,29 @@ class SlackSmartBot | |
| 105 125 | 
             
                  end
         | 
| 106 126 | 
             
                end
         | 
| 107 127 |  | 
| 108 | 
            -
                if help.key?(: | 
| 109 | 
            -
                   | 
| 110 | 
            -
                     | 
| 111 | 
            -
             | 
| 128 | 
            +
                if help.key?(:general_commands_file)
         | 
| 129 | 
            +
                  txt += "===================================
         | 
| 130 | 
            +
                    *General commands on any channel where the Smart Bot is a member:*\n" if descriptions
         | 
| 131 | 
            +
                  txt += help.general_commands_file
         | 
| 132 | 
            +
                end
         | 
| 133 | 
            +
             | 
| 134 | 
            +
                if help.key?(:on_bot) and channel_type != :external and channel_type != :extended
         | 
| 135 | 
            +
                  if descriptions
         | 
| 136 | 
            +
                    if channel_type == :direct
         | 
| 137 | 
            +
                      txt += "===================================
         | 
| 138 | 
            +
                      *General commands on bot, DM or on external call on demand:*\n"
         | 
| 139 | 
            +
                    else
         | 
| 140 | 
            +
                      txt += "===================================
         | 
| 141 | 
            +
                      *General commands only when the Smart Bot is listening to you or on demand:*\n"
         | 
| 142 | 
            +
                    end
         | 
| 112 143 | 
             
                  end
         | 
| 113 144 | 
             
                  order.on_bot.each do |o|
         | 
| 114 145 | 
             
                    txt += help.on_bot[o]
         | 
| 115 146 | 
             
                  end
         | 
| 116 147 | 
             
                end
         | 
| 117 | 
            -
                if help.key?(:on_bot) and help.on_bot.key?(:admin)
         | 
| 148 | 
            +
                if help.key?(:on_bot) and help.on_bot.key?(:admin) and channel_type != :external and channel_type != :extended
         | 
| 118 149 | 
             
                  txt += "===================================
         | 
| 119 | 
            -
                    *Admin commands:*\n"
         | 
| 120 | 
            -
                  txt += "\n\n"
         | 
| 150 | 
            +
                    *Admin commands:*\n\n" if descriptions
         | 
| 121 151 | 
             
                  order.on_bot_admin.each do |o|
         | 
| 122 152 | 
             
                    txt += help.on_bot.admin[o]
         | 
| 123 153 | 
             
                  end
         | 
| @@ -128,76 +158,36 @@ class SlackSmartBot | |
| 128 158 | 
             
                  end
         | 
| 129 159 | 
             
                end
         | 
| 130 160 |  | 
| 131 | 
            -
                if help.key?(:on_bot) and help.on_bot.key?(:admin_master) and help.on_bot.admin_master.size > 0
         | 
| 161 | 
            +
                if help.key?(:on_bot) and help.on_bot.key?(:admin_master) and help.on_bot.admin_master.size > 0 and channel_type != :external and channel_type != :extended
         | 
| 132 162 | 
             
                  txt += "===================================
         | 
| 133 | 
            -
             | 
| 163 | 
            +
                    *Master Admin commands:*\n" if descriptions
         | 
| 134 164 | 
             
                  help.on_bot.admin_master.each do |k, v|
         | 
| 135 165 | 
             
                    txt += v if v.is_a?(String)
         | 
| 136 166 | 
             
                  end
         | 
| 137 167 | 
             
                end
         | 
| 138 168 |  | 
| 139 | 
            -
                if help.key?(:on_master) and help.on_master.key?(:admin_master) and help.on_master.admin_master.size > 0
         | 
| 169 | 
            +
                if help.key?(:on_master) and help.on_master.key?(:admin_master) and help.on_master.admin_master.size > 0 and channel_type != :external and channel_type != :extended
         | 
| 140 170 | 
             
                  txt += "===================================
         | 
| 141 | 
            -
             | 
| 171 | 
            +
                    *Master Admin commands:*\n" unless txt.include?('*Master Admin commands*') or !descriptions
         | 
| 142 172 | 
             
                  help.on_master.admin_master.each do |k, v|
         | 
| 143 173 | 
             
                    txt += v if v.is_a?(String)
         | 
| 144 174 | 
             
                  end
         | 
| 145 175 | 
             
                end
         | 
| 146 176 |  | 
| 147 | 
            -
                if help.key?(:rules_file)
         | 
| 177 | 
            +
                if help.key?(:rules_file) and channel_type != :external
         | 
| 148 178 | 
             
                  @logger.info channel_type if config.testing
         | 
| 149 179 | 
             
                  if channel_type == :extended or channel_type == :direct
         | 
| 150 180 | 
             
                    @logger.info help.rules_file if config.testing
         | 
| 151 181 | 
             
                    help.rules_file = help.rules_file.gsub(/^\s*\*These are specific commands.+NAME_OF_BOT THE_COMMAND`\s*$/im, "")
         | 
| 152 182 | 
             
                  end
         | 
| 153 183 |  | 
| 154 | 
            -
                   | 
| 155 | 
            -
                     | 
| 156 | 
            -
             | 
| 157 | 
            -
                      command_done = false
         | 
| 158 | 
            -
                      explanation_done = false
         | 
| 159 | 
            -
                      example_done = false
         | 
| 160 | 
            -
                      if rule.match?(/These are specific commands for this/i)
         | 
| 161 | 
            -
                        resf += rule
         | 
| 162 | 
            -
                        resf += "-"*50
         | 
| 163 | 
            -
                        resf += "\n"
         | 
| 164 | 
            -
                      elsif rule.match?(/To run a command on demand and add the respond on a thread/i)
         | 
| 165 | 
            -
                        resf += rule
         | 
| 166 | 
            -
                        resf += "-"*50
         | 
| 167 | 
            -
                        resf += "\n"
         | 
| 168 | 
            -
                      else
         | 
| 169 | 
            -
                        rule.split("\n").each do |line|
         | 
| 170 | 
            -
                          if line.match?(/^\s*\-+\s*/i)
         | 
| 171 | 
            -
                            resf += line
         | 
| 172 | 
            -
                          elsif !command_done and line.match?(/^\s*`.+`\s*/i)
         | 
| 173 | 
            -
                            resf += "\n#{line}"
         | 
| 174 | 
            -
                            command_done = true
         | 
| 175 | 
            -
                          elsif !explanation_done and line.match?(/^\s+[^`].+\s*/i)
         | 
| 176 | 
            -
                            resf += "\n#{line}"
         | 
| 177 | 
            -
                            explanation_done = true
         | 
| 178 | 
            -
                          elsif !example_done and line.match?(/^\s*_.+_\s*/i)
         | 
| 179 | 
            -
                            resf += "\n     Example: #{line}"
         | 
| 180 | 
            -
                            example_done = true
         | 
| 181 | 
            -
                          end
         | 
| 182 | 
            -
                        end
         | 
| 183 | 
            -
                        resf += "\n\n"
         | 
| 184 | 
            -
                      end
         | 
| 185 | 
            -
                    end
         | 
| 186 | 
            -
                    unless resf.match?(/These are specific commands for this bot on this Channel/i)
         | 
| 187 | 
            -
                      if resf.match?(/\A\s*[=\-]+$/)
         | 
| 188 | 
            -
                        pre = ''
         | 
| 189 | 
            -
                        post = ''
         | 
| 190 | 
            -
                      else
         | 
| 191 | 
            -
                        pre = ('='*50) + "\n"
         | 
| 192 | 
            -
                        post = ('-'*50) + "\n"
         | 
| 193 | 
            -
                      end
         | 
| 194 | 
            -
                      resf = "#{pre}*These are specific commands for this bot on this Channel:*\n#{post}" + resf
         | 
| 195 | 
            -
                    end
         | 
| 196 | 
            -
                    help.rules_file = resf
         | 
| 184 | 
            +
                  if !help.rules_file.to_s.include?('These are specific commands') and help.rules_file!=''
         | 
| 185 | 
            +
                    txt += "===================================
         | 
| 186 | 
            +
                     *Specific commands on this Channel, call them !THE_COMMAND or !!THE_COMMAND:*\n" if descriptions
         | 
| 197 187 | 
             
                  end
         | 
| 188 | 
            +
              
         | 
| 198 189 | 
             
                  txt += help.rules_file
         | 
| 199 190 | 
             
                end
         | 
| 200 | 
            -
             | 
| 201 191 | 
             
                return txt
         | 
| 202 192 | 
             
              end
         | 
| 203 193 | 
             
            end
         | 
| @@ -0,0 +1,12 @@ | |
| 1 | 
            +
            class SlackSmartBot
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              def get_shares()
         | 
| 4 | 
            +
                channel = @channels_name[@channel_id]
         | 
| 5 | 
            +
                if File.exist?("#{config.path}/shares/#{channel}.csv")
         | 
| 6 | 
            +
                  "#{config.path}/shares/#{channel}.csv"
         | 
| 7 | 
            +
                  t = CSV.table("#{config.path}/shares/#{channel}.csv", headers: ['share_id', 'user_deleted', 'user_created', 'date', 'time', 'type', 'to_channel', 'condition'])
         | 
| 8 | 
            +
                  t.delete_if {|row| row[:user_deleted] != ''}
         | 
| 9 | 
            +
                  @shares[channel] = t
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
            end
         | 
| @@ -0,0 +1,12 @@ | |
| 1 | 
            +
            class SlackSmartBot
         | 
| 2 | 
            +
                def has_access?(method, user=nil)
         | 
| 3 | 
            +
                    user = Thread.current[:user] if user.nil?
         | 
| 4 | 
            +
                    if config[:allow_access].key?(method) and !config[:allow_access][method].include?(user.name) and !config[:allow_access][method].include?(user.id) and 
         | 
| 5 | 
            +
                        (!user.key?(:enterprise_user) or ( user.key?(:enterprise_user) and !config[:allow_access][method].include?(user[:enterprise_user].id)))
         | 
| 6 | 
            +
                        respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
         | 
| 7 | 
            +
                        return false
         | 
| 8 | 
            +
                    else
         | 
| 9 | 
            +
                        return true
         | 
| 10 | 
            +
                    end      
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
            end
         |