@@ -11,29 +11,19 @@ def self.call(client, data, match)
1111 expression . gsub! '—' , '--'
1212 logger . info "SLACK: #{ client . owner } - #{ expression } "
1313 args , pipe = Shellwords . parse ( expression )
14- execute ( client , args ) do |output , error |
15- if error && !error . blank?
16- client . say ( channel : data . channel , text : "```\n #{ error } ```" )
17- else
18- output = pipe ? JsonPath . on ( output , pipe ) : JSON . parse ( output )
19- output = JSON . pretty_generate ( output )
20- client . say ( channel : data . channel , text : "```\n #{ output } ```" )
21- end
14+ output , error , _ = Open3 . capture3 ( * [ 'slack' , '--slack-api-token' , client . owner . token , args ] . flatten )
15+ error &.strip!
16+ output &.strip!
17+ if error && !error . blank?
18+ client . say ( channel : data . channel , text : "```\n #{ error } ```" )
19+ else
20+ output = pipe ? JsonPath . on ( output , pipe ) : JSON . parse ( output )
21+ output = JSON . pretty_generate ( output )
22+ client . say ( channel : data . channel , text : "```\n #{ output } ```" )
2223 end
2324 rescue SyntaxError => e
2425 client . say ( channel : data . channel , text : e . message )
2526 end
26-
27- def self . execute ( client , args )
28- Open3 . popen3 ( * [
29- 'slack' ,
30- '--slack-api-token' ,
31- client . owner . token ,
32- args
33- ] . flatten ) do |_ , stdout , stderr , _ |
34- yield stdout . read &.strip , stderr . read &.strip
35- end
36- end
3727 end
3828 end
3929end
0 commit comments