cksh_commander 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cksh_commander/command.rb +4 -8
- data/lib/cksh_commander/runner.rb +7 -2
- data/lib/cksh_commander/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43245e06eb2f0aaa72365542ce09253981d5456b
|
4
|
+
data.tar.gz: da64aaf628c17d06d9932f1f137fbf18d57ec227
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acf265dbe3c0b3897b2bb2ad926a495ac140bc62c8731440b4ab0f572b71c1bab9b4e9218776ef4643168d0ff31a42cbae1b8015785a7217017c829aa8bc8e26
|
7
|
+
data.tar.gz: a5319c02db85c07b0c5c828ca9d72d312361dbd59c36782ad82e06e07e8ac5ff6c42245a70c09742cbb296d33d6f70207a4413a8df7b87423d3913ba8b75282d
|
@@ -24,7 +24,6 @@ module CKSHCommander
|
|
24
24
|
|
25
25
|
def initialize(data = nil)
|
26
26
|
@data = data
|
27
|
-
@authorized = true
|
28
27
|
@debugging = false
|
29
28
|
@response = Response.new
|
30
29
|
end
|
@@ -85,12 +84,10 @@ module CKSHCommander
|
|
85
84
|
end
|
86
85
|
|
87
86
|
def set_response_text(text)
|
88
|
-
return unless @authorized
|
89
87
|
@response.text = text
|
90
88
|
end
|
91
89
|
|
92
90
|
def add_response_attachment(attachment)
|
93
|
-
return unless @authorized
|
94
91
|
unless attachment.is_a?(Hash)
|
95
92
|
raise ArgumentError, "Attachment must be a Hash"
|
96
93
|
end
|
@@ -99,17 +96,14 @@ module CKSHCommander
|
|
99
96
|
end
|
100
97
|
|
101
98
|
def respond_in_channel!
|
102
|
-
return unless @authorized
|
103
99
|
@response.type = 'in_channel'
|
104
100
|
end
|
105
101
|
|
106
102
|
# Authorize users to use a subcommand by
|
107
103
|
# whitelisting user IDs.
|
108
104
|
def authorize(ids)
|
109
|
-
|
110
|
-
unless
|
111
|
-
@response = Response.new("You are unauthorized to use this subcommand!")
|
112
|
-
end
|
105
|
+
authorized = ids.any? { |id| @data.user_id == id }
|
106
|
+
raise UnauthorizedError unless authorized
|
113
107
|
end
|
114
108
|
|
115
109
|
def debug!
|
@@ -149,4 +143,6 @@ module CKSHCommander
|
|
149
143
|
output += "```"
|
150
144
|
end
|
151
145
|
end
|
146
|
+
|
147
|
+
class UnauthorizedError < StandardError; end
|
152
148
|
end
|
@@ -13,8 +13,13 @@ module CKSHCommander
|
|
13
13
|
|
14
14
|
response = cmd.authenticated? ? cmd.run : Response.new("Invalid token!")
|
15
15
|
rescue => e
|
16
|
-
text =
|
17
|
-
|
16
|
+
text = if e.is_a?(UnauthorizedError)
|
17
|
+
"You are unauthorized to use this subcommand!"
|
18
|
+
else
|
19
|
+
cmd && cmd.debugging? ? e.message :
|
20
|
+
cmd ? cmd.error_message : "Command not found..."
|
21
|
+
end
|
22
|
+
|
18
23
|
response = Response.new(text)
|
19
24
|
end
|
20
25
|
|