slack-smart-bot 1.3.1 → 1.4.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 (32) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -4
  3. data/lib/slack-smart-bot.rb +5 -11
  4. data/lib/slack/smart-bot/comm.rb +7 -253
  5. data/lib/slack/smart-bot/comm/ask.rb +48 -0
  6. data/lib/slack/smart-bot/comm/dont_understand.rb +61 -0
  7. data/lib/slack/smart-bot/comm/respond.rb +51 -0
  8. data/lib/slack/smart-bot/comm/respond_direct.rb +6 -0
  9. data/lib/slack/smart-bot/comm/send_file.rb +25 -0
  10. data/lib/slack/smart-bot/comm/send_msg_channel.rb +30 -0
  11. data/lib/slack/smart-bot/comm/send_msg_user.rb +37 -0
  12. data/lib/slack/smart-bot/commands.rb +25 -0
  13. data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +1 -0
  14. data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +1 -0
  15. data/lib/slack/smart-bot/listen.rb +1 -2
  16. data/lib/slack/smart-bot/process.rb +0 -26
  17. data/lib/slack/smart-bot/process_first.rb +0 -1
  18. data/lib/slack/smart-bot/treat_message.rb +16 -1
  19. data/lib/slack/smart-bot/utils.rb +12 -337
  20. data/lib/slack/smart-bot/utils/build_help.rb +15 -0
  21. data/lib/slack/smart-bot/utils/create_routine_thread.rb +86 -0
  22. data/lib/slack/smart-bot/utils/get_bots_created.rb +24 -0
  23. data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +21 -0
  24. data/lib/slack/smart-bot/utils/get_help.rb +131 -0
  25. data/lib/slack/smart-bot/utils/get_routines.rb +11 -0
  26. data/lib/slack/smart-bot/utils/get_rules_imported.rb +15 -0
  27. data/lib/slack/smart-bot/utils/remove_hash_keys.rb +17 -0
  28. data/lib/slack/smart-bot/utils/update_bots_file.rb +11 -0
  29. data/lib/slack/smart-bot/utils/update_routines.rb +16 -0
  30. data/lib/slack/smart-bot/utils/update_rules_imported.rb +8 -0
  31. data/lib/slack/smart-bot/utils/update_shortcuts_file.rb +7 -0
  32. metadata +29 -10
