slack-smart-bot 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9dd7ec5a931f45aeef862b601c89dd869edfb317e5e05f47fd997f3c48af0b0f
4
- data.tar.gz: b6c6171727919ba7f8200d9ff14f299e19a1d0b07c62263759758ed88ba4f14e
3
+ metadata.gz: e8df140b707c4449949790ee4aec06123d702f7e504d9181d17ab28ce4907d50
4
+ data.tar.gz: cb3b7b350309de0f3597f1349138f1532324377ee51b0340a5d95478a7ef10ef
5
5
  SHA512:
6
- metadata.gz: 82fded753140cd4b5f1635ed3a22f6f5c156b57e7d93d9b45a1f8f643d8ed92acb5a6c83aabfb005feb753cc73c05e9d6de1c481532f26a851e21ccdb22aa30f
7
- data.tar.gz: b81648ea8b9ff046d0a379941acbc6db78823bb1d5c2b3d95a57ed11b77c8a5ada4f398c443cefcf7251dc0ba348c1eebddcab784dddceb74f70b105300641cb
6
+ metadata.gz: 945db84827a120c3cd07c301f15f0de822628060d65ac75d4856f97f19e2af8640a4fe9c7c6290541e2541d89fd6794e90e03170e229f16a2d0fcc6e150632e0
7
+ data.tar.gz: de406836aeb262ef22fc468add1a7dc8a0bdd02f2003e94d28e5965f22333a0d6d87bf11efc1062604a83b4ba776aec2ac98616a6d04e2f1d5bffc4da2ff73d8
data/README.md CHANGED
@@ -71,21 +71,21 @@ def rules(user, command, processed, dest)
71
71
  # help: `echo SOMETHING`
72
72
  # help: repeats SOMETHING
73
73
  # help:
74
- when /echo\s(.+)/i
74
+ when /^echo\s(.+)/i
75
75
  respond $1
76
76
 
77
77
  # help: `go to sleep`
78
78
  # help: it will sleep the bot for 10 seconds
79
79
  # help:
80
- when /go\sto\ssleep/i
80
+ when /^go\sto\ssleep/i
81
81
  unless @questions.keys.include?(from)
82
82
  ask("do you want me to take a siesta?", command, from)
83
83
  else
84
84
  case @questions[from]
85
85
  when /yes/i, /yep/i, /sure/i
86
86
  @questions.delete(from)
87
- respond "zZzzzzzZZZZZZzzzzzzz!"
88
87
  respond "I'll be sleeping for 10 secs... just for you"
88
+ respond "zZzzzzzZZZZZZzzzzzzz!"
89
89
  sleep 10
90
90
  when /no/i, /nope/i, /cancel/i
91
91
  @questions.delete(from)
@@ -95,6 +95,27 @@ def rules(user, command, processed, dest)
95
95
  ask("are you sure do you want me to sleep? (yes or no)", "go to sleep", from)
96
96
  end
97
97
  end
98
+
99
+ # help: ----------------------------------------------
100
+ # help: `run something`
101
+ # help: It will run the process and report the results when done
102
+ # help:
103
+ when /^run something/i
104
+ respond "Running", dest
105
+
106
+ process_to_run = "ruby -v"
107
+ process_to_run = ("cd #{project_folder} &&" + process_to_run) if defined?(project_folder)
108
+ stdout, stderr, status = Open3.capture3(process_to_run)
109
+ if stderr == ""
110
+ if stdout == ""
111
+ respond "#{user.name}: Nothing returned.", dest
112
+ else
113
+ respond "#{user.name}: #{stdout}", dest
114
+ end
115
+ else
116
+ respond "#{user.name}: #{stderr}", dest
117
+ end
118
+
98
119
  else
99
120
  unless processed
100
121
  resp = %w{ what huh sorry }.sample
@@ -1,5 +1,5 @@
1
1
  require "slack-ruby-client"
