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/application.rb
CHANGED
@@ -1,197 +1,198 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Discorb
|
4
|
-
#
|
5
|
-
# Represents a Discord application.
|
6
|
-
#
|
7
|
-
class Application < DiscordModel
|
8
|
-
# @return [Discorb::Snowflake] The application's ID.
|
9
|
-
attr_reader :id
|
10
|
-
# @return [String] The application's name.
|
11
|
-
attr_reader :name
|
12
|
-
# @return [Discorb::Asset] The application's icon.
|
13
|
-
attr_reader :icon
|
14
|
-
# @return [String] The application's description.
|
15
|
-
attr_reader :description
|
16
|
-
# @return [String] The application's summary.
|
17
|
-
attr_reader :summary
|
18
|
-
# @return [String] The application's public key.
|
19
|
-
attr_reader :verify_key
|
20
|
-
# @return [Discorb::User] The application's owner.
|
21
|
-
attr_reader :owner
|
22
|
-
# @return [Discorb::Application::Team] The application's team.
|
23
|
-
attr_reader :team
|
24
|
-
# @return [Boolean] Whether the application's bot is public.
|
25
|
-
attr_reader :bot_public
|
26
|
-
alias bot_public? bot_public
|
27
|
-
# @return [Boolean] Whether the application's bot requires a code grant.
|
28
|
-
attr_reader :bot_require_code_grant
|
29
|
-
alias bot_require_code_grant? bot_require_code_grant
|
30
|
-
# @return [Discorb::Application::Flag] The application's flags.
|
31
|
-
attr_reader :flags
|
32
|
-
|
33
|
-
#
|
34
|
-
# Initializes a new instance of the Application class.
|
35
|
-
# @private
|
36
|
-
#
|
37
|
-
# @param [Discorb::Client] client The client that instantiated the object.
|
38
|
-
# @param [Hash] data The data of the object.
|
39
|
-
#
|
40
|
-
def initialize(client, data)
|
41
|
-
@client = client
|
42
|
-
@data = data
|
43
|
-
@id = Snowflake.new(data[:id])
|
44
|
-
@name = data[:name]
|
45
|
-
@icon = Asset.new(self, data[:icon])
|
46
|
-
@description = data[:description]
|
47
|
-
@summary = data[:summary]
|
48
|
-
@bot_public = data[:bot_public]
|
49
|
-
@bot_require_code_grant = data[:bot_require_code_grant]
|
50
|
-
@verify_key = data[:verify_key]
|
51
|
-
@owner =
|
52
|
-
|
53
|
-
@
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
# | `1 <<
|
72
|
-
# | `1 <<
|
73
|
-
# | `1 <<
|
74
|
-
# | `1 <<
|
75
|
-
# | `1 <<
|
76
|
-
# | `1 <<
|
77
|
-
# | `1 <<
|
78
|
-
#
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
#
|
108
|
-
|
109
|
-
|
110
|
-
#
|
111
|
-
#
|
112
|
-
# @
|
113
|
-
#
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
@
|
119
|
-
@
|
120
|
-
@
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
#
|
127
|
-
#
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
# @return [
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
#
|
152
|
-
|
153
|
-
|
154
|
-
#
|
155
|
-
#
|
156
|
-
#
|
157
|
-
|
158
|
-
#
|
159
|
-
#
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
}.freeze
|
164
|
-
|
165
|
-
def initialize(client, team, data)
|
166
|
-
@client = client
|
167
|
-
@data = data
|
168
|
-
@team = team
|
169
|
-
@user =
|
170
|
-
|
171
|
-
@
|
172
|
-
@
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discorb
|
4
|
+
#
|
5
|
+
# Represents a Discord application.
|
6
|
+
#
|
7
|
+
class Application < DiscordModel
|
8
|
+
# @return [Discorb::Snowflake] The application's ID.
|
9
|
+
attr_reader :id
|
10
|
+
# @return [String] The application's name.
|
11
|
+
attr_reader :name
|
12
|
+
# @return [Discorb::Asset] The application's icon.
|
13
|
+
attr_reader :icon
|
14
|
+
# @return [String] The application's description.
|
15
|
+
attr_reader :description
|
16
|
+
# @return [String] The application's summary.
|
17
|
+
attr_reader :summary
|
18
|
+
# @return [String] The application's public key.
|
19
|
+
attr_reader :verify_key
|
20
|
+
# @return [Discorb::User] The application's owner.
|
21
|
+
attr_reader :owner
|
22
|
+
# @return [Discorb::Application::Team] The application's team.
|
23
|
+
attr_reader :team
|
24
|
+
# @return [Boolean] Whether the application's bot is public.
|
25
|
+
attr_reader :bot_public
|
26
|
+
alias bot_public? bot_public
|
27
|
+
# @return [Boolean] Whether the application's bot requires a code grant.
|
28
|
+
attr_reader :bot_require_code_grant
|
29
|
+
alias bot_require_code_grant? bot_require_code_grant
|
30
|
+
# @return [Discorb::Application::Flag] The application's flags.
|
31
|
+
attr_reader :flags
|
32
|
+
|
33
|
+
#
|
34
|
+
# Initializes a new instance of the Application class.
|
35
|
+
# @private
|
36
|
+
#
|
37
|
+
# @param [Discorb::Client] client The client that instantiated the object.
|
38
|
+
# @param [Hash] data The data of the object.
|
39
|
+
#
|
40
|
+
def initialize(client, data)
|
41
|
+
@client = client
|
42
|
+
@data = data
|
43
|
+
@id = Snowflake.new(data[:id])
|
44
|
+
@name = data[:name]
|
45
|
+
@icon = Asset.new(self, data[:icon])
|
46
|
+
@description = data[:description]
|
47
|
+
@summary = data[:summary]
|
48
|
+
@bot_public = data[:bot_public]
|
49
|
+
@bot_require_code_grant = data[:bot_require_code_grant]
|
50
|
+
@verify_key = data[:verify_key]
|
51
|
+
@owner =
|
52
|
+
@client.users[data[:owner][:id]] || User.new(@client, data[:owner])
|
53
|
+
@team = data[:team] && Team.new(@client, data[:team])
|
54
|
+
@flags = Flag.new(data[:flags])
|
55
|
+
end
|
56
|
+
|
57
|
+
def inspect
|
58
|
+
"#<#{self.class} id=#{@id}>"
|
59
|
+
end
|
60
|
+
|
61
|
+
alias public? bot_public?
|
62
|
+
|
63
|
+
alias require_code_grant? bot_require_code_grant?
|
64
|
+
|
65
|
+
#
|
66
|
+
# Represents a flag for an application.
|
67
|
+
# ## Flag fields
|
68
|
+
#
|
69
|
+
# | Field|Value|
|
70
|
+
# |---|---|
|
71
|
+
# | `1 << 12` | `:gateway_presence` |
|
72
|
+
# | `1 << 13` | `:gateway_presence_limited` |
|
73
|
+
# | `1 << 14` | `:gateway_guild_members` |
|
74
|
+
# | `1 << 15` | `:gateway_guild_members_limited` |
|
75
|
+
# | `1 << 16` | `:verification_pending_guild_limit` |
|
76
|
+
# | `1 << 17` | `:embedded` |
|
77
|
+
# | `1 << 18` | `:gateway_message_content` |
|
78
|
+
# | `1 << 19` | `:gateway_message_content_limited` |
|
79
|
+
# | `1 << 23` | `:application_command_badge` |
|
80
|
+
#
|
81
|
+
class Flag < Discorb::Flag
|
82
|
+
@bits = {
|
83
|
+
gateway_presence: 12,
|
84
|
+
gateway_presence_limited: 13,
|
85
|
+
gateway_guild_members: 14,
|
86
|
+
gateway_guild_members_limited: 15,
|
87
|
+
verification_pending_guild_limit: 16,
|
88
|
+
embedded: 17,
|
89
|
+
gateway_message_content: 18,
|
90
|
+
gateway_message_content_limited: 19,
|
91
|
+
application_command_badge: 23
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
#
|
96
|
+
# Represents a team for an application.
|
97
|
+
#
|
98
|
+
class Team < DiscordModel
|
99
|
+
# @return [Discorb::Snowflake] The team's ID.
|
100
|
+
attr_reader :id
|
101
|
+
# @return [Discorb::Asset] The team's icon.
|
102
|
+
attr_reader :icon
|
103
|
+
# @return [String] The team's name.
|
104
|
+
attr_reader :name
|
105
|
+
# @return [Discorb::Snowflake] The team's owner's ID.
|
106
|
+
attr_reader :owner_user_id
|
107
|
+
# @return [Discorb::Application::Team::Member] The team's member.
|
108
|
+
attr_reader :members
|
109
|
+
|
110
|
+
#
|
111
|
+
# Initializes a new instance of the Team class.
|
112
|
+
# @private
|
113
|
+
#
|
114
|
+
# @param [Discorb::Client] client The client that instantiated the object.
|
115
|
+
# @param [Hash] data The data of the object.
|
116
|
+
#
|
117
|
+
def initialize(client, data)
|
118
|
+
@client = client
|
119
|
+
@id = Snowflake.new(data[:id])
|
120
|
+
@icon = Asset.new(self, data[:icon])
|
121
|
+
@name = data[:name]
|
122
|
+
@owner_user_id = data[:owner_user_id]
|
123
|
+
@members = data[:members].map { |m| Team::Member.new(@client, self, m) }
|
124
|
+
end
|
125
|
+
|
126
|
+
#
|
127
|
+
# The team's owner.
|
128
|
+
#
|
129
|
+
# @return [Discorb::Application::Team::Member] The team's owner.
|
130
|
+
#
|
131
|
+
def owner
|
132
|
+
@members.find { |m| m.user.id == @owner_user_id }
|
133
|
+
end
|
134
|
+
|
135
|
+
def inspect
|
136
|
+
"#<#{self.class} id=#{@id}>"
|
137
|
+
end
|
138
|
+
|
139
|
+
#
|
140
|
+
# Represents a member of team.
|
141
|
+
#
|
142
|
+
class Member < DiscordModel
|
143
|
+
# @return [Discorb::User] The user.
|
144
|
+
attr_reader :user
|
145
|
+
# @return [Snowflake] The ID of member's team.
|
146
|
+
attr_reader :team_id
|
147
|
+
# @return [:invited, :accepted] The member's membership state.
|
148
|
+
attr_reader :membership_state
|
149
|
+
alias state membership_state
|
150
|
+
# @return [Array<Symbol>] The permissions of the member.
|
151
|
+
# @note This always return `:*`.
|
152
|
+
attr_reader :permissions
|
153
|
+
|
154
|
+
# @!attribute [r] pending?
|
155
|
+
# @return [Boolean] Whether the member is not joined to the team.
|
156
|
+
# @!attribute [r] accepted?
|
157
|
+
# @return [Boolean] Whether the member accepted joining the team.
|
158
|
+
# @!attribute [r] owner?
|
159
|
+
# @return [Boolean] Whether the member is the team's owner.
|
160
|
+
|
161
|
+
# @private
|
162
|
+
# @return [{Integer => Symbol}] The permission map.
|
163
|
+
MEMBERSHIP_STATE = { 1 => :invited, 2 => :accepted }.freeze
|
164
|
+
|
165
|
+
def initialize(client, team, data)
|
166
|
+
@client = client
|
167
|
+
@data = data
|
168
|
+
@team = team
|
169
|
+
@user =
|
170
|
+
client.users[data[:user][:id]] || User.new(client, data[:user])
|
171
|
+
@team_id = Snowflake.new(data[:team_id])
|
172
|
+
@membership_state = MEMBERSHIP_STATE[data[:membership_state]]
|
173
|
+
@permissions = data[:permissions].map(&:to_sym)
|
174
|
+
end
|
175
|
+
|
176
|
+
def pending?
|
177
|
+
@membership_state == :invited
|
178
|
+
end
|
179
|
+
|
180
|
+
def accepted?
|
181
|
+
@membership_state == :accepted
|
182
|
+
end
|
183
|
+
|
184
|
+
def inspect
|
185
|
+
"#<#{self.class} id=#{@user.id}>"
|
186
|
+
end
|
187
|
+
|
188
|
+
def owner?
|
189
|
+
@team.owner_user_id == @user.id
|
190
|
+
end
|
191
|
+
|
192
|
+
def ==(other)
|
193
|
+
super || @user == other
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
data/lib/discorb/asset.rb
CHANGED
@@ -1,101 +1,101 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Discorb
|
4
|
-
#
|
5
|
-
# Represents a single asset.
|
6
|
-
#
|
7
|
-
class Asset < DiscordModel
|
8
|
-
# @return [String] The hash of asset.
|
9
|
-
attr_reader :hash
|
10
|
-
|
11
|
-
# @!attribute [r] animated?
|
12
|
-
# @return [Boolean] Whether the asset is animated.
|
13
|
-
|
14
|
-
#
|
15
|
-
# Initialize a new instance of the Asset class.
|
16
|
-
# @private
|
17
|
-
#
|
18
|
-
# @param [Discorb::Client] client The client that instantiated the object.
|
19
|
-
# @param [Hash] data The data of the object.
|
20
|
-
#
|
21
|
-
def initialize(target, hash, path: nil)
|
22
|
-
@hash = hash
|
23
|
-
@target = target
|
24
|
-
@path = path
|
25
|
-
end
|
26
|
-
|
27
|
-
def animated?
|
28
|
-
@hash.start_with? "a_"
|
29
|
-
end
|
30
|
-
|
31
|
-
#
|
32
|
-
# URL of the asset.
|
33
|
-
#
|
34
|
-
# @param [String] image_format The image format.
|
35
|
-
# @param [Integer] size The size of the image.
|
36
|
-
#
|
37
|
-
# @return [String] URL of the asset.
|
38
|
-
#
|
39
|
-
def url(image_format: nil, size: 1024)
|
40
|
-
path = @path || "#{endpoint}/#{@target.id}"
|
41
|
-
"https://cdn.discordapp.com/#{path}/#{@hash}.#{image_format or (animated? ? "gif" : "webp")}?size=#{size}"
|
42
|
-
end
|
43
|
-
|
44
|
-
def inspect
|
45
|
-
"#<#{self.class} #{@target.class} #{@hash}>"
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def endpoint
|
51
|
-
case @target
|
52
|
-
when User, Member, Webhook
|
53
|
-
"avatars"
|
54
|
-
when Guild, Webhook::FollowerWebhook::Guild
|
55
|
-
"icons"
|
56
|
-
when Application, Integration::Application
|
57
|
-
"app-icons"
|
58
|
-
when Application::Team
|
59
|
-
"team-icons"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
#
|
65
|
-
# Represents a default avatar.
|
66
|
-
#
|
67
|
-
class DefaultAvatar < DiscordModel
|
68
|
-
# @!attribute [r] animated?
|
69
|
-
# @return [false] For compatibility with {Asset}, always `false`.
|
70
|
-
|
71
|
-
#
|
72
|
-
# Initialize a new instance of the DefaultAvatar class.
|
73
|
-
# @private
|
74
|
-
#
|
75
|
-
def initialize(discriminator)
|
76
|
-
@discriminator = discriminator.to_s.rjust(4, "0")
|
77
|
-
end
|
78
|
-
|
79
|
-
def animated?
|
80
|
-
false
|
81
|
-
end
|
82
|
-
|
83
|
-
#
|
84
|
-
# Returns the URL of the avatar.
|
85
|
-
#
|
86
|
-
# @param [String] image_format The image format. This is compatible with {Asset#url}, will be ignored.
|
87
|
-
# @param [Integer] size The size of the image. This is compatible with {Asset#url}, will be ignored.
|
88
|
-
#
|
89
|
-
# @return [String] URL of the avatar.
|
90
|
-
#
|
91
|
-
# rubocop: disable Lint/UnusedMethodArgument
|
92
|
-
def url(image_format: nil, size: 1024)
|
93
|
-
# rubocop: enable Lint/UnusedMethodArgument
|
94
|
-
"https://cdn.discordapp.com/embed/avatars/#{@discriminator.to_i % 5}.png"
|
95
|
-
end
|
96
|
-
|
97
|
-
def inspect
|
98
|
-
"#<#{self.class} #{@discriminator}>"
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discorb
|
4
|
+
#
|
5
|
+
# Represents a single asset.
|
6
|
+
#
|
7
|
+
class Asset < DiscordModel
|
8
|
+
# @return [String] The hash of asset.
|
9
|
+
attr_reader :hash
|
10
|
+
|
11
|
+
# @!attribute [r] animated?
|
12
|
+
# @return [Boolean] Whether the asset is animated.
|
13
|
+
|
14
|
+
#
|
15
|
+
# Initialize a new instance of the Asset class.
|
16
|
+
# @private
|
17
|
+
#
|
18
|
+
# @param [Discorb::Client] client The client that instantiated the object.
|
19
|
+
# @param [Hash] data The data of the object.
|
20
|
+
#
|
21
|
+
def initialize(target, hash, path: nil)
|
22
|
+
@hash = hash
|
23
|
+
@target = target
|
24
|
+
@path = path
|
25
|
+
end
|
26
|
+
|
27
|
+
def animated?
|
28
|
+
@hash.start_with? "a_"
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# URL of the asset.
|
33
|
+
#
|
34
|
+
# @param [String] image_format The image format.
|
35
|
+
# @param [Integer] size The size of the image.
|
36
|
+
#
|
37
|
+
# @return [String] URL of the asset.
|
38
|
+
#
|
39
|
+
def url(image_format: nil, size: 1024)
|
40
|
+
path = @path || "#{endpoint}/#{@target.id}"
|
41
|
+
"https://cdn.discordapp.com/#{path}/#{@hash}.#{image_format or (animated? ? "gif" : "webp")}?size=#{size}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def inspect
|
45
|
+
"#<#{self.class} #{@target.class} #{@hash}>"
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def endpoint
|
51
|
+
case @target
|
52
|
+
when User, Member, Webhook
|
53
|
+
"avatars"
|
54
|
+
when Guild, Webhook::FollowerWebhook::Guild
|
55
|
+
"icons"
|
56
|
+
when Application, Integration::Application
|
57
|
+
"app-icons"
|
58
|
+
when Application::Team
|
59
|
+
"team-icons"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# Represents a default avatar.
|
66
|
+
#
|
67
|
+
class DefaultAvatar < DiscordModel
|
68
|
+
# @!attribute [r] animated?
|
69
|
+
# @return [false] For compatibility with {Asset}, always `false`.
|
70
|
+
|
71
|
+
#
|
72
|
+
# Initialize a new instance of the DefaultAvatar class.
|
73
|
+
# @private
|
74
|
+
#
|
75
|
+
def initialize(discriminator)
|
76
|
+
@discriminator = discriminator.to_s.rjust(4, "0")
|
77
|
+
end
|
78
|
+
|
79
|
+
def animated?
|
80
|
+
false
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
# Returns the URL of the avatar.
|
85
|
+
#
|
86
|
+
# @param [String] image_format The image format. This is compatible with {Asset#url}, will be ignored.
|
87
|
+
# @param [Integer] size The size of the image. This is compatible with {Asset#url}, will be ignored.
|
88
|
+
#
|
89
|
+
# @return [String] URL of the avatar.
|
90
|
+
#
|
91
|
+
# rubocop: disable Lint/UnusedMethodArgument
|
92
|
+
def url(image_format: nil, size: 1024)
|
93
|
+
# rubocop: enable Lint/UnusedMethodArgument
|
94
|
+
"https://cdn.discordapp.com/embed/avatars/#{@discriminator.to_i % 5}.png"
|
95
|
+
end
|
96
|
+
|
97
|
+
def inspect
|
98
|
+
"#<#{self.class} #{@discriminator}>"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|