slack-smart-bot 1.8.1 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +127 -21
- data/lib/slack/smart-bot/comm/ask.rb +55 -42
- data/lib/slack/smart-bot/comm/dont_understand.rb +2 -2
- data/lib/slack/smart-bot/comm/event_hello.rb +34 -0
- data/lib/slack/smart-bot/comm/get_channel_members.rb +13 -0
- data/lib/slack/smart-bot/comm/get_channels.rb +35 -0
- data/lib/slack/smart-bot/comm/get_user_info.rb +20 -0
- data/lib/slack/smart-bot/comm/get_users.rb +24 -0
- data/lib/slack/smart-bot/comm/react.rb +38 -8
- data/lib/slack/smart-bot/comm/respond.rb +219 -48
- 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 +24 -7
- data/lib/slack/smart-bot/comm.rb +7 -1
- data/lib/slack/smart-bot/commands/general/add_announcement.rb +32 -0
- data/lib/slack/smart-bot/commands/general/bot_help.rb +68 -28
- data/lib/slack/smart-bot/commands/general/bot_stats.rb +314 -0
- data/lib/slack/smart-bot/commands/general/bot_status.rb +3 -5
- 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 +13 -16
- data/lib/slack/smart-bot/commands/general/whats_new.rb +19 -0
- data/lib/slack/smart-bot/commands/general_bot_commands.rb +243 -0
- data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +67 -38
- data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +49 -14
- data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +5 -7
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +4 -1
- 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 +12 -4
- data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +4 -1
- 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 +3 -5
- data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +54 -25
- data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +7 -9
- data/lib/slack/smart-bot/commands/on_bot/repl.rb +55 -25
- data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +36 -13
- data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +5 -7
- data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +4 -6
- data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +29 -13
- data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +55 -9
- 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 +5 -3
- data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +2 -1
- 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 +49 -0
- data/lib/slack/smart-bot/commands/on_master/create_bot.rb +30 -21
- data/lib/slack/smart-bot/commands.rb +19 -1
- data/lib/slack/smart-bot/listen.rb +7 -8
- data/lib/slack/smart-bot/process.rb +373 -192
- data/lib/slack/smart-bot/process_first.rb +202 -104
- data/lib/slack/smart-bot/treat_message.rb +325 -186
- data/lib/slack/smart-bot/utils/answer.rb +18 -0
- data/lib/slack/smart-bot/utils/answer_delete.rb +15 -0
- data/lib/slack/smart-bot/utils/build_help.rb +57 -5
- data/lib/slack/smart-bot/utils/create_routine_thread.rb +83 -30
- data/lib/slack/smart-bot/utils/get_bots_created.rb +4 -1
- data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +1 -7
- data/lib/slack/smart-bot/utils/get_help.rb +87 -35
- 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 +23 -8
- data/lib/slack/smart-bot/utils/save_status.rb +52 -0
- data/lib/slack/smart-bot/utils/update_shortcuts_file.rb +6 -0
- data/lib/slack/smart-bot/utils.rb +5 -0
- data/lib/slack-smart-bot.rb +88 -47
- 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 +49 -23
- data/whats_new.txt +36 -0
- metadata +44 -13
- data/lib/slack/smart-bot/commands/on_bot/admin_master/bot_stats.rb +0 -195
@@ -13,7 +13,9 @@ def general_rules(user, command, processed, dest, files = [], rules_file = "")
|
|
13
13
|
# help: Examples:
|
14
14
|
# help: _echo I am the Smart Bot_
|
15
15
|
# help: _100 echo :heart:_
|
16
|
-
|
16
|
+
# help: command_id: :echo
|
17
|
+
# help:
|
18
|
+
when /\A\s*(\d*)\s*echo\s(.+)/i
|
17
19
|
save_stats :echo
|
18
20
|
$1.to_s == '' ? times = 1 : times = $1.to_i
|
19
21
|
respond ($2*times).to_s
|
@@ -25,9 +27,10 @@ def general_rules(user, command, processed, dest, files = [], rules_file = "")
|
|
25
27
|
rescue => exception
|
26
28
|
if defined?(@logger)
|
27
29
|
@logger.fatal exception
|
28
|
-
respond "Unexpected error!! Please contact an admin to solve it: <@#{
|
30
|
+
respond "Unexpected error!! Please contact an admin to solve it: <@#{config.admins.join(">, <@")}>"
|
29
31
|
else
|
30
32
|
puts exception
|
31
33
|
end
|
34
|
+
return false
|
32
35
|
end
|
33
36
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#path to the project folder
|
3
3
|
# for example "#{`eval echo ~$USER`.chop}/projects/the_project"
|
4
4
|
def project_folder()
|
5
|
-
"#{
|
5
|
+
"#{Dir.pwd}/"
|
6
6
|
end
|
7
7
|
|
8
8
|
#link to the project
|
@@ -40,22 +40,25 @@ def rules(user, command, processed, dest, files = [], rules_file = "")
|
|
40
40
|
|
41
41
|
load "#{config.path}/rules/general_rules.rb"
|
42
42
|
|
43
|
-
|
43
|
+
if general_rules(user, command, processed, dest, files, rules_file)
|
44
|
+
return true
|
45
|
+
else
|
44
46
|
begin
|
45
47
|
case command
|
46
48
|
|
47
49
|
# help: ----------------------------------------------
|
48
50
|
# help: `go to sleep`
|
49
51
|
# help: it will sleep the bot for 5 seconds
|
52
|
+
# help: command_id: :go_to_sleep
|
50
53
|
# help:
|
51
|
-
when
|
54
|
+
when /\A\s*go\sto\ssleep/i
|
52
55
|
save_stats :go_to_sleep
|
53
|
-
|
56
|
+
if answer.empty?
|
54
57
|
ask "do you want me to take a siesta?"
|
55
58
|
else
|
56
|
-
case
|
59
|
+
case answer
|
57
60
|
when /yes/i, /yep/i, /sure/i
|
58
|
-
|
61
|
+
answer_delete
|
59
62
|
respond "I'll be sleeping for 5 secs... just for you"
|
60
63
|
respond "zZzzzzzZZZZZZzzzzzzz!"
|
61
64
|
react :sleeping
|
@@ -63,43 +66,52 @@ def rules(user, command, processed, dest, files = [], rules_file = "")
|
|
63
66
|
unreact :sleeping
|
64
67
|
react :sunny
|
65
68
|
when /no/i, /nope/i, /cancel/i
|
66
|
-
|
69
|
+
answer_delete
|
67
70
|
respond "Thanks, I'm happy to be awake"
|
68
71
|
else
|
69
72
|
respond "I don't understand"
|
70
|
-
ask "are you sure
|
73
|
+
ask "are you sure you want me to sleep? (yes or no)"
|
71
74
|
end
|
72
75
|
end
|
73
76
|
|
74
77
|
# help: ----------------------------------------------
|
75
78
|
# help: `run something`
|
76
79
|
# help: It will run the process and report the results when done
|
80
|
+
# help: command_id: :run_something
|
77
81
|
# help:
|
78
|
-
when
|
82
|
+
when /\Arun something/i
|
79
83
|
save_stats :run_something
|
80
|
-
|
84
|
+
if has_access?(:run_something, user)
|
85
|
+
react :runner
|
81
86
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
87
|
+
process_to_run = "ruby -v"
|
88
|
+
process_to_run = ("cd #{project_folder} &&" + process_to_run) if defined?(project_folder)
|
89
|
+
stdout, stderr, status = Open3.capture3(process_to_run)
|
90
|
+
unreact :runner
|
91
|
+
if stderr == ""
|
92
|
+
if stdout == ""
|
93
|
+
respond "#{display_name}: Nothing returned."
|
94
|
+
else
|
95
|
+
respond "#{display_name}: #{stdout}"
|
96
|
+
end
|
89
97
|
else
|
90
|
-
respond "#{display_name}: #{stdout}"
|
98
|
+
respond "#{display_name}: #{stdout} #{stderr}"
|
91
99
|
end
|
92
|
-
else
|
93
|
-
respond "#{display_name}: #{stdout} #{stderr}"
|
94
100
|
end
|
95
101
|
|
96
102
|
# Emoticons you can use with `react` command https://www.webfx.com/tools/emoji-cheat-sheet/
|
97
103
|
|
98
|
-
# Examples for respond and respond_direct
|
104
|
+
# Examples for respond, respond_thread and respond_direct
|
99
105
|
# # send 'the message' to the channel or direct message where the command was written
|
100
106
|
# respond "the message"
|
101
107
|
# # send 'the message' privately as a direct message to the user that sent the command
|
102
108
|
# respond_direct "the message"
|
109
|
+
# # same thing can be done:
|
110
|
+
# respond "the message", :direct
|
111
|
+
# # send 'the message' opening a thread
|
112
|
+
# respond_thread "the message"
|
113
|
+
# # same thing can be done:
|
114
|
+
# respond 'the message', :on_thread
|
103
115
|
# # send 'the message' to a specific channel name
|
104
116
|
# respond "the message", 'my_channel'
|
105
117
|
# # send 'the message' to a specific channel id
|
@@ -109,6 +121,19 @@ def rules(user, command, processed, dest, files = [], rules_file = "")
|
|
109
121
|
# # send 'the message' to a specific user id as direct message
|
110
122
|
# respond "the message", 'US3344D3'
|
111
123
|
|
124
|
+
# Example sending blocks https://api.slack.com/block-kit
|
125
|
+
# my_blocks = [
|
126
|
+
# { type: "context",
|
127
|
+
# elements:
|
128
|
+
# [
|
129
|
+
# { type: "plain_text", :text=>"\tInfo: " },
|
130
|
+
# { type: "image", image_url: "https://avatars.slack-edge.com/2021-03-23/182815_e54abb1dd_24.jpg", alt_text: "mario" },
|
131
|
+
# { type: "mrkdwn", text: " *Mario Ruiz* (marior) " }
|
132
|
+
# ]
|
133
|
+
# }
|
134
|
+
# ]
|
135
|
+
# respond blocks: my_blocks
|
136
|
+
|
112
137
|
# Example downloading a file from slack
|
113
138
|
# if !files.nil? and files.size == 1 and files[0].filetype == 'yaml'
|
114
139
|
# require 'nice_http'
|
@@ -120,16 +145,17 @@ def rules(user, command, processed, dest, files = [], rules_file = "")
|
|
120
145
|
# send_file(to, msg, filepath, title, format, type = "text")
|
121
146
|
# send_file(dest, 'the message', "#{project_folder}/temp/logs_ptBI.log", 'title', 'text/plain', "text")
|
122
147
|
# send_file(dest, 'the message', "#{project_folder}/temp/example.jpeg", 'title', 'image/jpeg', "jpg")
|
123
|
-
|
124
|
-
|
125
148
|
else
|
126
149
|
unless processed
|
127
150
|
dont_understand()
|
128
151
|
end
|
152
|
+
return false
|
129
153
|
end
|
154
|
+
return true
|
130
155
|
rescue => exception
|
131
156
|
@logger.fatal exception
|
132
157
|
respond "Unexpected error!! Please contact an admin to solve it: <@#{config.admins.join(">, <@")}>"
|
158
|
+
return false
|
133
159
|
end
|
134
160
|
end
|
135
161
|
end
|
data/whats_new.txt
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
*Version 1.10.0* Released 2021-Sep-17
|
2
|
+
|
3
|
+
*For General users*
|
4
|
+
- When on a private conversation with the SmartBot (DM) and not using any channels rule on the conversation, the general_rules will be available.
|
5
|
+
- On DM with the SmartBot if you want to use a rule from a specific channel you can use also: `#CHANNEL RULE` or `on #CHANNEL RULE`. For example: `#sales get report for India`
|
6
|
+
- Now when using general commands, the SmartBot will be responding on any channel where is a member, even though is not listening to you. For example: `clear screen`
|
7
|
+
- Added command `suggest command` that will return the help content for a random command.
|
8
|
+
- New command `leaderboard` returns useful information about the use of the SmartBot.
|
9
|
+
- `add COLOR announcement MESSAGE`, `add EMOJI announcement MESSAGE` command stores the message on the announcement list labeled with the color/emoji specified, white by default. Aliases for announcement: statement, declaration, message. Related: `see announcements`, `delete announcement id`
|
10
|
+
- `hi bot` and `bye bot` can be called from any channel where the SmartBot is a member.
|
11
|
+
- Added general command `see statuses`, `who is on vacation?`, `who is not on vacation?`
|
12
|
+
- New general command `see favorite commands`. It will display the favorite commands in that channel.
|
13
|
+
- Now when running the `ruby` command it can be supplied a code block.
|
14
|
+
- New general command `share messages /REGEXP/ on #CHANNEL`, `share messages "TEXT" on #CHANNEL`, `see shares', `delete share ID`. It will automatically share new messages published that meet the specified criteria.
|
15
|
+
|
16
|
+
*For Admin users*
|
17
|
+
- respond_thread method will send the respond creating a thread if necessary. It can be used also `respond 'msg', :on_thread`
|
18
|
+
- `respond 'msg', :direct` will send a direct message to the person that is executing the rule.
|
19
|
+
- You can add general commands that will be responding on any channel where the Smart Bot is a member even though is not 'listening to you'. Add them to '/rules/general_commands.rb
|
20
|
+
- when using `respond` you can supply two options: unfurl_links and unfurl_media. By default is a boolean: true
|
21
|
+
- added option 'weekdays' and 'weekends' for `create routine` command, for example: `add silent routine suggestions on weekdays at 09:00 suggest command`
|
22
|
+
- Added a new config for the SmartBot to log all RTM communication, admits `true` or `false`, by default `false`: `logrtm`
|
23
|
+
- Use the command `send message to` and `react to` to impersonate the SmartBot. Only accessible for Master Admins on a DM with the SmartBot.
|
24
|
+
- New command to see the result of the last run of a routine: `see result routine NAME`
|
25
|
+
- Now it is possible to create *bgroutine* then the results of the routine run won't be published.
|
26
|
+
- To display a general message after every command use: `set general message MESSAGE`. Use `set general message off` to stop displaying it.
|
27
|
+
- When adding a general message is possible to use interpolation
|
28
|
+
- If you are a master admin and you are on master channel then you can call `publish announcements` that will publish the announcements on all channels. The messages stored on a DM won't be published. This is very convenient to be called from a *Routine* for example every weekday at 09:00.
|
29
|
+
- Now it is possible to send blocks `respond blocks: my_blocks`. More info about blocks: https://api.slack.com/block-kit
|
30
|
+
- When using bgroutines if we want to avoid a file to be sent:
|
31
|
+
send_file(dest, 'description', "file_path", 'desc', 'text/plain', "text") unless Thread.current[:routine_type] == 'bgroutine'
|
32
|
+
- SmartBot will notify about SmartBot status changes if defined the status_channel in config file and the channel exists. By default: smartbot-status
|
33
|
+
|
34
|
+
------------------------------
|
35
|
+
|
36
|
+
*Previous*: <https://github.com/MarioRuiz/slack-smart-bot/blob/dd23939f93ee95aca3c04d33cd1ce197d6efbd37/whats_new.txt|1.9.0>
|
metadata
CHANGED
@@ -1,35 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack-smart-bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Ruiz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slack-ruby-client
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.15'
|
20
17
|
- - ">="
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.
|
19
|
+
version: 0.17.0
|
20
|
+
- - "~>"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0.17'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0.15'
|
30
27
|
- - ">="
|
31
28
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.
|
29
|
+
version: 0.17.0
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.17'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: nice_http
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
version: '1'
|
82
82
|
- - ">="
|
83
83
|
- !ruby/object:Gem::Version
|
84
|
-
version: 1.
|
84
|
+
version: 1.3.0
|
85
85
|
type: :runtime
|
86
86
|
prerelease: false
|
87
87
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -91,7 +91,7 @@ dependencies:
|
|
91
91
|
version: '1'
|
92
92
|
- - ">="
|
93
93
|
- !ruby/object:Gem::Version
|
94
|
-
version: 1.
|
94
|
+
version: 1.3.0
|
95
95
|
- !ruby/object:Gem::Dependency
|
96
96
|
name: rspec
|
97
97
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,25 +125,45 @@ files:
|
|
125
125
|
- LICENSE
|
126
126
|
- README.md
|
127
127
|
- lib/slack-smart-bot.rb
|
128
|
+
- lib/slack-smart-bot_general_commands.rb
|
128
129
|
- lib/slack-smart-bot_general_rules.rb
|
129
130
|
- lib/slack-smart-bot_rules.rb
|
130
131
|
- lib/slack/smart-bot/comm.rb
|
131
132
|
- lib/slack/smart-bot/comm/ask.rb
|
132
133
|
- lib/slack/smart-bot/comm/dont_understand.rb
|
134
|
+
- lib/slack/smart-bot/comm/event_hello.rb
|
135
|
+
- lib/slack/smart-bot/comm/get_channel_members.rb
|
136
|
+
- lib/slack/smart-bot/comm/get_channels.rb
|
137
|
+
- lib/slack/smart-bot/comm/get_user_info.rb
|
138
|
+
- lib/slack/smart-bot/comm/get_users.rb
|
133
139
|
- lib/slack/smart-bot/comm/react.rb
|
134
140
|
- lib/slack/smart-bot/comm/respond.rb
|
135
141
|
- lib/slack/smart-bot/comm/respond_direct.rb
|
142
|
+
- lib/slack/smart-bot/comm/respond_thread.rb
|
136
143
|
- lib/slack/smart-bot/comm/send_file.rb
|
137
144
|
- lib/slack/smart-bot/comm/send_msg_channel.rb
|
138
145
|
- lib/slack/smart-bot/comm/send_msg_user.rb
|
139
146
|
- lib/slack/smart-bot/comm/unreact.rb
|
140
147
|
- lib/slack/smart-bot/commands.rb
|
148
|
+
- lib/slack/smart-bot/commands/general/add_announcement.rb
|
141
149
|
- lib/slack/smart-bot/commands/general/bot_help.rb
|
150
|
+
- lib/slack/smart-bot/commands/general/bot_stats.rb
|
142
151
|
- lib/slack/smart-bot/commands/general/bot_status.rb
|
143
152
|
- lib/slack/smart-bot/commands/general/bye_bot.rb
|
153
|
+
- lib/slack/smart-bot/commands/general/delete_announcement.rb
|
154
|
+
- lib/slack/smart-bot/commands/general/delete_share.rb
|
144
155
|
- lib/slack/smart-bot/commands/general/hi_bot.rb
|
156
|
+
- lib/slack/smart-bot/commands/general/leaderboard.rb
|
157
|
+
- lib/slack/smart-bot/commands/general/see_announcements.rb
|
158
|
+
- lib/slack/smart-bot/commands/general/see_favorite_commands.rb
|
159
|
+
- lib/slack/smart-bot/commands/general/see_shares.rb
|
160
|
+
- lib/slack/smart-bot/commands/general/see_statuses.rb
|
161
|
+
- lib/slack/smart-bot/commands/general/share_messages.rb
|
145
162
|
- lib/slack/smart-bot/commands/general/stop_using_rules.rb
|
163
|
+
- lib/slack/smart-bot/commands/general/suggest_command.rb
|
146
164
|
- lib/slack/smart-bot/commands/general/use_rules.rb
|
165
|
+
- lib/slack/smart-bot/commands/general/whats_new.rb
|
166
|
+
- lib/slack/smart-bot/commands/general_bot_commands.rb
|
147
167
|
- lib/slack/smart-bot/commands/on_bot/add_shortcut.rb
|
148
168
|
- lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb
|
149
169
|
- lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb
|
@@ -151,12 +171,14 @@ files:
|
|
151
171
|
- lib/slack/smart-bot/commands/on_bot/admin/pause_routine.rb
|
152
172
|
- lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb
|
153
173
|
- lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb
|
174
|
+
- lib/slack/smart-bot/commands/on_bot/admin/see_result_routine.rb
|
154
175
|
- lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb
|
155
176
|
- lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb
|
156
177
|
- lib/slack/smart-bot/commands/on_bot/admin/start_routine.rb
|
157
178
|
- lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb
|
158
|
-
- lib/slack/smart-bot/commands/on_bot/admin_master/bot_stats.rb
|
159
179
|
- lib/slack/smart-bot/commands/on_bot/admin_master/get_bot_logs.rb
|
180
|
+
- lib/slack/smart-bot/commands/on_bot/admin_master/react_to.rb
|
181
|
+
- lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb
|
160
182
|
- lib/slack/smart-bot/commands/on_bot/delete_repl.rb
|
161
183
|
- lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb
|
162
184
|
- lib/slack/smart-bot/commands/on_bot/get_repl.rb
|
@@ -169,12 +191,17 @@ files:
|
|
169
191
|
- lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb
|
170
192
|
- lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb
|
171
193
|
- lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb
|
194
|
+
- lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb
|
195
|
+
- lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb
|
196
|
+
- lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb
|
172
197
|
- lib/slack/smart-bot/commands/on_master/create_bot.rb
|
173
198
|
- lib/slack/smart-bot/listen.rb
|
174
199
|
- lib/slack/smart-bot/process.rb
|
175
200
|
- lib/slack/smart-bot/process_first.rb
|
176
201
|
- lib/slack/smart-bot/treat_message.rb
|
177
202
|
- lib/slack/smart-bot/utils.rb
|
203
|
+
- lib/slack/smart-bot/utils/answer.rb
|
204
|
+
- lib/slack/smart-bot/utils/answer_delete.rb
|
178
205
|
- lib/slack/smart-bot/utils/build_help.rb
|
179
206
|
- lib/slack/smart-bot/utils/create_routine_thread.rb
|
180
207
|
- lib/slack/smart-bot/utils/get_bots_created.rb
|
@@ -183,13 +210,17 @@ files:
|
|
183
210
|
- lib/slack/smart-bot/utils/get_repls.rb
|
184
211
|
- lib/slack/smart-bot/utils/get_routines.rb
|
185
212
|
- lib/slack/smart-bot/utils/get_rules_imported.rb
|
213
|
+
- lib/slack/smart-bot/utils/get_shares.rb
|
214
|
+
- lib/slack/smart-bot/utils/has_access.rb
|
186
215
|
- lib/slack/smart-bot/utils/remove_hash_keys.rb
|
187
216
|
- lib/slack/smart-bot/utils/save_stats.rb
|
217
|
+
- lib/slack/smart-bot/utils/save_status.rb
|
188
218
|
- lib/slack/smart-bot/utils/update_bots_file.rb
|
189
219
|
- lib/slack/smart-bot/utils/update_repls.rb
|
190
220
|
- lib/slack/smart-bot/utils/update_routines.rb
|
191
221
|
- lib/slack/smart-bot/utils/update_rules_imported.rb
|
192
222
|
- lib/slack/smart-bot/utils/update_shortcuts_file.rb
|
223
|
+
- whats_new.txt
|
193
224
|
homepage: https://github.com/MarioRuiz/slack-smart-bot
|
194
225
|
licenses:
|
195
226
|
- MIT
|
@@ -1,195 +0,0 @@
|
|
1
|
-
class SlackSmartBot
|
2
|
-
# helpadmin: ----------------------------------------------
|
3
|
-
# helpadmin: `bot stats`
|
4
|
-
# helpadmin: `bot stats USER_NAME`
|
5
|
-
# helpadmin: `bot stats exclude masters`
|
6
|
-
# helpadmin: `bot stats from YYYY/MM/DD`
|
7
|
-
# helpadmin: `bot stats from YYYY/MM/DD to YYYY/MM/DD`
|
8
|
-
# helpadmin: `bot stats CHANNEL`
|
9
|
-
# helpadmin: `bot stats CHANNEL from YYYY/MM/DD`
|
10
|
-
# helpadmin: `bot stats CHANNEL from YYYY/MM/DD to YYYY/MM/DD`
|
11
|
-
# helpadmin: `bot stats USER_NAME from YYYY/MM/DD to YYYY/MM/DD`
|
12
|
-
# helpadmin: `bot stats CHANNEL USER_NAME from YYYY/MM/DD to YYYY/MM/DD`
|
13
|
-
# helpadmin: `bot stats CHANNEL exclude masters from YYYY/MM/DD to YYYY/MM/DD`
|
14
|
-
# helpadmin: `bot stats today`
|
15
|
-
# helpadmin: `bot stats exclude COMMAND_ID`
|
16
|
-
# helpadmin: `bot stats monthly`
|
17
|
-
# helpadmin: To see the bot stats
|
18
|
-
# helpadmin: You can use this command only if you are a Master admin user and if you are in a private conversation with the bot
|
19
|
-
# helpadmin: You need to set stats to true to generate the stats when running the bot instance.
|
20
|
-
# helpadmin: Examples:
|
21
|
-
# helpadmin: _bot stats #sales_
|
22
|
-
# helpadmin: _bot stats @peter.wind_
|
23
|
-
# helpadmin: _bot stats #sales from 2019/12/15 to 2019/12/31_
|
24
|
-
# helpadmin: _bot stats #sales today_
|
25
|
-
# helpadmin: _bot stats #sales from 2020-01-01 monthly_
|
26
|
-
# helpadmin:
|
27
|
-
def bot_stats(dest, from_user, typem, channel_id, from, to, user, exclude_masters, exclude_command, monthly)
|
28
|
-
require 'csv'
|
29
|
-
if config.stats
|
30
|
-
message = []
|
31
|
-
else
|
32
|
-
message = ["You need to set stats to true to generate the stats when running the bot instance."]
|
33
|
-
end
|
34
|
-
save_stats(__method__)
|
35
|
-
if (config.masters.include?(from_user) or @master_admin_users_id.include?(from_user)) and typem==:on_dm #master admin user
|
36
|
-
if !File.exist?("#{config.stats_path}.#{Time.now.strftime("%Y-%m")}.log")
|
37
|
-
message<<'No stats'
|
38
|
-
else
|
39
|
-
from = "#{Time.now.strftime("%Y-%m")}-01" if from == ''
|
40
|
-
to = "#{Time.now.strftime("%Y-%m-%d")}" if to == ''
|
41
|
-
from_short = from
|
42
|
-
to_short = to
|
43
|
-
from_file = from[0..3] + '-' + from[5..6]
|
44
|
-
to_file = to[0..3] + '-' + to[5..6]
|
45
|
-
from+= " 00:00:00 +0000"
|
46
|
-
to+= " 23:59:59 +0000"
|
47
|
-
rows = []
|
48
|
-
rows_month = {}
|
49
|
-
users_month = {}
|
50
|
-
commands_month = {}
|
51
|
-
users_id_name = {}
|
52
|
-
users_name_id = {}
|
53
|
-
|
54
|
-
# to translate global and enterprise users since sometimes was returning different names/ids
|
55
|
-
Dir["#{config.stats_path}.*.log"].sort.each do |file|
|
56
|
-
if file >= "#{config.stats_path}.#{from_file}.log" or file <= "#{config.stats_path}.#{to_file}.log"
|
57
|
-
CSV.foreach(file, headers: true, header_converters: :symbol, converters: :numeric) do |row|
|
58
|
-
unless users_id_name.key?(row[:user_id])
|
59
|
-
users_id_name[row[:user_id]] = row[:user_name]
|
60
|
-
end
|
61
|
-
unless users_name_id.key?(row[:user_name])
|
62
|
-
users_name_id[row[:user_name]] = row[:user_id]
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
if user!=''
|
70
|
-
user_info = client.web_client.users_info(user: user)
|
71
|
-
if users_id_name.key?(user_info.user.id)
|
72
|
-
user_name = users_id_name[user_info.user.id]
|
73
|
-
else
|
74
|
-
user_name = user_info.user.name
|
75
|
-
end
|
76
|
-
if users_name_id.key?(user_info.user.name)
|
77
|
-
user_id = users_name_id[user_info.user.name]
|
78
|
-
else
|
79
|
-
user_id = user_info.user.id
|
80
|
-
end
|
81
|
-
end
|
82
|
-
master_admins = config.masters.dup
|
83
|
-
config.masters.each do |u|
|
84
|
-
if users_id_name.key?(u)
|
85
|
-
master_admins << users_id_name[u]
|
86
|
-
elsif users_name_id.key?(u)
|
87
|
-
master_admins << users_name_id[u]
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
Dir["#{config.stats_path}.*.log"].sort.each do |file|
|
92
|
-
if file >= "#{config.stats_path}.#{from_file}.log" or file <= "#{config.stats_path}.#{to_file}.log"
|
93
|
-
CSV.foreach(file, headers: true, header_converters: :symbol, converters: :numeric) do |row|
|
94
|
-
row[:date] = row[:date].to_s
|
95
|
-
row[:user_name] = users_id_name[row[:user_id]]
|
96
|
-
row[:user_id] = users_name_id[row[:user_name]]
|
97
|
-
if !exclude_masters or (exclude_masters and !master_admins.include?(row[:user_name]) and
|
98
|
-
!master_admins.include?(row[:user_id]) and
|
99
|
-
!@master_admin_users_id.include?(row[:user_id]))
|
100
|
-
if user=='' or (user!='' and row[:user_name] == user_name) or (user!='' and row[:user_id] == user_id)
|
101
|
-
if exclude_command == '' or (exclude_command!='' and row[:command]!=exclude_command)
|
102
|
-
if row[:bot_channel_id] == channel_id or channel_id == ''
|
103
|
-
if row[:date] >= from and row[:date] <= to
|
104
|
-
rows << row.to_h
|
105
|
-
if monthly
|
106
|
-
rows_month[row[:date][0..6]] = 0 unless rows_month.key?(row[:date][0..6])
|
107
|
-
users_month[row[:date][0..6]] = [] unless users_month.key?(row[:date][0..6])
|
108
|
-
commands_month[row[:date][0..6]] = [] unless commands_month.key?(row[:date][0..6])
|
109
|
-
rows_month[row[:date][0..6]] += 1
|
110
|
-
users_month[row[:date][0..6]] << row[:user_id]
|
111
|
-
commands_month[row[:date][0..6]] << row[:command]
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
total = rows.size
|
122
|
-
if exclude_masters
|
123
|
-
message << 'Excluding master admins'
|
124
|
-
end
|
125
|
-
if exclude_command != ''
|
126
|
-
message << "Excluding command #{exclude_command}"
|
127
|
-
end
|
128
|
-
if user!=''
|
129
|
-
message << "Showing only user <@#{user}>"
|
130
|
-
end
|
131
|
-
if channel_id == ''
|
132
|
-
message << "*Total calls*: #{total} from #{from_short} to #{to_short}"
|
133
|
-
else
|
134
|
-
message << "*Total calls <##{channel_id}>*: #{total} from #{from_short} to #{to_short}"
|
135
|
-
end
|
136
|
-
if total > 0
|
137
|
-
if monthly
|
138
|
-
message << '*Totals by month / commands / users (%new)*'
|
139
|
-
all_users = []
|
140
|
-
new_users = []
|
141
|
-
rows_month.each do |k,v|
|
142
|
-
if all_users.empty?
|
143
|
-
message_new_users = ''
|
144
|
-
else
|
145
|
-
new_users = (users_month[k]-all_users).uniq
|
146
|
-
message_new_users = "(#{new_users.size*100/users_month[k].uniq.size}%)"
|
147
|
-
end
|
148
|
-
all_users += users_month[k]
|
149
|
-
message << "\t#{k}: #{v} (#{(v.to_f*100/total).round(2)}%) / #{commands_month[k].uniq.size} / #{users_month[k].uniq.size} #{message_new_users}"
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
if channel_id == ''
|
154
|
-
message << "*Channels*"
|
155
|
-
channels = rows.bot_channel.uniq.sort
|
156
|
-
channels.each do |channel|
|
157
|
-
count = rows.count {|h| h.bot_channel==channel}
|
158
|
-
message << "\t#{channel}: #{count} (#{(count.to_f*100/total).round(2)}%)"
|
159
|
-
end
|
160
|
-
end
|
161
|
-
if user==''
|
162
|
-
users = rows.user_id.uniq.sort
|
163
|
-
message << "*Users* - #{users.size}"
|
164
|
-
count_user = {}
|
165
|
-
users.each do |user|
|
166
|
-
count = rows.count {|h| h.user_id==user}
|
167
|
-
count_user[user] = count
|
168
|
-
end
|
169
|
-
count_user.sort_by {|k,v| -v}.each do |user, count|
|
170
|
-
message << "\t#{users_id_name[user]}: #{count} (#{(count.to_f*100/total).round(2)}%)"
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
commands = rows.command.uniq.sort
|
175
|
-
message << "*Commands* - #{commands.size}"
|
176
|
-
commands.each do |command|
|
177
|
-
count = rows.count {|h| h.command==command}
|
178
|
-
message << "\t#{command}: #{count} (#{(count.to_f*100/total).round(2)}%)"
|
179
|
-
end
|
180
|
-
|
181
|
-
message << "*Message type*"
|
182
|
-
types = rows.type_message.uniq.sort
|
183
|
-
types.each do |type|
|
184
|
-
count = rows.count {|h| h.type_message==type}
|
185
|
-
message << "\t#{type}: #{count} (#{(count.to_f*100/total).round(2)}%)"
|
186
|
-
end
|
187
|
-
message << "*Last activity*: #{rows[-1].date} #{rows[-1].bot_channel} #{rows[-1].type_message} #{rows[-1].user_name} #{rows[-1].command}"
|
188
|
-
end
|
189
|
-
end
|
190
|
-
else
|
191
|
-
message<<"Only Master admin users on a private conversation with the bot can see the bot stats."
|
192
|
-
end
|
193
|
-
respond "#{message.join("\n")}", dest
|
194
|
-
end
|
195
|
-
end
|