2
- require 'async'
2
+ require "async"
3
3
  require "open-uri"
4
4
  require "cgi"
5
5
  require "json"
@@ -194,13 +194,13 @@ class SlackSmartBot
194
194
  ((data.text[0] == "`" and data.text[-1] == "`") or (data.text[0] == "*" and data.text[-1] == "*") or (data.text[0] == "_" and data.text[-1] == "_"))
195
195
  data.text = data.text[1..-2]
196
196
  end
197
- if !data.files.nil? and data.files.size == 1 and
198
- (data.text.match?(/^(ruby|code)\s*$/) or (data.text.match?(/^\s*$/) and data.files[0].filetype=='ruby') or
199
- (data.text.match?(/^<@#{config[:nick_id]}>\s(on\s)?<#(\w+)\|(.+)>/im) and data.files[0].filetype=='ruby'))
200
- res=Faraday.new('https://files.slack.com', headers: { "Authorization" => "Bearer #{config[:token]}" }).get(data.files[0].url_private)
197
+ if !data.files.nil? and data.files.size == 1 and
198
+ (data.text.match?(/^(ruby|code)\s*$/) or (data.text.match?(/^\s*$/) and data.files[0].filetype == "ruby") or
199
+ (data.text.match?(/^<@#{config[:nick_id]}>\s(on\s)?<#(\w+)\|(.+)>/im) and data.files[0].filetype == "ruby"))
200
+ res = Faraday.new("https://files.slack.com", headers: { "Authorization" => "Bearer #{config[:token]}" }).get(data.files[0].url_private)
201
201
  data.text = "#{data.text} ruby #{res.body.to_s}"
202
202
  end
203
-
203
+
204
204
  if data.text.match(/^<@#{config[:nick_id]}>\s(on\s)?<#(\w+)\|(.+)>\s*:?\s*(.+)/im)
205
205
  channel_rules = $2
206
206
  channel_rules_name = $3
@@ -209,7 +209,7 @@ class SlackSmartBot
209
209
  ((command[0] == "`" and command[-1] == "`") or (command[0] == "*" and command[-1] == "*") or (command[0] == "_" and command[-1] == "_"))
210
210
  command = command[1..-2]
211
211
  end
212
-
212
+
213
213
  command = "!" + command unless command[0] == "!"
214
214
 
215
215
  if @channels_id[CHANNEL] == channel_rules #to be treated only on the bot of the requested channel
@@ -251,7 +251,7 @@ class SlackSmartBot
251
251
 
252
252
  def process_first(user, text, dest, dchannel)
253
253
  nick = user.name
254
- rules_file = ''
254
+ rules_file = ""
255
255
 
256
256
  if dest[0] == "C" or dest[0] == "G" # on a channel or private channel
257
257
  rules_file = RULES_FILE
@@ -355,13 +355,12 @@ class SlackSmartBot
355
355
  @logger.info "command: #{nick}> #{command}" unless processed
356
356
  #todo: verify this
357
357
 
358
-
359
358
  if dest[0] == "C" or dest[0] == "G" #only for channels, not for DM
360
359
  if @rules_imported.key?(user.id) and @rules_imported[user.id].key?(dchannel)
361
360
  if @bots_created.key?(@rules_imported[user.id][dchannel])
362
361
  if @bots_created[@rules_imported[user.id][dchannel]][:status] != :on
363
362
  respond "The bot on that channel is not :on", dest
364
- rules_file = ''
363
+ rules_file = ""
365
364
  end
366
365
  end
367
366
  end
@@ -391,7 +390,7 @@ class SlackSmartBot
391
390
  end
392
391
  else
393
392
  respond "The bot on <##{@rules_imported[user.id][user.id]}|#{@bots_created[@rules_imported[user.id][user.id]][:channel_name]}> is not :on", dest
394
- rules_file = ''
393
+ rules_file = ""
395
394
  end
396
395
  end
397
396
 
@@ -998,15 +997,15 @@ class SlackSmartBot
998
997
  code.gsub!("\\r", "\r")
999
998
  @logger.info code
1000
999
  unless code.match?(/System/i) or code.match?(/Kernel/i) or code.include?("File") or
1001
- code.include?("`") or code.include?("exec") or code.include?("spawn") or code.include?("IO.") or
1002
- code.match?(/open3/i) or code.match?(/bundle/i) or code.match?(/gemfile/i) or code.include?("%x") or
1003
- code.include?("ENV") or code.match?(/=\s*IO/)
1000
+ code.include?("`") or code.include?("exec") or code.include?("spawn") or code.include?("IO.") or
1001
+ code.match?(/open3/i) or code.match?(/bundle/i) or code.match?(/gemfile/i) or code.include?("%x") or
1002
+ code.include?("ENV") or code.match?(/=\s*IO/)
1004
1003
  unless rules_file.empty?
1005
1004
  begin
1006
1005
  eval(File.new(rules_file).read) if File.exist?(rules_file)
1007
1006
  end
1008
1007
  end
1009
-
1008
+
1010
1009
  respond "Running", dest if code.size > 100
1011
1010
 
1012
1011
  begin
@@ -1091,7 +1090,7 @@ class SlackSmartBot
1091
1090
  end
1092
1091
 
1093
1092
  #to send a file to an user or channel
1094
- def send_file(to, msg, file, title, format, type='text')
1093
+ def send_file(to, msg, file, title, format, type = "text")
1095
1094
  if to[0] == "U" #user
1096
1095
  im = client.web_client.im_open(user: to)
1097
1096
  channel = im["channel"]["id"]
@@ -61,8 +61,8 @@ def rules(user, command, processed, dest)
61
61
  case @questions[from]
62
62
  when /yes/i, /yep/i, /sure/i
63
63
  @questions.delete(from)
64
- respond "zZzzzzzZZZZZZzzzzzzz!", dest
65
64
  respond "I'll be sleeping for 5 secs... just for you", dest
65
+ respond "zZzzzzzZZZZZZzzzzzzz!", dest
66
66
  sleep 5
67
67
  when /no/i, /nope/i, /cancel/i
68
68
  @questions.delete(from)
@@ -72,6 +72,26 @@ def rules(user, command, processed, dest)
72
72
  ask("are you sure do you want me to sleep? (yes or no)", "go to sleep", from, dest)
73
73
  end
74
74
  end
75
+
76
+ # help: ----------------------------------------------
77
+ # help: `run something`
78
+ # help: It will run the process and report the results when done
79
+ # help:
80
+ when /^run something/i
81
+ respond "Running", dest
82
+
83
+ process_to_run = "ruby -v"
84
+ process_to_run = ("cd #{project_folder} &&" + process_to_run) if defined?(project_folder)
85
+ stdout, stderr, status = Open3.capture3(process_to_run)
86
+ if stderr == ""
87
+ if stdout == ""
88
+ respond "#{user.name}: Nothing returned.", dest
89
+ else
90
+ respond "#{user.name}: #{stdout}", dest
91
+ end
92
+ else
93
+ respond "#{user.name}: #{stderr}", dest
94
+ end
75
95
  else
76
96
  unless processed
77
97
  resp = %w{ what huh sorry }.sample
@@ -83,7 +103,7 @@ end
83
103
  #for the case of testing just running this file, write the dialogue in here:
84
104
  if @testing
85
105
  require "nice_hash"
86
- user = { name: "Peter Johson", id: "Uxxxxxx" }
106
+ user = { name: "Peter Johnson", id: "Uxxxxxx" }
87
107
 
88
108
  rules user, "go to sleep, you look tired", false, nil
89
109
  rules user, "yes", false, nil
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-smart-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-07 00:00:00.000000000 Z
11
+ date: 2019-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slack-ruby-client