@@ -0,0 +1,6 @@
1
+ class SlackSmartBot
2
+ def respond_direct(msg)
3
+ dest = Thread.current[:user].id
4
+ respond(msg, dest)
5
+ end
6
+ end
@@ -0,0 +1,25 @@
1
+ class SlackSmartBot
2
+
3
+ #to send a file to an user or channel
4
+ #send_file(dest, 'the message', "#{project_folder}/temp/logs_ptBI.log", 'message to be sent', 'text/plain', "text")
5
+ #send_file(dest, 'the message', "#{project_folder}/temp/example.jpeg", 'message to be sent', 'image/jpeg', "jpg")
6
+ def send_file(to, msg, file, title, format, type = "text")
7
+ if to[0] == "U" #user
8
+ im = client.web_client.im_open(user: to)
9
+ channel = im["channel"]["id"]
10
+ else
11
+ channel = to
12
+ end
13
+
14
+ client.web_client.files_upload(
15
+ channels: channel,
16
+ as_user: true,
17
+ file: Faraday::UploadIO.new(file, format),
18
+ title: title,
19
+ filename: file,
20
+ filetype: type,
21
+ initial_comment: msg,
22
+ )
23
+ end
24
+
25
+ end
@@ -0,0 +1,30 @@
1
+ class SlackSmartBot
2
+
3
+ # to: (String) Channel name or id
4
+ # msg: (String) message to send
5
+ def send_msg_channel(to, msg)
6
+ unless msg == ""
7
+ get_channels_name_and_id() unless @channels_name.key?(to) or @channels_id.key?(to)
8
+ if @channels_name.key?(to) #it is an id
9
+ channel_id = to
10
+ elsif @channels_id.key?(to) #it is a channel name
11
+ channel_id = @channels_id[to]
12
+ else
13
+ @logger.fatal "Channel: #{to} not found. Message: #{msg}"
14
+ end
15
+ if config[:simulate]
16
+ open("#{config.path}/buffer_complete.log", "a") { |f|
17
+ f.puts "|#{channel_id}|#{config[:nick_id]}|#{msg}~~~"
18
+ }
19
+ else
20
+ client.message(channel: channel_id, text: msg, as_user: true)
21
+ end
22
+ if config[:testing] and config.on_master_bot
23
+ open("#{config.path}/buffer.log", "a") { |f|
24
+ f.puts "|#{channel_id}|#{config[:nick_id]}|#{msg}"
25
+ }
26
+ end
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,37 @@
1
+ class SlackSmartBot
2
+
3
+ #to send messages without listening for a response to users
4
+ def send_msg_user(id_user, msg)
5
+ unless msg == ""
6
+ if id_user[0] == "D"
7
+ if config[:simulate]
8
+ open("#{config.path}/buffer_complete.log", "a") { |f|
9
+ f.puts "|#{id_user}|#{config[:nick_id]}|#{msg}~~~"
10
+ }
11
+ else
12
+ client.message(channel: id_user, as_user: true, text: msg)
13
+ end
14
+ if config[:testing] and config.on_master_bot
15
+ open("#{config.path}/buffer.log", "a") { |f|
16
+ f.puts "|#{id_user}|#{config[:nick_id]}|#{msg}"
17
+ }
18
+ end
19
+ else
20
+ im = client.web_client.im_open(user: id_user)
21
+ if config[:simulate]
22
+ open("#{config.path}/buffer_complete.log", "a") { |f|
23
+ f.puts "|#{im["channel"]["id"]}|#{config[:nick_id]}|#{msg}~~~"
24
+ }
25
+ else
26
+ client.message(channel: im["channel"]["id"], as_user: true, text: msg)
27
+ end
28
+ if config[:testing] and config.on_master_bot
29
+ open("#{config.path}/buffer.log", "a") { |f|
30
+ f.puts "|#{im["channel"]["id"]}|#{config[:nick_id]}|#{msg}"
31
+ }
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,25 @@
1
+ require_relative "commands/general/hi_bot"
2
+ require_relative "commands/general/bye_bot"
3
+ require_relative "commands/general/bot_help"
4
+ require_relative "commands/on_bot/ruby_code"
5
+ require_relative "commands/general/use_rules"
6
+ require_relative "commands/general/stop_using_rules"
7
+ require_relative "commands/on_master/admin_master/exit_bot"
8
+ require_relative "commands/on_master/admin_master/notify_message"
9
+ require_relative "commands/on_master/admin/kill_bot_on_channel"
10
+ require_relative "commands/on_master/create_bot"
11
+ require_relative "commands/on_bot/admin/add_routine"
12
+ require_relative "commands/on_bot/admin/start_bot"
13
+ require_relative "commands/on_bot/admin/pause_bot"
14
+ require_relative "commands/on_bot/admin/remove_routine"
15
+ require_relative "commands/on_bot/admin/run_routine"
16
+ require_relative "commands/on_bot/admin/pause_routine"
17
+ require_relative "commands/on_bot/admin/start_routine"
18
+ require_relative "commands/on_bot/admin/see_routines"
19
+ require_relative "commands/on_bot/admin/extend_rules"
20
+ require_relative "commands/on_bot/admin/stop_using_rules_on"
21
+ require_relative "commands/general/bot_status"
22
+ require_relative "commands/on_bot/add_shortcut"
23
+ require_relative "commands/on_bot/delete_shortcut"
24
+ require_relative "commands/on_bot/see_shortcuts"
25
+ require_relative "commands/on_extended/bot_rules"
@@ -11,6 +11,7 @@ class SlackSmartBot
11
11
  respond "This bot is paused from now on. You can start it again: start this bot", dest
12
12
  respond "zZzzzzZzzzzZZZZZZzzzzzzzz", dest
13
13
  @status = :paused
