discorb 0.19.0 → 0.20.0
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 +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/channel/base.rb
CHANGED
@@ -1,108 +1,107 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Discorb
|
4
|
-
#
|
5
|
-
# Represents a channel of Discord.
|
6
|
-
# @abstract
|
7
|
-
#
|
8
|
-
class Channel < DiscordModel
|
9
|
-
# @return [Discorb::Snowflake] The ID of the channel.
|
10
|
-
attr_reader :id
|
11
|
-
# @return [String] The name of the channel.
|
12
|
-
attr_reader :name
|
13
|
-
|
14
|
-
# @!attribute [r] type
|
15
|
-
# @return [Integer] The type of the channel as integer.
|
16
|
-
|
17
|
-
@channel_type = nil
|
18
|
-
@subclasses = []
|
19
|
-
|
20
|
-
#
|
21
|
-
# Initializes a new instance of the Channel class.
|
22
|
-
# @private
|
23
|
-
#
|
24
|
-
def initialize(client, data, no_cache: false)
|
25
|
-
@client = client
|
26
|
-
@data = {}
|
27
|
-
@no_cache = no_cache
|
28
|
-
_set_data(data)
|
29
|
-
end
|
30
|
-
|
31
|
-
#
|
32
|
-
# Checks if the channel is other channel.
|
33
|
-
#
|
34
|
-
# @param [Discorb::Channel] other The channel to check.
|
35
|
-
#
|
36
|
-
# @return [Boolean] True if the channel is other channel.
|
37
|
-
#
|
38
|
-
def ==(other)
|
39
|
-
return false unless other.respond_to?(:id)
|
40
|
-
|
41
|
-
@id == other.id
|
42
|
-
end
|
43
|
-
|
44
|
-
def inspect
|
45
|
-
"#<#{self.class} \"##{@name}\" id=#{@id}>"
|
46
|
-
end
|
47
|
-
|
48
|
-
#
|
49
|
-
# Returns the descendants of the Channel class.
|
50
|
-
# @private
|
51
|
-
#
|
52
|
-
def self.descendants
|
53
|
-
ObjectSpace.each_object(Class).select { |klass| klass < self }
|
54
|
-
end
|
55
|
-
|
56
|
-
#
|
57
|
-
# Creates a new instance of the Channel class or instance of its descendants.
|
58
|
-
# @private
|
59
|
-
#
|
60
|
-
# @param [Discorb::Client] client The client that instantiated the object.
|
61
|
-
# @param [Hash] data The data of the object.
|
62
|
-
# @param [Boolean] no_cache Whether to disable cache the object.
|
63
|
-
#
|
64
|
-
def self.make_channel(client, data, no_cache: false)
|
65
|
-
descendants.each do |klass|
|
66
|
-
if !klass.channel_type.nil? && klass.channel_type == data[:type]
|
67
|
-
return klass.new(client, data,
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
#
|
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
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discorb
|
4
|
+
#
|
5
|
+
# Represents a channel of Discord.
|
6
|
+
# @abstract
|
7
|
+
#
|
8
|
+
class Channel < DiscordModel
|
9
|
+
# @return [Discorb::Snowflake] The ID of the channel.
|
10
|
+
attr_reader :id
|
11
|
+
# @return [String] The name of the channel.
|
12
|
+
attr_reader :name
|
13
|
+
|
14
|
+
# @!attribute [r] type
|
15
|
+
# @return [Integer] The type of the channel as integer.
|
16
|
+
|
17
|
+
@channel_type = nil
|
18
|
+
@subclasses = []
|
19
|
+
|
20
|
+
#
|
21
|
+
# Initializes a new instance of the Channel class.
|
22
|
+
# @private
|
23
|
+
#
|
24
|
+
def initialize(client, data, no_cache: false)
|
25
|
+
@client = client
|
26
|
+
@data = {}
|
27
|
+
@no_cache = no_cache
|
28
|
+
_set_data(data)
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Checks if the channel is other channel.
|
33
|
+
#
|
34
|
+
# @param [Discorb::Channel] other The channel to check.
|
35
|
+
#
|
36
|
+
# @return [Boolean] True if the channel is other channel.
|
37
|
+
#
|
38
|
+
def ==(other)
|
39
|
+
return false unless other.respond_to?(:id)
|
40
|
+
|
41
|
+
@id == other.id
|
42
|
+
end
|
43
|
+
|
44
|
+
def inspect
|
45
|
+
"#<#{self.class} \"##{@name}\" id=#{@id}>"
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# Returns the descendants of the Channel class.
|
50
|
+
# @private
|
51
|
+
#
|
52
|
+
def self.descendants
|
53
|
+
ObjectSpace.each_object(Class).select { |klass| klass < self }
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# Creates a new instance of the Channel class or instance of its descendants.
|
58
|
+
# @private
|
59
|
+
#
|
60
|
+
# @param [Discorb::Client] client The client that instantiated the object.
|
61
|
+
# @param [Hash] data The data of the object.
|
62
|
+
# @param [Boolean] no_cache Whether to disable cache the object.
|
63
|
+
#
|
64
|
+
def self.make_channel(client, data, no_cache: false)
|
65
|
+
descendants.each do |klass|
|
66
|
+
if !klass.channel_type.nil? && klass.channel_type == data[:type]
|
67
|
+
return klass.new(client, data, no_cache: no_cache)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
client.logger.warn(
|
71
|
+
"Unknown channel type #{data[:type]}, initialized GuildChannel"
|
72
|
+
)
|
73
|
+
GuildChannel.new(client, data)
|
74
|
+
end
|
75
|
+
|
76
|
+
class << self
|
77
|
+
#
|
78
|
+
# @private
|
79
|
+
# @return [Integer] The type of the channel.
|
80
|
+
#
|
81
|
+
attr_reader :channel_type
|
82
|
+
end
|
83
|
+
|
84
|
+
def type
|
85
|
+
self.class.channel_type
|
86
|
+
end
|
87
|
+
|
88
|
+
#
|
89
|
+
# Returns the channel id to request.
|
90
|
+
# @private
|
91
|
+
#
|
92
|
+
# @return [Async::Task<Discorb::Snowflake>] A task that resolves to the channel id.
|
93
|
+
#
|
94
|
+
def channel_id
|
95
|
+
Async { @id }
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def _set_data(data)
|
101
|
+
@id = Snowflake.new(data[:id])
|
102
|
+
@name = data[:name]
|
103
|
+
@client.channels[@id] = self if !@no_cache && !(data[:no_cache])
|
104
|
+
@data.update(data)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -1,32 +1,32 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Discorb
|
4
|
-
#
|
5
|
-
# Represents a category in a guild.
|
6
|
-
#
|
7
|
-
class CategoryChannel < GuildChannel
|
8
|
-
@channel_type = 4
|
9
|
-
|
10
|
-
include Discorb::ChannelContainer
|
11
|
-
|
12
|
-
def channels
|
13
|
-
@client.channels.values.filter { |channel| channel.parent == self }
|
14
|
-
end
|
15
|
-
|
16
|
-
def create_text_channel(*args, **kwargs)
|
17
|
-
guild.create_text_channel(*args, parent: self, **kwargs)
|
18
|
-
end
|
19
|
-
|
20
|
-
def create_voice_channel(*args, **kwargs)
|
21
|
-
guild.create_voice_channel(*args, parent: self, **kwargs)
|
22
|
-
end
|
23
|
-
|
24
|
-
def create_news_channel(*args, **kwargs)
|
25
|
-
guild.create_news_channel(*args, parent: self, **kwargs)
|
26
|
-
end
|
27
|
-
|
28
|
-
def create_stage_channel(*args, **kwargs)
|
29
|
-
guild.create_stage_channel(*args, parent: self, **kwargs)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discorb
|
4
|
+
#
|
5
|
+
# Represents a category in a guild.
|
6
|
+
#
|
7
|
+
class CategoryChannel < GuildChannel
|
8
|
+
@channel_type = 4
|
9
|
+
|
10
|
+
include Discorb::ChannelContainer
|
11
|
+
|
12
|
+
def channels
|
13
|
+
@client.channels.values.filter { |channel| channel.parent == self }
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_text_channel(*args, **kwargs)
|
17
|
+
guild.create_text_channel(*args, parent: self, **kwargs)
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_voice_channel(*args, **kwargs)
|
21
|
+
guild.create_voice_channel(*args, parent: self, **kwargs)
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_news_channel(*args, **kwargs)
|
25
|
+
guild.create_news_channel(*args, parent: self, **kwargs)
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_stage_channel(*args, **kwargs)
|
29
|
+
guild.create_stage_channel(*args, parent: self, **kwargs)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,44 +1,44 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Discorb
|
4
|
-
#
|
5
|
-
# Module for container of channels.
|
6
|
-
#
|
7
|
-
module ChannelContainer
|
8
|
-
#
|
9
|
-
# Returns text channels.
|
10
|
-
#
|
11
|
-
# @return [Array<Discorb::TextChannel>] The text channels.
|
12
|
-
#
|
13
|
-
def text_channels
|
14
|
-
channels.filter { |c| c.instance_of? TextChannel }
|
15
|
-
end
|
16
|
-
|
17
|
-
#
|
18
|
-
# Returns voice channels.
|
19
|
-
#
|
20
|
-
# @return [Array<Discorb::VoiceChannel>] The voice channels.
|
21
|
-
#
|
22
|
-
def voice_channels
|
23
|
-
channels.filter { |c| c.instance_of? VoiceChannel }
|
24
|
-
end
|
25
|
-
|
26
|
-
#
|
27
|
-
# Returns news channels.
|
28
|
-
#
|
29
|
-
# @return [Array<Discorb::NewsChannel>] The news channels.
|
30
|
-
#
|
31
|
-
def news_channels
|
32
|
-
channels.filter { |c| c.instance_of? NewsChannel }
|
33
|
-
end
|
34
|
-
|
35
|
-
#
|
36
|
-
# Returns stage channels.
|
37
|
-
#
|
38
|
-
# @return [Array<Discorb::StageChannel>] The stage channels.
|
39
|
-
#
|
40
|
-
def stage_channels
|
41
|
-
channels.filter { |c| c.instance_of? StageChannel }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discorb
|
4
|
+
#
|
5
|
+
# Module for container of channels.
|
6
|
+
#
|
7
|
+
module ChannelContainer
|
8
|
+
#
|
9
|
+
# Returns text channels.
|
10
|
+
#
|
11
|
+
# @return [Array<Discorb::TextChannel>] The text channels.
|
12
|
+
#
|
13
|
+
def text_channels
|
14
|
+
channels.filter { |c| c.instance_of? TextChannel }
|
15
|
+
end
|
16
|
+
|
17
|
+
#
|
18
|
+
# Returns voice channels.
|
19
|
+
#
|
20
|
+
# @return [Array<Discorb::VoiceChannel>] The voice channels.
|
21
|
+
#
|
22
|
+
def voice_channels
|
23
|
+
channels.filter { |c| c.instance_of? VoiceChannel }
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# Returns news channels.
|
28
|
+
#
|
29
|
+
# @return [Array<Discorb::NewsChannel>] The news channels.
|
30
|
+
#
|
31
|
+
def news_channels
|
32
|
+
channels.filter { |c| c.instance_of? NewsChannel }
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Returns stage channels.
|
37
|
+
#
|
38
|
+
# @return [Array<Discorb::StageChannel>] The stage channels.
|
39
|
+
#
|
40
|
+
def stage_channels
|
41
|
+
channels.filter { |c| c.instance_of? StageChannel }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/discorb/channel/dm.rb
CHANGED
@@ -1,28 +1,26 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Discorb
|
4
|
-
#
|
5
|
-
# Represents a DM channel.
|
6
|
-
#
|
7
|
-
class DMChannel < Channel
|
8
|
-
include Messageable
|
9
|
-
|
10
|
-
#
|
11
|
-
# Returns the channel id to request.
|
12
|
-
# @private
|
13
|
-
#
|
14
|
-
# @return [Async::Task<Discorb::Snowflake>] A task that resolves to the channel id.
|
15
|
-
#
|
16
|
-
def channel_id
|
17
|
-
Async
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discorb
|
4
|
+
#
|
5
|
+
# Represents a DM channel.
|
6
|
+
#
|
7
|
+
class DMChannel < Channel
|
8
|
+
include Messageable
|
9
|
+
|
10
|
+
#
|
11
|
+
# Returns the channel id to request.
|
12
|
+
# @private
|
13
|
+
#
|
14
|
+
# @return [Async::Task<Discorb::Snowflake>] A task that resolves to the channel id.
|
15
|
+
#
|
16
|
+
def channel_id
|
17
|
+
Async { @id }
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def _set_data(data)
|
23
|
+
@id = Snowflake.new(data)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|