discorb 0.19.0 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build_version.yml +2 -2
- data/.rubocop.yml +12 -75
- data/Changelog.md +10 -0
- data/Rakefile +482 -454
- data/lib/discorb/allowed_mentions.rb +68 -72
- data/lib/discorb/app_command/command.rb +466 -398
- data/lib/discorb/app_command/common.rb +65 -25
- data/lib/discorb/app_command/handler.rb +304 -266
- data/lib/discorb/app_command.rb +5 -5
- data/lib/discorb/application.rb +198 -197
- data/lib/discorb/asset.rb +101 -101
- data/lib/discorb/attachment.rb +134 -119
- data/lib/discorb/audit_logs.rb +412 -385
- data/lib/discorb/automod.rb +279 -269
- data/lib/discorb/channel/base.rb +107 -108
- data/lib/discorb/channel/category.rb +32 -32
- data/lib/discorb/channel/container.rb +44 -44
- data/lib/discorb/channel/dm.rb +26 -28
- data/lib/discorb/channel/guild.rb +311 -246
- data/lib/discorb/channel/stage.rb +156 -140
- data/lib/discorb/channel/text.rb +430 -336
- data/lib/discorb/channel/thread.rb +374 -325
- data/lib/discorb/channel/voice.rb +85 -79
- data/lib/discorb/channel.rb +5 -5
- data/lib/discorb/client.rb +635 -621
- data/lib/discorb/color.rb +178 -182
- data/lib/discorb/common.rb +168 -164
- data/lib/discorb/components/button.rb +107 -106
- data/lib/discorb/components/select_menu.rb +157 -145
- data/lib/discorb/components/text_input.rb +103 -106
- data/lib/discorb/components.rb +68 -66
- data/lib/discorb/dictionary.rb +135 -135
- data/lib/discorb/embed.rb +404 -398
- data/lib/discorb/emoji.rb +309 -302
- data/lib/discorb/emoji_table.rb +16099 -8857
- data/lib/discorb/error.rb +131 -131
- data/lib/discorb/event.rb +360 -314
- data/lib/discorb/event_handler.rb +39 -39
- data/lib/discorb/exe/about.rb +17 -17
- data/lib/discorb/exe/irb.rb +72 -67
- data/lib/discorb/exe/new.rb +323 -315
- data/lib/discorb/exe/run.rb +69 -68
- data/lib/discorb/exe/setup.rb +57 -55
- data/lib/discorb/exe/show.rb +12 -12
- data/lib/discorb/extend.rb +25 -45
- data/lib/discorb/extension.rb +89 -83
- data/lib/discorb/flag.rb +126 -128
- data/lib/discorb/gateway.rb +984 -804
- data/lib/discorb/gateway_events.rb +670 -638
- data/lib/discorb/gateway_requests.rb +45 -48
- data/lib/discorb/guild.rb +2115 -1626
- data/lib/discorb/guild_template.rb +280 -241
- data/lib/discorb/http.rb +247 -232
- data/lib/discorb/image.rb +42 -42
- data/lib/discorb/integration.rb +169 -161
- data/lib/discorb/intents.rb +161 -163
- data/lib/discorb/interaction/autocomplete.rb +76 -62
- data/lib/discorb/interaction/command.rb +279 -224
- data/lib/discorb/interaction/components.rb +114 -104
- data/lib/discorb/interaction/modal.rb +36 -32
- data/lib/discorb/interaction/response.rb +379 -336
- data/lib/discorb/interaction/root.rb +271 -257
- data/lib/discorb/interaction.rb +5 -5
- data/lib/discorb/invite.rb +154 -153
- data/lib/discorb/member.rb +344 -311
- data/lib/discorb/message.rb +615 -544
- data/lib/discorb/message_meta.rb +197 -186
- data/lib/discorb/modules.rb +371 -290
- data/lib/discorb/permission.rb +305 -291
- data/lib/discorb/presence.rb +352 -346
- data/lib/discorb/rate_limit.rb +81 -76
- data/lib/discorb/reaction.rb +55 -54
- data/lib/discorb/role.rb +272 -240
- data/lib/discorb/shard.rb +76 -74
- data/lib/discorb/sticker.rb +193 -171
- data/lib/discorb/user.rb +205 -188
- data/lib/discorb/utils/colored_puts.rb +16 -16
- data/lib/discorb/utils.rb +12 -16
- data/lib/discorb/voice_state.rb +305 -281
- data/lib/discorb/webhook.rb +537 -507
- data/lib/discorb.rb +62 -56
- data/sig/discorb/application.rbs +2 -0
- data/sig/discorb/automod.rbs +10 -1
- data/sig/discorb/guild.rbs +2 -0
- data/sig/discorb/message.rbs +2 -0
- data/sig/discorb/user.rbs +22 -20
- metadata +2 -2
data/lib/discorb/error.rb
CHANGED
@@ -1,131 +1,131 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Discorb
|
4
|
-
#
|
5
|
-
# Error class for Discorb.
|
6
|
-
# @abstract
|
7
|
-
#
|
8
|
-
class DiscorbError < StandardError
|
9
|
-
private
|
10
|
-
|
11
|
-
def enumerate_errors(hash)
|
12
|
-
res = {}
|
13
|
-
_recr_items([], hash, res)
|
14
|
-
res = {} if res == { "" => nil }
|
15
|
-
res
|
16
|
-
end
|
17
|
-
|
18
|
-
def _recr_items(key, item, res)
|
19
|
-
case item
|
20
|
-
when Array
|
21
|
-
item.each_with_index
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
#
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
#
|
78
|
-
# Represents a 401 error.
|
79
|
-
#
|
80
|
-
class UnauthorizedError < HTTPError
|
81
|
-
end
|
82
|
-
|
83
|
-
#
|
84
|
-
# Represents a 403 error.
|
85
|
-
#
|
86
|
-
class ForbiddenError < HTTPError
|
87
|
-
end
|
88
|
-
|
89
|
-
#
|
90
|
-
# Represents a 404 error.
|
91
|
-
#
|
92
|
-
class NotFoundError < HTTPError
|
93
|
-
end
|
94
|
-
|
95
|
-
#
|
96
|
-
# Represents a error because of a cloudflare ban.
|
97
|
-
#
|
98
|
-
class CloudFlareBanError < HTTPError
|
99
|
-
def initialize(_resp, client)
|
100
|
-
@client = client
|
101
|
-
@client.close!
|
102
|
-
message = <<~MESSAGE
|
103
|
-
The client is banned from CloudFlare.
|
104
|
-
Hint: Try to decrease the number of requests per second, e.g. Use sleep in between requests.
|
105
|
-
MESSAGE
|
106
|
-
warn message
|
107
|
-
DiscorbError.instance_method(:initialize).bind(self).call(message)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
#
|
112
|
-
# Represents a error in client-side.
|
113
|
-
#
|
114
|
-
class ClientError < DiscorbError
|
115
|
-
end
|
116
|
-
|
117
|
-
#
|
118
|
-
# Represents a timeout error.
|
119
|
-
#
|
120
|
-
class TimeoutError < DiscorbError
|
121
|
-
end
|
122
|
-
|
123
|
-
#
|
124
|
-
# Represents a warning.
|
125
|
-
#
|
126
|
-
class NotSupportedWarning < DiscorbError
|
127
|
-
def initialize(message)
|
128
|
-
super("#{message} is not supported yet.")
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discorb
|
4
|
+
#
|
5
|
+
# Error class for Discorb.
|
6
|
+
# @abstract
|
7
|
+
#
|
8
|
+
class DiscorbError < StandardError
|
9
|
+
private
|
10
|
+
|
11
|
+
def enumerate_errors(hash)
|
12
|
+
res = {}
|
13
|
+
_recr_items([], hash, res)
|
14
|
+
res = {} if res == { "" => nil }
|
15
|
+
res
|
16
|
+
end
|
17
|
+
|
18
|
+
def _recr_items(key, item, res)
|
19
|
+
case item
|
20
|
+
when Array
|
21
|
+
item.each_with_index { |v, i| _recr_items (key + [i]), v, res }
|
22
|
+
when Hash
|
23
|
+
item.each { |k, v| _recr_items (key + [k]), v, res }
|
24
|
+
else
|
25
|
+
res[key.join(".").gsub("_errors.", "")] = item
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# Represents a HTTP error.
|
32
|
+
# @abstract
|
33
|
+
#
|
34
|
+
class HTTPError < DiscorbError
|
35
|
+
# @return [String] the JSON response code.
|
36
|
+
# @see https://discord.com/developers/docs/topics/opcodes-and-status-codes#json-json-error-codes
|
37
|
+
attr_reader :code
|
38
|
+
# @return [Net::HTTPResponse] the HTTP response.
|
39
|
+
attr_reader :response
|
40
|
+
|
41
|
+
#
|
42
|
+
# Initialize a new instance of the HTTPError class.
|
43
|
+
# @private
|
44
|
+
#
|
45
|
+
def initialize(resp, data)
|
46
|
+
@code = data[:code]
|
47
|
+
@response = resp
|
48
|
+
super(data[:message] + " (#{@code})")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# Represents a 400 error.
|
54
|
+
#
|
55
|
+
class BadRequestError < HTTPError
|
56
|
+
#
|
57
|
+
# Initialize a new instance of the BadRequestError class.
|
58
|
+
# @private
|
59
|
+
#
|
60
|
+
def initialize(resp, data)
|
61
|
+
@code = data[:code]
|
62
|
+
@response = resp
|
63
|
+
DiscorbError
|
64
|
+
.instance_method(:initialize)
|
65
|
+
.bind(self)
|
66
|
+
.call(
|
67
|
+
[
|
68
|
+
data[:message] + " (#{@code})",
|
69
|
+
enumerate_errors(data[:errors])
|
70
|
+
.map { |ek, ev| "#{ek}=>#{ev}" }
|
71
|
+
.join("\n")
|
72
|
+
].join("\n")
|
73
|
+
)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
#
|
78
|
+
# Represents a 401 error.
|
79
|
+
#
|
80
|
+
class UnauthorizedError < HTTPError
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
# Represents a 403 error.
|
85
|
+
#
|
86
|
+
class ForbiddenError < HTTPError
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# Represents a 404 error.
|
91
|
+
#
|
92
|
+
class NotFoundError < HTTPError
|
93
|
+
end
|
94
|
+
|
95
|
+
#
|
96
|
+
# Represents a error because of a cloudflare ban.
|
97
|
+
#
|
98
|
+
class CloudFlareBanError < HTTPError
|
99
|
+
def initialize(_resp, client)
|
100
|
+
@client = client
|
101
|
+
@client.close!
|
102
|
+
message = <<~MESSAGE
|
103
|
+
The client is banned from CloudFlare.
|
104
|
+
Hint: Try to decrease the number of requests per second, e.g. Use sleep in between requests.
|
105
|
+
MESSAGE
|
106
|
+
warn message
|
107
|
+
DiscorbError.instance_method(:initialize).bind(self).call(message)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
#
|
112
|
+
# Represents a error in client-side.
|
113
|
+
#
|
114
|
+
class ClientError < DiscorbError
|
115
|
+
end
|
116
|
+
|
117
|
+
#
|
118
|
+
# Represents a timeout error.
|
119
|
+
#
|
120
|
+
class TimeoutError < DiscorbError
|
121
|
+
end
|
122
|
+
|
123
|
+
#
|
124
|
+
# Represents a warning.
|
125
|
+
#
|
126
|
+
class NotSupportedWarning < DiscorbError
|
127
|
+
def initialize(message)
|
128
|
+
super("#{message} is not supported yet.")
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|