14
+ @bots_created[@channel_id][:status] = :paused
14
15
  unless config.on_master_bot
15
16
  send_msg_channel config.master_channel, "Changed status on #{config.channel} to :paused"
16
17
  end
@@ -10,6 +10,7 @@ class SlackSmartBot
10
10
  if config.admins.include?(from) #admin user
11
11
  respond "This bot is running and listening from now on. You can pause again: pause this bot", dest
12
12
  @status = :on
13
+ @bots_created[@channel_id][:status] = :on
13
14
  unless config.on_master_bot
14
15
  send_msg_channel config.master_channel, "Changed status on #{config.channel} to :on"
15
16
  end
@@ -5,7 +5,7 @@ class SlackSmartBot
5
5
  get_bots_created()
6
6
  @buffer_complete = [] unless defined?(@buffer_complete)
7
7
  b = File.read("#{config.path}/buffer_complete.log")
8
- result = b.scan(/^\|(\w+)\|(\w+)\|([^$]+)\$\$\$/m)
8
+ result = b.scan(/^\|(\w+)\|(\w+)\|([^~]+)~~~/m)
9
9
  result.delete(nil)
10
10
  new_messages = result[@buffer_complete.size..-1]
11
11
  unless new_messages.nil? or new_messages.empty?
@@ -22,7 +22,6 @@ class SlackSmartBot
22
22
  end
23
23
 
24
24
  def listen
25
- @salutations = [config[:nick], "<@#{config[:nick_id]}>", "bot", "smart"]
26
25
  @pings = []
27
26
  get_bots_created()
28
27
 
@@ -1,29 +1,3 @@
1
- require_relative "commands/general/hi_bot"
2
- require_relative "commands/general/bye_bot"
3
- require_relative "commands/general/bot_help"
4
- require_relative "commands/on_bot/ruby_code"
5
- require_relative "commands/general/use_rules"
6
- require_relative "commands/general/stop_using_rules"
7
- require_relative "commands/on_master/admin_master/exit_bot"
8
- require_relative "commands/on_master/admin_master/notify_message"
9
- require_relative "commands/on_master/admin/kill_bot_on_channel"
10
- require_relative "commands/on_master/create_bot"
11
- require_relative "commands/on_bot/admin/add_routine"
12
- require_relative "commands/on_bot/admin/start_bot"
13
- require_relative "commands/on_bot/admin/pause_bot"
14
- require_relative "commands/on_bot/admin/remove_routine"
15
- require_relative "commands/on_bot/admin/run_routine"
16
- require_relative "commands/on_bot/admin/pause_routine"
17
- require_relative "commands/on_bot/admin/start_routine"
18
- require_relative "commands/on_bot/admin/see_routines"
19
- require_relative "commands/on_bot/admin/extend_rules"
20
- require_relative "commands/on_bot/admin/stop_using_rules_on"
21
- require_relative "commands/general/bot_status"
22
- require_relative "commands/on_bot/add_shortcut"
23
- require_relative "commands/on_bot/delete_shortcut"
24
- require_relative "commands/on_bot/see_shortcuts"
25
- require_relative "commands/on_extended/bot_rules"
26
-
27
1
  class SlackSmartBot
28
2
  def process(user, command, dest, dchannel, rules_file, typem, files)
29
3
  from = user.name
@@ -2,7 +2,6 @@ class SlackSmartBot
2
2
  def process_first(user, text, dest, dchannel, typem, files)
3
3
  nick = user.name
4
4
  rules_file = ""
5
-
6
5
  if typem == :on_call
7
6
  rules_file = config.rules_file
8
7
  elsif dest[0] == "C" or dest[0] == "G" # on a channel or private channel
@@ -71,7 +71,6 @@ class SlackSmartBot
71
71
  end
72
72
  end
73
73
  end
74
-
75
74
  unless typem == :dont_treat
76
75
  begin
77
76
  #todo: when changed @questions user_id then move user_info inside the ifs to avoid calling it when not necessary
@@ -146,6 +145,22 @@ class SlackSmartBot
146
145
  if !config.on_master_bot and !dest.nil? and (dest == @master_bot_id or dest[0] == "D") and
