slack-smart-bot 1.9.1 → 1.11.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.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +184 -16
  3. data/lib/slack/smart-bot/comm/ask.rb +55 -49
  4. data/lib/slack/smart-bot/comm/delete.rb +13 -0
  5. data/lib/slack/smart-bot/comm/dont_understand.rb +3 -3
  6. data/lib/slack/smart-bot/comm/event_hello.rb +8 -4
  7. data/lib/slack/smart-bot/comm/get_channel_members.rb +13 -4
  8. data/lib/slack/smart-bot/comm/get_channels.rb +31 -16
  9. data/lib/slack/smart-bot/comm/get_presence.rb +20 -0
  10. data/lib/slack/smart-bot/comm/get_user_info.rb +12 -8
  11. data/lib/slack/smart-bot/comm/get_users.rb +24 -0
  12. data/lib/slack/smart-bot/comm/react.rb +19 -2
  13. data/lib/slack/smart-bot/comm/respond.rb +224 -53
  14. data/lib/slack/smart-bot/comm/respond_direct.rb +2 -3
  15. data/lib/slack/smart-bot/comm/respond_thread.rb +5 -0
  16. data/lib/slack/smart-bot/comm/send_file.rb +38 -34
  17. data/lib/slack/smart-bot/comm/send_msg_channel.rb +27 -22
  18. data/lib/slack/smart-bot/comm/send_msg_user.rb +59 -33
  19. data/lib/slack/smart-bot/comm/unreact.rb +22 -18
  20. data/lib/slack/smart-bot/comm.rb +4 -0
  21. data/lib/slack/smart-bot/commands/general/add_admin.rb +51 -0
  22. data/lib/slack/smart-bot/commands/general/add_announcement.rb +32 -0
  23. data/lib/slack/smart-bot/commands/general/add_team.rb +80 -0
  24. data/lib/slack/smart-bot/commands/general/allow_access.rb +67 -0
  25. data/lib/slack/smart-bot/commands/general/bot_help.rb +69 -33
  26. data/lib/slack/smart-bot/commands/general/bye_bot.rb +0 -7
  27. data/lib/slack/smart-bot/commands/general/delete_announcement.rb +34 -0
  28. data/lib/slack/smart-bot/commands/general/delete_share.rb +34 -0
  29. data/lib/slack/smart-bot/commands/general/delete_team.rb +34 -0
  30. data/lib/slack/smart-bot/commands/general/deny_access.rb +36 -0
  31. data/lib/slack/smart-bot/commands/general/hi_bot.rb +16 -11
  32. data/lib/slack/smart-bot/commands/general/ping_team.rb +100 -0
  33. data/lib/slack/smart-bot/commands/general/poster.rb +116 -0
  34. data/lib/slack/smart-bot/commands/general/remove_admin.rb +58 -0
  35. data/lib/slack/smart-bot/commands/general/see_access.rb +24 -0
  36. data/lib/slack/smart-bot/commands/general/see_admins.rb +33 -0
  37. data/lib/slack/smart-bot/commands/general/see_announcements.rb +115 -0
  38. data/lib/slack/smart-bot/commands/general/see_command_ids.rb +29 -0
  39. data/lib/slack/smart-bot/commands/general/see_favorite_commands.rb +53 -0
  40. data/lib/slack/smart-bot/commands/general/see_shares.rb +41 -0
  41. data/lib/slack/smart-bot/commands/general/see_statuses.rb +91 -0
  42. data/lib/slack/smart-bot/commands/general/see_teams.rb +252 -0
  43. data/lib/slack/smart-bot/commands/general/share_messages.rb +58 -0
  44. data/lib/slack/smart-bot/commands/general/update_team.rb +109 -0
  45. data/lib/slack/smart-bot/commands/general_bot_commands.rb +504 -0
  46. data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +4 -6
  47. data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +45 -14
  48. data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +4 -1
  49. data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +6 -3
  50. data/lib/slack/smart-bot/commands/on_bot/admin/pause_routine.rb +3 -1
  51. data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +4 -4
  52. data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +8 -2
  53. data/lib/slack/smart-bot/commands/on_bot/admin/see_result_routine.rb +33 -0
  54. data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +13 -10
  55. data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +6 -3
  56. data/lib/slack/smart-bot/commands/on_bot/admin/start_routine.rb +3 -1
  57. data/lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb +4 -1
  58. data/lib/slack/smart-bot/commands/on_bot/admin_master/delete_message.rb +25 -0
  59. data/lib/slack/smart-bot/commands/on_bot/admin_master/get_bot_logs.rb +1 -0
  60. data/lib/slack/smart-bot/commands/on_bot/admin_master/react_to.rb +34 -0
  61. data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +37 -0
  62. data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +4 -5
  63. data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +7 -8
  64. data/lib/slack/smart-bot/commands/on_bot/general/bot_stats.rb +400 -0
  65. data/lib/slack/smart-bot/commands/{general → on_bot/general}/bot_status.rb +3 -4
  66. data/lib/slack/smart-bot/commands/on_bot/general/leaderboard.rb +201 -0
  67. data/lib/slack/smart-bot/commands/{general → on_bot/general}/stop_using_rules.rb +12 -6
  68. data/lib/slack/smart-bot/commands/on_bot/general/suggest_command.rb +36 -0
  69. data/lib/slack/smart-bot/commands/{general → on_bot/general}/use_rules.rb +13 -11
  70. data/lib/slack/smart-bot/commands/{general → on_bot/general}/whats_new.rb +2 -1
  71. data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +4 -5
  72. data/lib/slack/smart-bot/commands/on_bot/repl.rb +76 -21
  73. data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +3 -4
  74. data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +15 -7
  75. data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +5 -6
  76. data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +5 -6
  77. data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +45 -12
  78. data/lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb +7 -3
  79. data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +4 -1
  80. data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +3 -1
  81. data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +33 -0
  82. data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +39 -0
  83. data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +10 -1
  84. data/lib/slack/smart-bot/commands/on_master/create_bot.rb +28 -14
  85. data/lib/slack/smart-bot/commands/on_master/where_smartbot.rb +41 -0
  86. data/lib/slack/smart-bot/commands.rb +36 -5
  87. data/lib/slack/smart-bot/listen.rb +31 -33
  88. data/lib/slack/smart-bot/process.rb +234 -73
  89. data/lib/slack/smart-bot/process_first.rb +119 -38
  90. data/lib/slack/smart-bot/treat_message.rb +310 -237
  91. data/lib/slack/smart-bot/utils/build_help.rb +2 -2
  92. data/lib/slack/smart-bot/utils/create_routine_thread.rb +81 -46
  93. data/lib/slack/smart-bot/utils/get_access_channels.rb +13 -0
  94. data/lib/slack/smart-bot/utils/get_admins_channels.rb +13 -0
  95. data/lib/slack/smart-bot/utils/get_bots_created.rb +28 -8
  96. data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +7 -2
  97. data/lib/slack/smart-bot/utils/get_command_ids.rb +84 -0
  98. data/lib/slack/smart-bot/utils/get_help.rb +79 -73
  99. data/lib/slack/smart-bot/utils/get_repls.rb +22 -2
  100. data/lib/slack/smart-bot/utils/get_routines.rb +22 -2
  101. data/lib/slack/smart-bot/utils/get_shares.rb +12 -0
  102. data/lib/slack/smart-bot/utils/get_teams.rb +22 -0
  103. data/lib/slack/smart-bot/utils/has_access.rb +28 -0
  104. data/lib/slack/smart-bot/utils/is_admin.rb +27 -0
  105. data/lib/slack/smart-bot/utils/save_stats.rb +46 -41
  106. data/lib/slack/smart-bot/utils/save_status.rb +67 -0
  107. data/lib/slack/smart-bot/utils/update_access_channels.rb +8 -0
  108. data/lib/slack/smart-bot/utils/update_admins_channels.rb +8 -0
  109. data/lib/slack/smart-bot/utils/update_bots_file.rb +28 -7
  110. data/lib/slack/smart-bot/utils/update_repls.rb +7 -4
  111. data/lib/slack/smart-bot/utils/update_routines.rb +9 -3
  112. data/lib/slack/smart-bot/utils/update_shortcuts_file.rb +13 -6
  113. data/lib/slack/smart-bot/utils/update_teams.rb +16 -0
  114. data/lib/slack/smart-bot/utils.rb +11 -0
  115. data/lib/slack-smart-bot.rb +72 -12
  116. data/lib/slack-smart-bot_general_commands.rb +61 -0
  117. data/lib/slack-smart-bot_general_rules.rb +5 -2
  118. data/lib/slack-smart-bot_rules.rb +43 -17
  119. data/whats_new.txt +20 -15
  120. metadata +76 -9
  121. data/lib/slack/smart-bot/commands/general/bot_stats.rb +0 -313
