cksh_commander 0.2.2 → 0.2.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f98c333fb1994d93150486351c05fac07578f1b1
4
- data.tar.gz: 587802b3cb82c7bf0da152b10d5a25d836f7d1b1
3
+ metadata.gz: 43245e06eb2f0aaa72365542ce09253981d5456b
4
+ data.tar.gz: da64aaf628c17d06d9932f1f137fbf18d57ec227
5
5
  SHA512:
6
- metadata.gz: 63295c5c7b1c4107287cac3ffb856f23828bef9be29fb45f6e4369091e192bad95bf15bb04efc4e5b38da4cce7be3ca1b3040d9b8f5ada096147da693f6c871a
7
- data.tar.gz: bbbfe5fc04d24897757a5ef04f382e837fdbb631481d95d181621195f0cad60192471254b0318178c6677e701ed4073dd17ed11ae873eea453fad90fea43b34d
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
- @authorized = ids.any? { |id| @data.user_id == id }
110
- unless @authorized
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 = cmd && cmd.debugging? ? e.message :
17
- cmd ? cmd.error_message : "Command not found..."
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
 
@@ -1,3 +1,3 @@
1
1
  module CKSHCommander
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cksh_commander
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Loncar