147
146
  data.text.match?(/^\s*bot\s+status\s*$/i) and @admin_users_id.include?(data.user)
148
147
  respond "ping from #{config.channel}", dest
148
+ elsif !config.on_master_bot and !dest.nil? and data.user == config[:nick_id] and dest == @master_bot_id
149
+ # to treat on other bots the status messages populated on master bot
150
+ case data.text
151
+ when /^Bot has been (closed|killed) by/i
152
+ sleep 2
153
+ get_bots_created()
154
+ when /^Changed status on (.+) to :(.+)/i
155
+ sleep 2
156
+ get_bots_created()
157
+ when /extended the rules from (.+) to be used on (.+)\.$/i
158
+ sleep 2
159
+ get_bots_created()
160
+ when /removed the access to the rules of (.+) from (.+)\.$/i
161
+ sleep 2
162
+ get_bots_created()
163
+ end
149
164
  end
150
165
  end
151
166
  end
@@ -1,337 +1,12 @@
1
- class SlackSmartBot
2
- def update_bots_file
3
- file = File.open(config.file_path.gsub(".rb", "_bots.rb"), "w")
4
- bots_created = @bots_created.dup
5
- bots_created.each { |k, v|
6
- v[:thread] = ""
7
- }
8
- file.write bots_created.inspect
9
- file.close
10
- end
11
-
12
- def get_bots_created
13
- if File.exist?(config.file_path.gsub(".rb", "_bots.rb"))
14
- if !defined?(@datetime_bots_created) or @datetime_bots_created != File.mtime(config.file_path.gsub(".rb", "_bots.rb"))
15
- file_conf = IO.readlines(config.file_path.gsub(".rb", "_bots.rb")).join
16
- if file_conf.to_s() == ""
17
- @bots_created = {}
18
- else
19
- @bots_created = eval(file_conf)
20
- end
21
- @datetime_bots_created = File.mtime(config.file_path.gsub(".rb", "_bots.rb"))
22
- @extended_from = {}
23
- @bots_created.each do |k, v|
24
- v[:extended] = [] unless v.key?(:extended)
25
- v[:extended].each do |ch|
26
- @extended_from[ch] = [] unless @extended_from.key?(ch)
27
- @extended_from[ch] << k
28
- end
29
- v[:rules_file].gsub!(/^\./, '')
30
- end
31
- end
32
- end
33
- end
34
-
35
- def update_shortcuts_file
36
- file = File.open("#{config.path}/shortcuts/#{config.shortcuts_file}", "w")
37
- file.write @shortcuts.inspect
38
- file.close
39
- end
40
-
41
- def get_rules_imported
42
- if File.exist?("#{config.path}/rules/rules_imported.rb")
43
- if !defined?(@datetime_rules_imported) or @datetime_rules_imported != File.mtime("#{config.path}/rules/rules_imported.rb")
44
- @datetime_rules_imported = File.mtime("#{config.path}/rules/rules_imported.rb")
45
- file_conf = IO.readlines("#{config.path}/rules/rules_imported.rb").join
46
- unless file_conf.to_s() == ""
47
- @rules_imported = eval(file_conf)
48
- end
49
- end
50
- end
51
- end
52
-
53
- def update_rules_imported
54
- file = File.open("#{config.path}/rules/rules_imported.rb", "w")
55
- file.write @rules_imported.inspect
56
- file.close
57
- end
58
-
59
- def get_channels_name_and_id
60
- #todo: add pagination for case more than 1000 channels on the workspace
61
- channels = client.web_client.conversations_list(
62
- types: "private_channel,public_channel",
63
- limit: "1000",
64
- exclude_archived: "true",
65
- ).channels
66
-
67
- @channels_id = Hash.new()
68
- @channels_name = Hash.new()
69
- channels.each do |ch|
70
- unless ch.is_archived
71
- @channels_id[ch.name] = ch.id
72
- @channels_name[ch.id] = ch.name
73
- end
74
- end
75
- end
76
-
77
- def get_routines(channel = @channel_id)
78
- if File.exist?("#{config.path}/routines/routines_#{channel}.rb")
79
- file_conf = IO.readlines("#{config.path}/routines/routines_#{channel}.rb").join
80
- unless file_conf.to_s() == ""
81
- @routines = eval(file_conf)
82
- end
83
- end
84
- end
85
-
86
- def update_routines(channel = @channel_id)
87
- routines = {}
88
- file = File.open("#{config.path}/routines/routines_#{channel}.rb", "w")
89
- @routines.each do |k,v|
90
- routines[k]={}
91
- v.each do |kk,vv|
92
- routines[k][kk] = vv.dup
93
- routines[k][kk][:thread]=""
94
- end
95
- end
96
- file.write (routines.inspect)
97
- file.close
98
- end
99
-
100
- def create_routine_thread(name)
101
- t = Thread.new do
102
- while @routines.key?(@channel_id) and @routines[@channel_id].key?(name)
103
- @routines[@channel_id][name][:thread] = Thread.current
104
- started = Time.now
105
- if @status == :on and @routines[@channel_id][name][:status] == :on
106
- @logger.info "Routine: #{@routines[@channel_id][name].inspect}"
107
- if @routines[@channel_id][name][:file_path].match?(/\.rb$/i)
108
- ruby = "ruby "
109
- else
110
- ruby = ""
111
- end
112
- @routines[@channel_id][name][:silent] = false if !@routines[@channel_id][name].key?(:silent)
113
-
114
- if @routines[@channel_id][name][:at] == "" or
115
- (@routines[@channel_id][name][:at] != "" and @routines[@channel_id][name][:running] and
116
- @routines[@channel_id][name][:next_run] != "" and Time.now.to_s >= @routines[@channel_id][name][:next_run])
117
- if @routines[@channel_id][name][:file_path] != ""
118
- process_to_run = "#{ruby}#{Dir.pwd}#{@routines[@channel_id][name][:file_path][1..-1]}"
119
- process_to_run = ("cd #{project_folder} &&" + process_to_run) if defined?(project_folder)
120
-
121
- stdout, stderr, status = Open3.capture3(process_to_run)
122
- if !@routines[@channel_id][name][:silent] or (@routines[@channel_id][name][:silent] and (stderr!='' or stdout!=''))
123
- respond "routine *`#{name}`*: #{@routines[@channel_id][name][:file_path]}", @routines[@channel_id][name][:dest]
124
- end
125
- if stderr == ""
126
- unless stdout.match?(/\A\s*\z/)
127
- respond stdout, @routines[@channel_id][name][:dest]
128
- end
129
- else
130
- respond "#{stdout} #{stderr}", @routines[@channel_id][name][:dest]
131
- end
132
- else #command
133
- if !@routines[@channel_id][name][:silent]
134
- respond "routine *`#{name}`*: #{@routines[@channel_id][name][:command]}", @routines[@channel_id][name][:dest]
135
- end
136
- started = Time.now
137
- data = { channel: @routines[@channel_id][name][:dest],
138
- user: @routines[@channel_id][name][:creator_id],
139
- text: @routines[@channel_id][name][:command],
140
- files: nil }
141
- treat_message(data)
142
- end
143
- # in case the routine was deleted while running the process
144
- if !@routines.key?(@channel_id) or !@routines[@channel_id].key?(name)
145
- Thread.exit
146
- end
147
- @routines[@channel_id][name][:last_run] = started.to_s
148
- end
149
- if @routines[@channel_id][name][:last_run] == "" and @routines[@channel_id][name][:next_run] != "" #for the first create_routine of one routine with at
150
- elapsed = 0
151
- require "time"
152
- every_in_seconds = Time.parse(@routines[@channel_id][name][:next_run]) - Time.now
153
- elsif @routines[@channel_id][name][:at] != "" #coming from start after pause for 'at'
154
- if started.strftime("%H:%M:%S") < @routines[@channel_id][name][:at]
155
- nt = @routines[@channel_id][name][:at].split(":")
156
- next_run = Time.new(started.year, started.month, started.day, nt[0], nt[1], nt[2])
157
- else
158
- next_run = started + (24 * 60 * 60) # one more day
159
- nt = @routines[@channel_id][name][:at].split(":")
160
- next_run = Time.new(next_run.year, next_run.month, next_run.day, nt[0], nt[1], nt[2])
161
- end
162
- @routines[@channel_id][name][:next_run] = next_run.to_s
163
- elapsed = 0
164
- every_in_seconds = next_run - started
165
- else
166
- every_in_seconds = @routines[@channel_id][name][:every_in_seconds]
167
- elapsed = Time.now - started
168
- @routines[@channel_id][name][:last_elapsed] = elapsed
169
- @routines[@channel_id][name][:next_run] = (started + every_in_seconds).to_s
170
- end
171
- @routines[@channel_id][name][:running] = true
172
- @routines[@channel_id][name][:sleeping] = (every_in_seconds - elapsed).ceil
173
- update_routines()
174
- sleep(@routines[@channel_id][name][:sleeping]) unless elapsed > every_in_seconds
175
- else
176
- sleep 30
177
- end
178
- end
179
- end
180
- end
181
-
182
- def build_help(path)
183
- help_message = {}
184
- Dir["#{path}/*"].each do |t|
185
- if Dir.exist?(t)
186
- help_message[t.scan(/\/(\w+)$/).join.to_sym] = build_help(t)
187
- else
188
- help_message[t.scan(/\/(\w+)\.rb$/).join.to_sym] = IO.readlines(t).join.scan(/#\s*help\s*\w*:(.*)/).join("\n")
189
- end
190
- end
191
- return help_message
192
- end
193
-
194
- def remove_hash_keys(hash, key)
195
- newh = Hash.new
196
- hash.each do |k, v|
197
- unless k == key
198
- if v.is_a?(String)
199
- newh[k] = v
200
- else
201
- newh[k] = remove_hash_keys(v, key)
202
- end
203
- end
204
- end
205
- return newh
206
- end
207
-
208
- def get_help(rules_file, dest, from, only_rules = false)
209
- order = {
210
- general: [:hi_bot, :bye_bot, :bot_help, :bot_status, :use_rules, :stop_using_rules],
211
- on_bot: [:ruby_code, :add_shortcut, :delete_shortcut, :see_shortcuts],
212
- on_bot_admin: [:extend_rules, :stop_using_rules_on, :start_bot, :pause_bot, :add_routine,
213
- :see_routines, :start_routine, :pause_routine, :remove_routine, :run_routine],
214
- }
215
- # user_type: :admin, :user, :admin_master
216
- if config.masters.include?(from)
217
- user_type = :admin_master
218
- elsif config.admins.include?(from)
219
- user_type = :admin
220
- else
221
- user_type = :user
222
- end
223
- # channel_type: :bot, :master_bot, :direct, :extended, :external
224
- if dest[0] == "D"
225
- channel_type = :direct
226
- elsif config.on_master_bot
227
- channel_type = :master_bot
228
- elsif @channel_id != dest
229
- channel_type = :extended
230
- else
231
- channel_type = :bot
232
- end
233
-
234
- @help_messages ||= build_help("#{__dir__}/commands")
235
- if only_rules
236
- help = {}
237
- else
238
- help = @help_messages.deep_copy
239
- end
240
- if rules_file != ""
241
- help[:rules_file] = IO.readlines(config.path+rules_file).join.scan(/#\s*help\s*\w*:(.*)/i).join("\n")
242
- end
243
-
244
- help = remove_hash_keys(help, :admin_master) unless user_type == :admin_master
245
- help = remove_hash_keys(help, :admin) unless user_type == :admin or user_type == :admin_master
246
- help = remove_hash_keys(help, :on_master) unless channel_type == :master_bot
247
- help = remove_hash_keys(help, :on_extended) unless channel_type == :extended
248
- help = remove_hash_keys(help, :on_dm) unless channel_type == :direct
249
- txt = ""
250
- if channel_type == :bot or channel_type == :master_bot
251
- txt += "===================================
252
- For the Smart Bot start listening to you say *hi bot*
253
- To run a command on demand even when the Smart Bot is not listening to you:
254
- *!THE_COMMAND*
255
- *@NAME_OF_BOT THE_COMMAND*
256
- *NAME_OF_BOT THE_COMMAND*\n"
257
- end
258
- if channel_type == :direct
259
- txt += "===================================
260
- When on a private conversation with the Smart Bot, I'm always listening to you.\n"
261
- end
262
- unless channel_type == :master_bot or channel_type == :extended
263
- txt += "===================================
264
- *Commands from Channels without a bot:*
265
- ----------------------------------------------
266
- `@BOT_NAME on #CHANNEL_NAME COMMAND`
267
- `@BOT_NAME #CHANNEL_NAME COMMAND`
268
- It will run the supplied command using the rules on the channel supplied.
269
- You need to join the specified channel to be able to use those rules.
270
- Also you can use this command to call another bot from a channel with a running bot.
271
-
272
- The commands you will be able to use from a channel without a bot:
273
- *bot rules*, *ruby CODE*, *add shortcut NAME: COMMAND*, *delete shortcut NAME*, *see shortcuts*, *shortcut NAME*
274
- *And all the specific rules of the Channel*\n"
275
- end
276
-
277
- if help.key?(:general)
278
- unless channel_type == :direct
279
- txt += "===================================
280
- *General commands even when the Smart Bot is not listening to you:*\n"
281
- end
282
- order.general.each do |o|
283
- txt += help.general[o]
284
- end
285
- if channel_type == :master_bot
286
- txt += help.on_master.create_bot
287
- end
288
- end
289
-
290
- if help.key?(:on_bot)
291
- unless channel_type == :direct
292
- txt += "===================================
293
- *General commands only when the Smart Bot is listening to you or on demand:*\n"
294
- end
295
- order.on_bot.each do |o|
296
- txt += help.on_bot[o]
297
- end
298
- end
299
-
300
- if help.key?(:on_bot) and help.on_bot.key?(:admin)
301
- txt += "===================================
302
- *Admin commands:*\n"
303
- txt += "\n\n"
304
- order.on_bot_admin.each do |o|
305
- txt += help.on_bot.admin[o]
306
- end
307
- if help.key?(:on_master) and help.on_master.key?(:admin)
308
- help.on_master.admin.each do |k, v|
309
- txt += v if v.is_a?(String)
310
- end
311
- end
312
- end
313
-
314
- if help.key?(:on_master) and help.on_master.key?(:admin_master)
315
- txt += "===================================
316
- *Master Admin commands:*\n"
317
- help.on_master.admin_master.each do |k, v|
318
- txt += v if v.is_a?(String)
319
- end
320
- end
321
-
322
- if help.key?(:on_bot) and help.on_bot.key?(:admin_master) and help.on_bot.admin_master.size > 0
323
- txt += "===================================
324
- *Master Admin commands:*\n"
325
- end
326
-
327
- if help.key?(:rules_file)
328
- @logger.info channel_type if config.testing
329
- if channel_type == :extended or channel_type == :direct
330
- @logger.info help.rules_file if config.testing
331
- help.rules_file = help.rules_file.gsub(/^\s*\*These are specific commands.+NAME_OF_BOT THE_COMMAND`\s*$/im, "")
332
- end
333
- txt += help.rules_file
334
- end
335
- return txt
336
- end
337
- end
1
+ require_relative 'utils/build_help'
2
+ require_relative 'utils/create_routine_thread'
3
+ require_relative 'utils/get_bots_created'
4
+ require_relative 'utils/get_channels_name_and_id'
5
+ require_relative 'utils/get_help'
6
+ require_relative 'utils/get_routines'
7
+ require_relative 'utils/get_rules_imported'
8
+ require_relative 'utils/remove_hash_keys'
9
+ require_relative 'utils/update_bots_file'
10
+ require_relative 'utils/update_routines'
11
+ require_relative 'utils/update_rules_imported'
12
+ require_relative 'utils/update_shortcuts_file'