@@ -0,0 +1,504 @@
1
+ # add here the general commands you will be using in any channel where The SmartBot is part of. Not necessary to use ! or ^, it will answer directly.
2
+ def general_bot_commands(user, command, dest, files = [])
3
+
4
+ begin
5
+ if config.simulate
6
+ display_name = user.profile.display_name
7
+ else
8
+ if user.profile.display_name.to_s.match?(/\A\s*\z/)
9
+ user.profile.display_name = user.profile.real_name
10
+ end
11
+ display_name = user.profile.display_name
12
+ end
13
+
14
+ case command
15
+
16
+
17
+ # help: ----------------------------------------------
18
+ # help: `bot help`
19
+ # help: `bot help COMMAND`
20
+ # help: `bot rules`
21
+ # help: `bot rules COMMAND`
22
+ # help: `bot help expanded`
23
+ # help: `bot rules expanded`
24
+ # help: `bot what can I do?`
25
+ # help: it will display this help. For a more detailed help call `bot help expanded` or `bot rules expanded`.
26
+ # help: if COMMAND supplied just help for that command
27
+ # help: you can use the option 'expanded' or the alias 'extended'
28
+ # help: `bot rules` will show only the specific rules for this channel.
29
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#bot-help|more info>
30
+ # help: command_id: :bot_help
31
+ # help:
32
+
33
+
34
+ # help: ----------------------------------------------
35
+ # help: `Hi Bot`
36
+ # help: `Hi Smart`
37
+ # help: `Hello Bot` `Hola Bot` `Hallo Bot` `What's up Bot` `Hey Bot` `Hæ Bot`
38
+ # help: `Hello THE_NAME_OF_THE_BOT`
39
+ # help: Bot starts listening to you if you are on a Bot channel
40
+ # help: After that if you want to avoid a single message to be treated by the smart bot, start the message by -
41
+ # help: Also apart of Hello you can use _Hallo, Hi, Hola, What's up, Hey, Hæ_
42
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#how-to-access-the-smart-bot|more info>
43
+ # help: command_id: :hi_bot
44
+ # help:
45
+ when /\A\s*(Hello|Hallo|Hi|Hola|What's\sup|Hey|Hæ)\s+(#{@salutations.join("|")})\s*$/i
46
+ hi_bot(user, dest, user.name, display_name)
47
+
48
+ # help: ----------------------------------------------
49
+ # help: `Bye Bot`
50
+ # help: `Bye Smart`
51
+ # help: `Bye NAME_OF_THE_BOT`
52
+ # help: Bot stops listening to you if you are on a Bot channel
53
+ # help: Also apart of Bye you can use _Bæ, Good Bye, Adiós, Ciao, Bless, Bless Bless, Adeu_
54
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#how-to-access-the-smart-bot|more info>
55
+ # help: command_id: :bye_bot
56
+ # help:
57
+ when /\A\s*(Bye|Bæ|Good\s+Bye|Adiós|Ciao|Bless|Bless\sBless|Adeu)\s+(#{@salutations.join("|")})\s*$/i
58
+ bye_bot(dest, user.name, display_name)
59
+
60
+ # help: ----------------------------------------------
61
+ # help: `add announcement MESSAGE`
62
+ # help: `add red announcement MESSAGE`
63
+ # help: `add green announcement MESSAGE`
64
+ # help: `add yellow announcement MESSAGE`
65
+ # help: `add white announcement MESSAGE`
66
+ # help: `add EMOJI announcement MESSAGE`
67
+ # help: It will store the message on the announcement list labeled with the color or emoji specified, white by default.
68
+ # help: aliases for announcement: statement, declaration, message
69
+ # help: Examples:
70
+ # help: _add green announcement :heavy_check_mark: All customer services are up and running_
71
+ # help: _add red declaration Customers db is down :x:_
72
+ # help: _add yellow statement Don't access the linux server without VPN_
73
+ # help: _add message `*Party* will start at *20:00* :tada:`_
74
+ # help: _add :heavy_exclamation_mark: message Pay attention all DB are on maintenance until 20:00 GMT_
75
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#announcements|more info>
76
+ # help: command_id: :add_announcement
77
+ # help:
78
+ when /\A\s*(add|create)\s+(red\s+|green\s+|white\s+|yellow\s+)?(announcement|statement|declaration|message)\s+(.+)\s*\z/i,
79
+ /\A\s*(add|create)\s+(:\w+:)\s+(announcement|statement|declaration|message)\s+(.+)\s*\z/i
80
+ type = $2.to_s.downcase.strip
81
+ type = 'white' if type == ''
82
+ message = $4
83
+ add_announcement(user, type, message)
84
+
85
+
86
+ # help: ----------------------------------------------
87
+ # help: `delete announcement ID`
88
+ # help: It will delete the message on the announcement list.
89
+ # help: aliases for announcement: statement, declaration, message
90
+ # help: Examples:
91
+ # help: _delete announcement 24_
92
+ # help: _delete message 645_
93
+ # help: _delete statement 77_
94
+ # help: _delete declaration 334_
95
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#announcements|more info>
96
+ # help: command_id: :delete_announcement
97
+ # help:
98
+ when /\A\s*(delete|remove)\s+(announcement|statement|declaration|message)\s+(\d+)\s*\z/i
99
+ message_id = $3
100
+ delete_announcement(user, message_id)
101
+
102
+ # help: ----------------------------------------------
103
+ # help: `see announcements`
104
+ # help: `see red announcements`
105
+ # help: `see green announcements`
106
+ # help: `see yellow announcements`
107
+ # help: `see white announcements`
108
+ # help: `see EMOJI announcements`
109
+ # helpmaster: `see announcements #CHANNEL`
110
+ # helpmaster: `see all announcements`
111
+ # help: It will display the announcements for the channel.
112
+ # help: aliases for announcements: statements, declarations, messages
113
+ # helpmaster: In case #CHANNEL it will display the announcements for that channel. Only master admins can use it from a DM with the Smartbot.
114
+ # helpmaster: In case 'all' it will display all the announcements for all channels. Only master admins can use it from a DM with the Smartbot.
115
+ # help: Examples:
116
+ # help: _see announcements_
117
+ # help: _see white messages_
118
+ # help: _see red statements_
119
+ # help: _see yellow declarations_
120
+ # help: _see messages_
121
+ # help: _see :heavy_exclamation_mark: messages_
122
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#announcements|more info>
123
+ # help: command_id: :see_announcements
124
+ # help:
125
+ when /\A\s*see\s+(red\s+|green\s+|white\s+|yellow\s+|:\w+:\s+)?(announcements|statements|declarations|messages)()\s*\z/i,
126
+ /\A\s*see\s+(all\s+)?(announcements|statements|declarations|messages)()\s*\z/i,
127
+ /\A\s*see\s+(red\s+|green\s+|white\s+|yellow\s+|:\w+:\s+)?(announcements|statements|declarations|messages)\s+#([\w\-]+)\s*\z/i,
128
+ /\A\s*see\s+(red\s+|green\s+|white\s+|yellow\s+|:\w+:\s+)?(announcements|statements|declarations|messages)\s+<#(\w+)\|.*>\s*\z/i
129
+
130
+ type = $1.to_s.downcase.strip
131
+ channel = $3.to_s
132
+
133
+ see_announcements(user, type, channel)
134
+
135
+
136
+ # help: ----------------------------------------------
137
+ # help: `share messages /REGEXP/ on #CHANNEL`
138
+ # help: `share messages "TEXT" on #CHANNEL`
139
+ # xhelp: `share messages :EMOJI: on #CHANNEL`
140
+ # help: It will automatically share new messages published that meet the specified criteria.
141
+ # xhelp: In case :EMOJI: it will share the messages with the indicated reaction.
142
+ # help: SmartBot user and user adding the share need to be members on both channels.
143
+ # help: The Regexp will automatically add the parameters /im
144
+ # help: Only available on public channels.
145
+ # help: Examples:
146
+ # help: _share messages /(last\s+|previous\s+)sales\s+results\s+/ on #sales_
147
+ # help: _share messages "share post" on #announcements_
148
+ # xhelp: _share messages :tada: on #announcements_
149
+ # xhelp: _share messages :moneybag: from #sales_
150
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#share-messages|more info>
151
+ # help: command_id: :share_messages
152
+ # help:
153
+ when /\A\s*share\s+messages\s+(\/.+\/|".+"|'.+')\s+on\s+<#\w+\|(.+)>\s*\z/i,
154
+ /\A\s*share\s+messages\s+(\/.+\/|".+"|'.+')\s+on\s+<#(\w+)\|>\s*\z/,
155
+ /\A\s*share\s+messages\s+(\/.+\/|".+"|'.+')\s+on\s+(.+)\s*\z/i
156
+ condition = $1
157
+ channel = $2
158
+ channel.gsub!('#','') # for the case the channel name is in plain text including #
159
+ channel = @channels_name[channel] if @channels_name.key?(channel)
160
+ channel_from = @channels_name[dest]
161
+ channel_to = channel
162
+ share_messages(user, channel_from, channel_to, condition)
163
+
164
+ # help: ----------------------------------------------
165
+ # help: `see shares`
166
+ # help: It will display the active shares from this channel.
167
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#share-messages|more info>
168
+ # help: command_id: :see_shares
169
+ # help:
170
+ when /\A\s*see\s+shares\s*\z/i
171
+ see_shares()
172
+
173
+ # help: ----------------------------------------------
174
+ # help: `delete share ID`
175
+ # help: It will delete the share id specified.
176
+ # help: Examples:
177
+ # help: _delete share 24_
178
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#share-messages|more info>
179
+ # help: command_id: :delete_share
180
+ # help:
181
+ when /\A\s*(delete|remove)\s+share\s+(\d+)\s*\z/i
182
+ share_id = $2
183
+ delete_share(user, share_id)
184
+
185
+ # help: ----------------------------------------------
186
+ # help: `see statuses`
187
+ # help: `see statuses #CHANNEL`
188
+ # help: `see status EMOJI`
189
+ # help: `see status EMOJI #CHANNEL`
190
+ # help: `see status EMOJI1 EMOJI99`
191
+ # help: `who is on vacation?`
192
+ # help: `who is on EMOJI`
193
+ # help: `who is on EMOJI #CHANNEL`
194
+ # help: `who is on EMOJI1 EMOJI99`
195
+ # help: `who is not on vacation?`
196
+ # help: `who is not on EMOJI`
197
+ # help: `who is available?`
198
+ # help: It will display the current statuses of the members of the channel where you are calling the command or on the channel you supply.
199
+ # help: In case of `who is available?` will show members of the channel that are on line and not on a meeting or vacation or sick.
200
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#see-statuses|more info>
201
+ # help: command_id: :see_statuses
202
+ # help:
203
+ when /\A\s*(see|get)\s+(statuses)()\s*\z/i,
204
+ /\A\s*(see\s+status|get\s+status|who\s+is\s+on|who\s+are\s+on|who\s+is\s+not\s+on|who\s+are\s+not\s+on)\s+(:[\w\-\:\s]+:)\s*\??()\s*\z/i,
205
+ /\A\s*(who\s+is\s+on|who\s+are\s+on|who\s+is\s+not\s+on|who\s+are\s+not\s+on)\s+(vacation|holiday)\s*\??()\s*\z/i,
206
+ /\A\s*(who\s+is|who\s+are)\s+(available|active)\s*\??()\s*\z/i,
207
+ /\A\s*(see|get)\s+(statuses)\s+#([\w\-]+)\s*\z/i,
208
+ /\A\s*(see\s+status|get\s+status|who\s+is\s+on|who\s+are\s+on|who\s+is\s+not\s+on|who\s+are\s+not\s+on)\s+(:[\w\-\:\s]+:)\s*\??\s+#([\w\-]+)\s*\z/i,
209
+ /\A\s*(who\s+is|who\s+are)\s+(available|active)\s*\??\s+#([\w\-]+)\s*\z/i,
210
+ /\A\s*(who\s+is|who\s+are)\s+(available|active)\s*\??\s+<#(\w+)\|.*>\s*\z/i,
211
+ /\A\s*(who\s+is\s+on|who\s+are\s+on|who\s+is\s+not\s+on|who\s+are\s+not\s+on)\s+(vacation|holiday)\s*\??\s+#([\w\-]+)\s*\z/i,
212
+ /\A\s*(see|get)\s+(statuses)\s+<#(\w+)\|.*>\s*\z/i,
213
+ /\A\s*(see\s+status|get\s+status|who\s+is\s+on|who\s+is\s+not\s+on|who\s+are\s+on|who\s+are\s+not\s+on)\s+(:[\w\-\:\s]+:)\s*\??\s+<#(\w+)\|.*>\s*\z/i,
214
+ /\A\s*(who\s+is\s+on|who\s+is\s+not\s+on|who\s+are\s+on|who\s+are\s+not\s+on)\s+(vacation|holiday)\s*\??\s+<#(\w+)\|.*>\s*\z/i
215
+
216
+ not_on = $1.match?(/who\s+(is|are)\s+not\s+on/i)
217
+ type = $2.downcase
218
+ channel = $3.to_s
219
+ if type == 'statuses'
220
+ types = []
221
+ elsif type =='vacation' or type == 'holiday'
222
+ types = [':palm_tree:']
223
+ elsif type == 'available' or type == 'active'
224
+ types = ['available']
225
+ else
226
+ type.gsub!(' ', '')
227
+ type.gsub!('::',': :')
228
+ types = type.split(' ')
229
+ end
230
+ see_statuses(user, channel, types, dest, not_on)
231
+
232
+
233
+ # help: ----------------------------------------------
234
+ # help: `see favorite commands`
235
+ # help: `see my favorite commands`
236
+ # help: `favorite commands`
237
+ # help: `my favorite commands`
238
+ # help: It will display the favorite commands.
239
+ # help: aliases for favorite: favourite, most used, fav
240
+ # helpmaster: You need to set stats to true to generate the stats when running the bot instance and get this info.
241
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#see-favorite-commands|more info>
242
+ # help: command_id: :see_favorite_commands
243
+ # help:
244
+ when /\A\s*(see\s+)?(my\s+)?(fav|favorite|favourite|most\s+used)\s+commands\s*\z/i
245
+ only_mine = $2.to_s!=''
246
+ see_favorite_commands(user, only_mine)
247
+
248
+ # helpadmin: ----------------------------------------------
249
+ # helpadmin: `add admin @user`
250
+ # helpadmin: It will add @user as an admin of the channel.
251
+ # helpadmin: Only creator of the channel, admins and master admins can use this command.
252
+ # helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#bot-management|more info>
253
+ # helpadmin: command_id: :add_admin
254
+ # helpadmin:
255
+ when /\A\s*add\s+admin\s+<@(\w+)>\s*\z/i
256
+ admin_user = $1
257
+ add_admin(user, admin_user)
258
+
259
+ # help: ----------------------------------------------
260
+ # help: `see admins`
261
+ # help: `show admins`
262
+ # help: `who are admins?`
263
+ # help: It will show who are the admins of the channel.
264
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#bot-management|more info>
265
+ # help: command_id: :see_admins
266
+ # help:
267
+ when /\A\s*(see|show)\s+admins\s*\z/i, /\A\s*who\s+are\s+(the\s+)?admins\??\s*\z/i
268
+ see_admins()
269
+
270
+ # helpadmin: ----------------------------------------------
271
+ # helpadmin: `remove admin @user`
272
+ # helpadmin: It will remove the admin privileges for @user on the channel.
273
+ # helpadmin: Only creator of the channel, admins and master admins can use this command.
274
+ # helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#bot-management|more info>
275
+ # helpadmin: command_id: :remove_admin
276
+ # helpadmin:
277
+ when /\A\s*(remove|delete)\s+admin\s+<@(\w+)>\s*\z/i
278
+ admin_user = $2
279
+ remove_admin(user, admin_user)
280
+
281
+ # helpadmin: ----------------------------------------------
282
+ # helpadmin: `see command ids`
283
+ # helpadmin: It will display all available command ids.
284
+ # helpadmin: The command id can be used on `bot stats command COMMAND_ID`, `allow access COMMAND_ID` and `deny access COMMAND_ID`
285
+ # helpadmin: Only creator of the channel, admins and master admins can use this command.
286
+ # helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#bot-management|more info>
287
+ # helpadmin: command_id: :see_command_ids
288
+ # helpadmin:
289
+ when /\A\s*(see|display|get)\s+command(\s+|_)ids?\s*\z/i
290
+ see_command_ids()
291
+
292
+ # helpadmin: ----------------------------------------------
293
+ # helpadmin: `allow access COMMAND_ID`
294
+ # helpadmin: `allow access COMMAND_ID @user1 @user99`
295
+ # helpadmin: It will allow the specified command to be used on the channel.
296
+ # helpadmin: If @user specified, only those users will have access to the command.
297
+ # helpadmin: Only admins of the channel can use this command
298
+ # helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#control-who-has-access-to-a-command|more info>
299
+ # helpadmin: command_id: :allow_access
300
+ # helpadmin:
301
+ when /\A\s*(allow|give)\s+access\s+(\w+)\s+(.+)\s*\z/i, /\A\s*(allow|give)\s+access\s+(\w+)()\s*\z/i
302
+ command_id = $2.downcase
303
+ opt = $3.to_s.split(' ')
304
+ allow_access(user, command_id, opt)
305
+
306
+ # helpadmin: ----------------------------------------------
307
+ # helpadmin: `deny access COMMAND_ID`
308
+ # helpadmin: It won't allow the specified command to be used on the channel.
309
+ # helpadmin: Only admins of the channel can use this command
310
+ # helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#control-who-has-access-to-a-command|more info>
311
+ # helpadmin: command_id: :deny_access
312
+ # helpadmin:
313
+ when /\A\s*deny\s+access(\s+rights)?\s+(\w+)\s*\z/i
314
+ command_id = $2.downcase
315
+ deny_access(user, command_id)
316
+
317
+
318
+ # help: ----------------------------------------------
319
+ # help: `see access COMMAND_ID`
320
+ # help: It will show the access rights for the specified command.
321
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#control-who-has-access-to-a-command|more info>
322
+ # help: command_id: :see_access
323
+ # help:
324
+ when /\A\s*(see|show)\s+access(\s+rights)?\s+(.+)\s*\z/i
325
+ command_id = $3.downcase
326
+ see_access(command_id)
327
+
328
+ # help: ----------------------------------------------
329
+ # help: `poster MESSAGE`
330
+ # help: `poster :EMOTICON_TEXT: MESSAGE`
331
+ # help: `poster :EMOTICON_TEXT: :EMOTICON_BACKGROUND: MESSAGE`
332
+ # help: `poster MINUTESm MESSAGE`
333
+ # help: It will create a poster with the message supplied. By default will be autodeleted 1 minute later.
334
+ # help: If you want the poster to be permanent then use the command `pposter`
335
+ # help: If minutes supplied then it will be deleted after the minutes specified. Maximum value 60.
336
+ # help: To see the messages on a mobile phone put the phone on landscape mode
337
+ # help: Max 15 characters. If the message is longer than that won't be treat it.
338
+ # help: Only letters from a to z, 0 to 9 and the chars: ? ! - + =
339
+ # help: To be displayed correctly use words with no more than 6 characters
340
+ # help: Examples:
341
+ # help: _poster nice work!_
342
+ # help: _poster :heart: nice work!_
343
+ # help: _poster :mac-spinning-wheel: :look: love!_
344
+ # help: _poster 25m :heart: woah!_
345
+ # help: command_id: :poster
346
+ # help:
347
+ when /\A()poster\s+(\d+m\s+)?(:[^:]+:)\s+(:[^:]+:)(.+)\s*\z/i, /\A()poster\s+(\d+m\s+)?(:.+:)\s+()(.+)\s*\z/i, /\A()poster\s+(\d+m\s+)?()()(.+)\s*\z/i,
348
+ /\A(p)poster\s+()(:[^:]+:)\s+(:[^:]+:)(.+)\s*\z/i, /\A(p)poster\s+()(:.+:)\s+()(.+)\s*\z/i, /\A(p)poster\s+()()()(.+)\s*\z/i
349
+ permanent = $1.to_s != ''
350
+ minutes = $2.to_s
351
+ emoticon_text = $3
352
+ emoticon_bg = $4
353
+ text = $5
354
+ minutes = minutes.scan(/(\d+)/).join
355
+
356
+ if minutes == ''
357
+ minutes = 1
358
+ elsif minutes.to_i > 60
359
+ minutes = 60
360
+ end
361
+
362
+ save_stats :poster
363
+ if text.to_s.gsub(/\s+/, '').length > 15
364
+ respond "Too long. Max 15 chars", :on_thread
365
+ else
366
+ poster(permanent, emoticon_text, emoticon_bg, text, minutes)
367
+ end
368
+
369
+ # help: ----------------------------------------------
370
+ # help: `add team TEAM_NAME members #TEAM_CHANNEL CHANNEL_TYPE #CHANNEL1 #CHANNEL99 : INFO`
371
+ # help: `add team TEAM_NAME MEMBER_TYPE @USER1 @USER99 CHANNEL_TYPE #CHANNEL1 #CHANNEL99 : INFO`
372
+ # help: `add team TEAM_NAME MEMBER_TYPE1 @USER1 @USER99 MEMBER_TYPE99 @USER1 @USER99 CHANNEL_TYPE1 #CHANNEL1 #CHANNEL99 CHANNEL_TYPE99 #CHANNEL1 #CHANNEL99 : INFO`
373
+ # help: It will add a team with the info supplied.
374
+ # help: TEAM_NAME, TYPE: one word, a-z, A-Z, 0-9, - and _
375
+ # help: In case it is supplied a channel with type 'members' the members of that channel would be considered members of the team. The SmartBot needs to be a member of the channel.
376
+ # help: Examples:
377
+ # help: _add team sales members #sales support #sales-support public #sales-ff : Contact us if you need anything related to Sales. You can also send us an email at sales@ffxaja.com_
378
+ # help: _add team Sales manager @ann qa @peter @berglind dev @john @sam @marta members #sales support #sales-support public #sales-ff : Contact us if you need anything related to Sales. You can also send us an email at sales@ffxaja.com_
379
+ # help: _add team devweb qa @jim dev @johnja @cooke @luisa members #devweb support #devweb-support : We take care of the website_
380
+ # help: _add team sandex manager @sarah members #sandex : We take care of the sand_
381
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#teams|more info>
382
+ # help: command_id: :add_team
383
+ # help:
384
+ when /\A\s*add\s+team\s+([\w\-]+)\s+([^:]+)\s*:\s+(.+)\s*\z/im, /\A\s*add\s+([\w\-]+)\s+team\s+([^:]+)\s*:\s+(.+)\s*\z/im
385
+ name = $1.downcase
386
+ options = $2
387
+ info = Thread.current[:command_orig].to_s.gsub("\u00A0", " ").scan(/^[^:]+:\s*(.+)\s*$/im).join
388
+ add_team(user, name, options, info)
389
+
390
+ # help: ----------------------------------------------
391
+ # help: `see teams`
392
+ # help: `see team TEAM_NAME`
393
+ # help: `team TEAM_NAME`
394
+ # help: `TEAM_NAME team`
395
+ # help: `which team @USER`
396
+ # help: `which team #CHANNEL`
397
+ # help: `which team TEXT_TO_SEARCH_ON_INFO`
398
+ # help: `which team does @USER belongs to?`
399
+ # help: It will display all teams or the team specified.
400
+ # help: In case a specific team it will show also the availability of the members.
401
+ # help: Examples:
402
+ # help: _see teams_
403
+ # help: _see team Sales_
404
+ # help: _Dev team_
405
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#teams|more info>
406
+ # help: command_id: :see_teams
407
+ # help:
408
+ when /\A\s*see\s+teams?\s*([\w\-]+)?\s*\z/i, /\A\s*team\s+([\w\-]+)\s*\z/i, /\A\s*([\w\-]+)\s+team\s*\z/i, /\A\s*see\s+all\s+teams\s*()\z/i
409
+ name = $1.to_s.downcase
410
+ see_teams(user, name)
411
+ when /\A\s*(which|search)\s+teams?\s+(is\s+)?(.+)\??\s*\z/i, /\A\s*which\s+team\s+does\s+()()(.+)\s+belongs\s+to\??\s*\z/i
412
+ search = $3.to_s.downcase
413
+ see_teams(user, '', search)
414
+
415
+ # help: ----------------------------------------------
416
+ # help: `update team TEAM_NAME NEW_TEAM_NAME`
417
+ # help: `update team TEAM_NAME : NEW_INFO`
418
+ # help: `update team TEAM_NAME add MEMBER_TYPE @USER`
419
+ # help: `update team TEAM_NAME add CHANNEL_TYPE #CHANNEL`
420
+ # help: `update team TEAM_NAME delete MEMBER_TYPE @USER`
421
+ # help: `update team TEAM_NAME delete CHANNEL_TYPE #CHANNEL`
422
+ # help: `update team TEAM_NAME delete @USER`
423
+ # help: `update team TEAM_NAME delete #CHANNEL`
424
+ # help: It will update a team with the info supplied.
425
+ # help: You have to be a member of the team, the creator or a Master admin to be able to update a team.
426
+ # help: Examples:
427
+ # help: _update team sales salesff_
428
+ # help: _update team salesff : Support for customers_
429
+ # help: _update sales team delete @sarah @peter_
430
+ # help: _update team sales delete public #sales_
431
+ # help: _update team sales delete #sales_support_
432
+ # help: _update sales team add public #salesff_
433
+ # help: _update sales team add qa @john @ben @ana_
434
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#teams|more info>
435
+ # help: command_id: :update_team
436
+ # help:
437
+ when /\A\s*update\s+team\s+([\w\-]+)\s+([\w\-]+)\s*\z/i, /\A\s*update\s+([\w\-]+)\s+team\s+([\w\-]+)\s*\z/i
438
+ name = $1.downcase
439
+ new_name = $2.downcase
440
+ update_team(user, name, new_name: new_name)
441
+ when /\A\s*update\s+team\s+([\w\-]+)\s*:\s+(.+)\s*\z/im, /\A\s*update\s+([\w\-]+)\s+team\s*:\s+(.+)\s*\z/im
442
+ name = $1.downcase
443
+ new_info = Thread.current[:command_orig].to_s.gsub("\u00A0", " ").scan(/^[^:]+:\s*(.+)\s*$/im).join
444
+ update_team(user, name, new_info: new_info)
445
+ when /\A\s*update\s+team\s+([\w\-]+)\s+(delete|remove)\s+(.+)\s*\z/i, /\A\s*update\s+([\w\-]+)\s+team\s+(delete|remove)\s+(.+)\s*\z/i
446
+ name = $1.downcase
447
+ delete_opts = $3
448
+ update_team(user, name, delete_opts: delete_opts)
449
+ when /\A\s*update\s+team\s+([\w\-]+)\s+add\s+(.+)\s*\z/i, /\A\s*update\s+([\w\-]+)\s+team\s+add\s+(.+)\s*\z/i
450
+ name = $1.downcase
451
+ add_opts = $2
452
+ update_team(user, name, add_opts: add_opts)
453
+
454
+ # help: ----------------------------------------------
455
+ # help: `ping team TEAM_NAME MEMBER_TYPE MESSAGE`
456
+ # help: `contact team TEAM_NAME MEMBER_TYPE MESSAGE`
457
+ # help: ping: It will send the MESSAGE naming all available members of the MEMBER_TYPE supplied.
458
+ # help: contact: It will send the MESSAGE naming all members of the MEMBER_TYPE supplied.
459
+ # help: In case MEMBER_TYPE is 'all' it will name 10 random members of the team
460
+ # help: Examples:
461
+ # help: _ping team sales development How is the status on the last feature_
462
+ # help: _contact team sales qa Please finish testing of dev02 feature before noon_
463
+ # help: _contact team qa all Check the test failures please_
464
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#teams|more info>
465
+ # help: command_id: :ping_team
466
+ # help: command_id: :contact_team
467
+ # help:
468
+ when /\A\s*(contact|ping)\s+team\s+([\w\-]+)\s+([\w\-]+)\s+(.+)\s*\z/im, /\A\s*(contact|ping)\s+([\w\-]+)\s+team\s+([\w\-]+)\s+(.+)\s*\z/im
469
+ type = $1.downcase.to_sym
470
+ name = $2.downcase
471
+ member_type = $3.downcase
472
+ message = Thread.current[:command_orig].to_s.gsub("\u00A0", " ").scan(/\A\s*[^\s]+\s*\w+\s+team\s+[\w\-]+\s+[\w\-]+\s+(.+)\s*\z/im).join
473
+ if message == ''
474
+ message = Thread.current[:command_orig].to_s.gsub("\u00A0", " ").scan(/\A\s*[^\s]+\s*\w+\s+[\w\-]+\s+team\s+[\w\-]+\s+(.+)\s*\z/im).join
475
+ end
476
+ ping_team(user, type, name, member_type, message)
477
+
478
+ # help: ----------------------------------------------
479
+ # help: `delete team TEAM_NAME`
480
+ # help: It will delete the supplied team.
481
+ # help: You have to be a member of the team, the creator or a Master admin to be able to delete a team.
482
+ # help: Examples:
483
+ # help: _delete team sales_
484
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#teams|more info>
485
+ # help: command_id: :delete_team
486
+ # help:
487
+ when /\A\s*(delete|remove)\s+team\s+([\w\-]+)\s*\z/i, /\A\s*(delete|remove)\s+([\w\-]+)\s+team\s*\z/i
488
+ name = $2.downcase
489
+ delete_team(user, name)
490
+
491
+ else
492
+ return false
493
+ end
494
+ return true
495
+ rescue => exception
496
+ if defined?(@logger)
497
+ @logger.fatal exception
498
+ respond "Unexpected error!! Please contact an admin to solve it: <@#{config.admins.join(">, <@")}>"
499
+ else
500
+ puts exception
501
+ end
502
+ return false
503
+ end
504
+ end
@@ -18,16 +18,14 @@ class SlackSmartBot
18
18
  # help: _sc spanish account_
19
19
  # help: _shortcut Spanish Account_
20
20
  # help: _Spanish Account_
21
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#shortcuts|more info>
22
+ # help: command_id: :add_shortcut
21
23
  # help:
22
24
  def add_shortcut(dest, user, typem, for_all, shortcut_name, command, command_to_run, global)
23
25
  save_stats(__method__)
24
26
  unless typem == :on_extended
25
27
  from = user.name
26
- if config[:allow_access].key?(__method__) and !config[:allow_access][__method__].include?(user.name) and !config[:allow_access][__method__].include?(user.id) and
27
- (!user.key?(:enterprise_user) or ( user.key?(:enterprise_user) and !config[:allow_access][__method__].include?(user[:enterprise_user].id)))
28
- respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
29
- else
30
-
28
+ if has_access?(__method__, user)
31
29
  if global
32
30
  if !config.on_master_bot or typem != :on_master
33
31
  respond "It is only possible to add global shortcuts from Master channel"
@@ -66,7 +64,7 @@ class SlackSmartBot
66
64
  end
67
65
  }
68
66
  end
69
- if !config.admins.include?(from) and @shortcuts[:all].include?(shortcut_name) and !@shortcuts[from].include?(shortcut_name)
67
+ if !is_admin?(from) and @shortcuts[:all].include?(shortcut_name) and !@shortcuts[from].include?(shortcut_name)
70
68
  respond "Only the creator of the shortcut can modify it", dest
71
69
  elsif found_other
72
70
  respond "You cannot create a shortcut for all with the same name than other user is using", dest
@@ -3,7 +3,9 @@ class SlackSmartBot
3
3
  # helpadmin: `add routine NAME every NUMBER PERIOD COMMAND`
4
4
  # helpadmin: `add routine NAME every NUMBER PERIOD #CHANNEL COMMAND`
5
5
  # helpadmin: `add routine NAME every NUMBER PERIOD`
6
+ # helpadmin: `add bgroutine NAME every NUMBER PERIOD`
6
7
  # helpadmin: `add silent routine NAME every NUMBER PERIOD`
8
+ # helpadmin: `add silent bgroutine NAME every NUMBER PERIOD`
7
9
  # helpadmin: `create routine NAME every NUMBER PERIOD`
8
10
  # helpadmin: `add routine NAME at TIME COMMAND`
9
11
  # helpadmin: `add routine NAME at TIME #CHANNEL COMMAND`
@@ -14,26 +16,31 @@ class SlackSmartBot
14
16
  # helpadmin: `create routine NAME at TIME`
15
17
  # helpadmin: It will execute the command/rule supplied. Only for Admin and Master Admins.
16
18
  # helpadmin: If no COMMAND supplied, then it will be necessary to attach a file with the code to be run and add this command as message to the file. ONLY for MASTER ADMINS.
19
+ # helpadmin: In case *bgroutine* then the results of the run won't be published. To see the results call: `see result routine NAME`
17
20
  # helpadmin: In case *silent* provided then when executed will be only displayed if the routine returns a message
18
21
  # helpadmin: NAME: one word to identify the routine
19
22
  # helpadmin: NUMBER: Integer
20
23
  # helpadmin: PERIOD: days, d, hours, h, minutes, mins, min, m, seconds, secs, sec, s
21
24
  # helpadmin: TIME: time at format HH:MM:SS
22
- # helpadmin: DAYWEEK: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. And their plurals.
25
+ # helpadmin: DAYWEEK: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. And their plurals. Also possible to be used 'weekdays' and 'weekends'
23
26
  # helpadmin: #CHANNEL: the destination channel where the results will be published. If not supplied then the bot channel by default or a DM if the command is run from a DM.
24
27
  # helpadmin: COMMAND: any valid smart bot command or rule
28
+ # helpadmin: It is possible to add a script directly. Only master admins can do it.
25
29
  # helpadmin: Examples:
26
- # helpadmin: _add routine example every 30s ruby puts 'a'_
27
- # helpadmin: _add routine example every 3 days ruby puts 'a'_
28
- # helpadmin: _add routine example at 17:05 ruby puts 'a'_
30
+ # helpadmin: _add routine example every 30s !ruby puts 'a'_
31
+ # helpadmin: _add bgroutine example every 3 days !ruby puts 'a'_
32
+ # helpadmin: _add routine example at 17:05 !ruby puts 'a'_
29
33
  # helpadmin: _create silent routine Example every 12 hours !Run customer tests_
30
- # helpadmin: _add routine example on Mondays at 05:00 !run customer tests_
34
+ # helpadmin: _add bgroutine example on Mondays at 05:00 !run customer tests_
31
35
  # helpadmin: _add routine example on Tuesdays at 09:00 #SREChannel !run db cleanup_
36
+ # helpadmin: _add routine example on weekdays at 22:00 suggest command_
37
+ # helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#routines|more info>
38
+ # helpadmin: command_id: :add_routine
32
39
  # helpadmin:
33
- def add_routine(dest, from, user, name, type, number_time, period, command_to_run, files, silent, channel)
40
+ def add_routine(dest, from, user, name, type, number_time, period, command_to_run, files, silent, channel, routine_type)
34
41
  save_stats(__method__)
35
42
  if files.nil? or files.size == 0 or (files.size > 0 and config.masters.include?(from))
36
- if config.admins.include?(from)
43
+ if is_admin?
37
44
  if @routines.key?(@channel_id) && @routines[@channel_id].key?(name)
38
45
  respond "I'm sorry but there is already a routine with that name.\nCall `see routines` to see added routines", dest
39
46
  else
@@ -61,8 +68,9 @@ class SlackSmartBot
61
68
  every = "#{number_time} seconds"
62
69
  every_in_seconds = number_time.to_i
63
70
  else # time
64
- if type != 'at'
71
+ if type != 'at' and type!='weekday' and type!='weekend'
65
72
  dayweek = type.downcase
73
+
66
74
  days = ['sunday','monday','tuesday','wednesday','thursday','friday','saturday']
67
75
  incr = days.index(dayweek) - Time.now.wday
68
76
  if incr < 0
@@ -72,6 +80,14 @@ class SlackSmartBot
72
80
  end
73
81
  days = incr/(24*60*60)
74
82
  every_in_seconds = 7 * 24 * 60 * 60 # one week
83
+ elsif type=='weekend'
84
+ dayweek = type.downcase
85
+ days = 0
86
+ every_in_seconds = 24 * 60 * 60 # one day
87
+ elsif type=='weekday'
88
+ dayweek = type.downcase
89
+ days = 0
90
+ every_in_seconds = 24 * 60 * 60 # one day
75
91
  else
76
92
  days = 0
77
93
  every_in_seconds = 24 * 60 * 60 # one day
@@ -95,20 +111,35 @@ class SlackSmartBot
95
111
  if files[0].filetype == "ruby" and files[0].name.scan(/[^\.]+(\.\w+$)/).join == ''
96
112
  file_path += ".rb"
97
113
  end
98
- http = NiceHttp.new(host: "https://files.slack.com", headers: { "Authorization" => "Bearer #{config[:token]}" }, log_headers: :partial)
99
- http.get(files[0].url_private_download, save_data: file_path)
114
+ if files[0].key?(:content)
115
+ File.open(file_path, 'w') do |f|
116
+ f.write files[0].content
117
+ end
118
+ else
119
+ http = NiceHttp.new(host: "https://files.slack.com", headers: { "Authorization" => "Bearer #{config[:token]}" }, log_headers: :partial)
120
+ http.get(files[0].url_private_download, save_data: file_path)
121
+ end
100
122
  system("chmod +x #{file_path}")
101
123
  end
102
- channel = dest if channel.to_s == ''
124
+ get_channels_name_and_id() unless @channels_name.keys.include?(channel) or @channels_id.keys.include?(channel)
125
+ channel_id = nil
126
+ if @channels_name.key?(channel) #it is an id
127
+ channel_id = channel
128
+ channel = @channels_name[channel_id]
129
+ elsif @channels_id.key?(channel) #it is a channel name
130
+ channel_id = @channels_id[channel]
131
+ end
132
+
133
+ channel_id = dest if channel_id.to_s == ''
103
134
  @routines[@channel_id] = {} unless @routines.key?(@channel_id)
104
135
  @routines[@channel_id][name] = { channel_name: config.channel, creator: from, creator_id: user.id, status: :on,
105
136
  every: every, every_in_seconds: every_in_seconds, at: at, dayweek: dayweek, file_path: file_path,
106
137
  command: command_to_run.to_s.strip, silent: silent,
107
- next_run: next_run.to_s, dest: channel, last_run: "", last_elapsed: "",
108
- running: false }
138
+ next_run: next_run.to_s, dest: channel_id, last_run: "", last_elapsed: "",
139
+ running: false, routine_type: routine_type}
109
140
  update_routines
110
141
  respond "Added routine *`#{name}`* to the channel", dest
111
- create_routine_thread(name)
142
+ create_routine_thread(name, @routines[@channel_id][name])
112
143
  end
113
144
  end
114
145
  else