discorb 0.9.3 → 0.10.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_main.yml +2 -0
- data/Changelog.md +298 -247
- data/README.md +6 -6
- data/Rakefile +7 -1
- data/assets/banner.svg +101 -101
- data/docs/application_command.md +8 -7
- data/docs/cli/run.md +3 -3
- data/docs/extension.md +16 -22
- data/docs/license.md +5 -1
- data/examples/extension/main.rb +1 -1
- data/examples/extension/message_expander.rb +4 -6
- data/lib/discorb/app_command.rb +12 -10
- data/lib/discorb/application.rb +3 -3
- data/lib/discorb/asset.rb +2 -2
- data/lib/discorb/audit_logs.rb +7 -7
- data/lib/discorb/channel.rb +10 -10
- data/lib/discorb/client.rb +22 -23
- data/lib/discorb/common.rb +6 -25
- data/lib/discorb/components.rb +31 -3
- data/lib/discorb/embed.rb +2 -2
- data/lib/discorb/emoji.rb +3 -3
- data/lib/discorb/error.rb +2 -2
- data/lib/discorb/exe/init.rb +8 -8
- data/lib/discorb/exe/run.rb +1 -1
- data/lib/discorb/extend.rb +21 -0
- data/lib/discorb/extension.rb +60 -47
- data/lib/discorb/file.rb +19 -1
- data/lib/discorb/gateway.rb +8 -8
- data/lib/discorb/gateway_requests.rb +1 -1
- data/lib/discorb/guild.rb +7 -7
- data/lib/discorb/guild_template.rb +4 -4
- data/lib/discorb/http.rb +1 -1
- data/lib/discorb/integration.rb +3 -3
- data/lib/discorb/interaction.rb +36 -32
- data/lib/discorb/invite.rb +2 -2
- data/lib/discorb/log.rb +1 -1
- data/lib/discorb/member.rb +1 -1
- data/lib/discorb/message.rb +34 -10
- data/lib/discorb/modules.rb +15 -49
- data/lib/discorb/permission.rb +2 -2
- data/lib/discorb/presence.rb +8 -8
- data/lib/discorb/rate_limit.rb +1 -1
- data/lib/discorb/reaction.rb +1 -1
- data/lib/discorb/role.rb +2 -2
- data/lib/discorb/sticker.rb +3 -3
- data/lib/discorb/user.rb +2 -2
- data/lib/discorb/utils/colored_puts.rb +3 -3
- data/lib/discorb/utils.rb +1 -21
- data/lib/discorb/voice_state.rb +3 -3
- data/lib/discorb/webhook.rb +7 -8
- data/lib/discorb.rb +1 -1
- data/sig/discorb.rbs +2 -2
- data/template-replace/files/css/common.css +26 -0
- data/template-replace/files/favicon.png +0 -0
- data/template-replace/scripts/arrow.rb +7 -0
- data/template-replace/scripts/favicon.rb +9 -0
- data/template-replace/scripts/version.rb +20 -5
- metadata +5 -2
data/lib/discorb/channel.rb
CHANGED
@@ -19,7 +19,7 @@ module Discorb
|
|
19
19
|
@channel_type = nil
|
20
20
|
@subclasses = []
|
21
21
|
|
22
|
-
#
|
22
|
+
# @private
|
23
23
|
def initialize(client, data, no_cache: false)
|
24
24
|
@client = client
|
25
25
|
@data = {}
|
@@ -44,12 +44,12 @@ module Discorb
|
|
44
44
|
"#<#{self.class} \"##{@name}\" id=#{@id}>"
|
45
45
|
end
|
46
46
|
|
47
|
-
#
|
47
|
+
# @private
|
48
48
|
def self.descendants
|
49
49
|
ObjectSpace.each_object(Class).select { |klass| klass < self }
|
50
50
|
end
|
51
51
|
|
52
|
-
#
|
52
|
+
# @private
|
53
53
|
def self.make_channel(client, data, no_cache: false)
|
54
54
|
descendants.each do |klass|
|
55
55
|
return klass.new(client, data, no_cache: no_cache) if !klass.channel_type.nil? && klass.channel_type == data[:type]
|
@@ -59,7 +59,7 @@ module Discorb
|
|
59
59
|
end
|
60
60
|
|
61
61
|
class << self
|
62
|
-
#
|
62
|
+
# @private
|
63
63
|
attr_reader :channel_type
|
64
64
|
end
|
65
65
|
|
@@ -67,7 +67,7 @@ module Discorb
|
|
67
67
|
self.class.channel_type
|
68
68
|
end
|
69
69
|
|
70
|
-
#
|
70
|
+
# @private
|
71
71
|
def channel_id
|
72
72
|
Async do
|
73
73
|
@id
|
@@ -248,7 +248,7 @@ module Discorb
|
|
248
248
|
|
249
249
|
@channel_type = 0
|
250
250
|
|
251
|
-
#
|
251
|
+
# @private
|
252
252
|
def initialize(client, data, no_cache: false)
|
253
253
|
super
|
254
254
|
@threads = Dictionary.new
|
@@ -697,7 +697,7 @@ module Discorb
|
|
697
697
|
attr_reader :bitrate
|
698
698
|
# @return [Integer] The user limit of the voice channel.
|
699
699
|
attr_reader :user_limit
|
700
|
-
#
|
700
|
+
# @private
|
701
701
|
attr_reader :stage_instances
|
702
702
|
|
703
703
|
include Connectable
|
@@ -706,7 +706,7 @@ module Discorb
|
|
706
706
|
# @return [Discorb::StageInstance] The stage instance of the channel.
|
707
707
|
|
708
708
|
@channel_type = 13
|
709
|
-
#
|
709
|
+
# @private
|
710
710
|
def initialize(...)
|
711
711
|
@stage_instances = Dictionary.new
|
712
712
|
super(...)
|
@@ -831,7 +831,7 @@ module Discorb
|
|
831
831
|
include Messageable
|
832
832
|
@channel_type = nil
|
833
833
|
|
834
|
-
#
|
834
|
+
# @private
|
835
835
|
def initialize(client, data, no_cache: false)
|
836
836
|
@members = Dictionary.new
|
837
837
|
super
|
@@ -1092,7 +1092,7 @@ module Discorb
|
|
1092
1092
|
class DMChannel < Channel
|
1093
1093
|
include Messageable
|
1094
1094
|
|
1095
|
-
#
|
1095
|
+
# @private
|
1096
1096
|
def channel_id
|
1097
1097
|
Async do
|
1098
1098
|
@id
|
data/lib/discorb/client.rb
CHANGED
@@ -369,31 +369,30 @@ module Discorb
|
|
369
369
|
#
|
370
370
|
# Load the extension.
|
371
371
|
#
|
372
|
-
# @param [
|
373
|
-
#
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
end
|
386
|
-
@commands.delete_if do |cmd|
|
387
|
-
cmd.respond_to? :extension and cmd.extension == mod.name
|
388
|
-
end
|
389
|
-
mod.commands.each do |cmd|
|
390
|
-
cmd.define_singleton_method(:extension) { mod.name }
|
391
|
-
@commands << cmd
|
372
|
+
# @param [Class] ext The extension to load.
|
373
|
+
# @param [Object] ... The arguments to pass to the `ext#initialize`.
|
374
|
+
#
|
375
|
+
def load_extension(ext, ...)
|
376
|
+
raise ArgumentError, "#{ext} is not a extension" unless ext.is_a?(Class) && ext < Discorb::Extension
|
377
|
+
ins = ext.new(self, ...)
|
378
|
+
@events.each_value do |event|
|
379
|
+
event.delete_if { |c| c.metadata[:extension] == ins.class.name }
|
380
|
+
end
|
381
|
+
ins.events.each do |name, events|
|
382
|
+
@events[name] ||= []
|
383
|
+
events.each do |event|
|
384
|
+
@events[name] << event
|
392
385
|
end
|
393
|
-
@bottom_commands += mod.bottom_commands
|
394
|
-
mod.client = self
|
395
386
|
end
|
396
|
-
|
387
|
+
@commands.delete_if do |cmd|
|
388
|
+
cmd.respond_to? :extension and cmd.extension == ins.name
|
389
|
+
end
|
390
|
+
ins.class.commands.each do |cmd|
|
391
|
+
cmd.define_singleton_method(:extension) { ins.name }
|
392
|
+
@commands << cmd
|
393
|
+
end
|
394
|
+
@bottom_commands += ins.class.bottom_commands
|
395
|
+
ins
|
397
396
|
end
|
398
397
|
|
399
398
|
include Discorb::Gateway::Handler
|
data/lib/discorb/common.rb
CHANGED
@@ -4,9 +4,9 @@ module Discorb
|
|
4
4
|
# @return [String] The API base URL.
|
5
5
|
API_BASE_URL = "https://discord.com/api/v9"
|
6
6
|
# @return [String] The version of discorb.
|
7
|
-
VERSION = "0.
|
7
|
+
VERSION = "0.10.0"
|
8
8
|
# @return [String] The user agent for the bot.
|
9
|
-
USER_AGENT = "DiscordBot (https://
|
9
|
+
USER_AGENT = "DiscordBot (https://discorb-lib.github.io #{VERSION}) Ruby/#{RUBY_VERSION}"
|
10
10
|
|
11
11
|
#
|
12
12
|
# @abstract
|
@@ -25,7 +25,7 @@ module Discorb
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
#
|
28
|
+
# @private
|
29
29
|
def inspect
|
30
30
|
super
|
31
31
|
end
|
@@ -39,10 +39,11 @@ module Discorb
|
|
39
39
|
# Represents Snowflake of Discord.
|
40
40
|
#
|
41
41
|
# @see https://discord.com/developers/docs/reference#snowflakes Official Discord API docs
|
42
|
-
class Snowflake <
|
43
|
-
#
|
42
|
+
class Snowflake < String
|
43
|
+
# @private
|
44
44
|
def initialize(value)
|
45
45
|
@value = value.to_i
|
46
|
+
super(@value.to_s)
|
46
47
|
end
|
47
48
|
|
48
49
|
# @!attribute [r] timestamp
|
@@ -64,26 +65,6 @@ module Discorb
|
|
64
65
|
#
|
65
66
|
# @return [Integer] Increment of snowflake.
|
66
67
|
|
67
|
-
#
|
68
|
-
# Stringify snowflake.
|
69
|
-
#
|
70
|
-
# @return [String] Stringified snowflake.
|
71
|
-
#
|
72
|
-
def to_s
|
73
|
-
@value.to_s
|
74
|
-
end
|
75
|
-
|
76
|
-
alias to_str to_s
|
77
|
-
|
78
|
-
#
|
79
|
-
# Integerize snowflake.
|
80
|
-
#
|
81
|
-
# @return [Integer] Integerized snowflake.
|
82
|
-
#
|
83
|
-
def to_i
|
84
|
-
@value.to_i
|
85
|
-
end
|
86
|
-
|
87
68
|
#
|
88
69
|
# Compares snowflake with other object.
|
89
70
|
#
|
data/lib/discorb/components.rb
CHANGED
@@ -36,6 +36,34 @@ module Discorb
|
|
36
36
|
)
|
37
37
|
end
|
38
38
|
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Convert components to a hash.
|
42
|
+
#
|
43
|
+
# @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components Components.
|
44
|
+
#
|
45
|
+
# @return [Array<Hash>] Hash data.
|
46
|
+
#
|
47
|
+
def to_payload(components)
|
48
|
+
tmp_components = []
|
49
|
+
tmp_row = []
|
50
|
+
components.each do |c|
|
51
|
+
case c
|
52
|
+
when Array
|
53
|
+
tmp_components << tmp_row
|
54
|
+
tmp_row = []
|
55
|
+
tmp_components << c
|
56
|
+
when SelectMenu
|
57
|
+
tmp_components << tmp_row
|
58
|
+
tmp_row = []
|
59
|
+
tmp_components << [c]
|
60
|
+
else
|
61
|
+
tmp_row << c
|
62
|
+
end
|
63
|
+
end
|
64
|
+
tmp_components << tmp_row
|
65
|
+
return tmp_components.filter { |c| c.length.positive? }.map { |c| { type: 1, components: c.map(&:to_hash) } }
|
66
|
+
end
|
39
67
|
end
|
40
68
|
end
|
41
69
|
|
@@ -115,7 +143,7 @@ module Discorb
|
|
115
143
|
end
|
116
144
|
|
117
145
|
class << self
|
118
|
-
#
|
146
|
+
# @private
|
119
147
|
attr_reader :styles
|
120
148
|
end
|
121
149
|
|
@@ -152,7 +180,7 @@ module Discorb
|
|
152
180
|
# @return [Integer] The maximum number of values.
|
153
181
|
attr_accessor :max_values
|
154
182
|
# @return [Boolean] Whether the select menu is disabled.
|
155
|
-
|
183
|
+
attr_accessor :disabled
|
156
184
|
alias disabled? disabled
|
157
185
|
|
158
186
|
#
|
@@ -236,7 +264,7 @@ module Discorb
|
|
236
264
|
}
|
237
265
|
end
|
238
266
|
|
239
|
-
#
|
267
|
+
# @private
|
240
268
|
def hash_emoji(emoji)
|
241
269
|
case emoji
|
242
270
|
when UnicodeEmoji
|
data/lib/discorb/embed.rb
CHANGED
@@ -317,7 +317,7 @@ module Discorb
|
|
317
317
|
# @return [Integer] The width of video.
|
318
318
|
attr_reader :width
|
319
319
|
|
320
|
-
#
|
320
|
+
# @private
|
321
321
|
def initialize(data)
|
322
322
|
@url = data[:url]
|
323
323
|
@proxy_url = data[:proxy_url]
|
@@ -335,7 +335,7 @@ module Discorb
|
|
335
335
|
# @return [String] The url of provider.
|
336
336
|
attr_reader :url
|
337
337
|
|
338
|
-
#
|
338
|
+
# @private
|
339
339
|
def initialize(data)
|
340
340
|
@name = data[:name]
|
341
341
|
@url = data[:url]
|
data/lib/discorb/emoji.rb
CHANGED
@@ -40,7 +40,7 @@ module Discorb
|
|
40
40
|
# @!attribute [r] roles?
|
41
41
|
# @return [Boolean] whether or not this emoji is restricted to certain roles.
|
42
42
|
|
43
|
-
#
|
43
|
+
# @private
|
44
44
|
def initialize(client, guild, data)
|
45
45
|
@client = client
|
46
46
|
@guild = guild
|
@@ -147,7 +147,7 @@ module Discorb
|
|
147
147
|
attr_reader :deleted
|
148
148
|
alias deleted? deleted
|
149
149
|
|
150
|
-
#
|
150
|
+
# @private
|
151
151
|
def initialize(data)
|
152
152
|
@id = Snowflake.new(data[:id])
|
153
153
|
@name = data[:name]
|
@@ -189,7 +189,7 @@ module Discorb
|
|
189
189
|
# @return [Integer] The skin tone of the emoji.
|
190
190
|
attr_reader :skin_tone
|
191
191
|
|
192
|
-
#
|
192
|
+
# @private
|
193
193
|
def initialize(name, tone: 0)
|
194
194
|
if EmojiTable::DISCORD_TO_UNICODE.key?(name)
|
195
195
|
@name = name
|
data/lib/discorb/error.rb
CHANGED
@@ -43,7 +43,7 @@ module Discorb
|
|
43
43
|
# @return [Net::HTTPResponse] the HTTP response.
|
44
44
|
attr_reader :response
|
45
45
|
|
46
|
-
#
|
46
|
+
# @private
|
47
47
|
def initialize(resp, data)
|
48
48
|
@code = data[:code]
|
49
49
|
@response = resp
|
@@ -55,7 +55,7 @@ module Discorb
|
|
55
55
|
# Represents a 400 error.
|
56
56
|
#
|
57
57
|
class BadRequestError < HTTPError
|
58
|
-
#
|
58
|
+
# @private
|
59
59
|
def initialize(resp, data)
|
60
60
|
@code = data[:code]
|
61
61
|
@response = resp
|
data/lib/discorb/exe/init.rb
CHANGED
@@ -6,7 +6,7 @@ require_relative "../utils/colored_puts"
|
|
6
6
|
|
7
7
|
$path = Dir.pwd
|
8
8
|
|
9
|
-
#
|
9
|
+
# @private
|
10
10
|
FILES = {
|
11
11
|
"main.rb" => <<~'RUBY',
|
12
12
|
require "discorb"
|
@@ -133,12 +133,12 @@ FILES = {
|
|
133
133
|
MARKDOWN
|
134
134
|
}
|
135
135
|
|
136
|
-
#
|
136
|
+
# @private
|
137
137
|
def create_file(name)
|
138
138
|
File.write($path + "/#{name}", format(FILES[name], token: $values[:token], name: $values[:name]), mode: "wb")
|
139
139
|
end
|
140
140
|
|
141
|
-
#
|
141
|
+
# @private
|
142
142
|
def make_files
|
143
143
|
iputs "Making files..."
|
144
144
|
create_file("main.rb")
|
@@ -146,7 +146,7 @@ def make_files
|
|
146
146
|
sputs "Made files.\n"
|
147
147
|
end
|
148
148
|
|
149
|
-
#
|
149
|
+
# @private
|
150
150
|
def bundle_init
|
151
151
|
iputs "Initializing bundle..."
|
152
152
|
create_file("Gemfile")
|
@@ -155,7 +155,7 @@ def bundle_init
|
|
155
155
|
sputs "Installed gems.\n"
|
156
156
|
end
|
157
157
|
|
158
|
-
#
|
158
|
+
# @private
|
159
159
|
def git_init
|
160
160
|
create_file(".gitignore")
|
161
161
|
iputs "Initializing git repository..."
|
@@ -167,7 +167,7 @@ def git_init
|
|
167
167
|
" to change commit message of initial commit.\n"
|
168
168
|
end
|
169
169
|
|
170
|
-
#
|
170
|
+
# @private
|
171
171
|
def make_descs
|
172
172
|
iputs "Making descriptions..."
|
173
173
|
create_file(".env.sample")
|
@@ -246,8 +246,8 @@ bundle_init if $values[:bundle]
|
|
246
246
|
|
247
247
|
make_files
|
248
248
|
|
249
|
-
git_init if $values[:git]
|
250
|
-
|
251
249
|
make_descs if $values[:descs]
|
252
250
|
|
251
|
+
git_init if $values[:git]
|
252
|
+
|
253
253
|
sputs "\nSuccessfully made a new project at \e[32m#{$path}\e[92m."
|
data/lib/discorb/exe/run.rb
CHANGED
data/lib/discorb/extend.rb
CHANGED
@@ -16,3 +16,24 @@ class Time
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
|
+
|
20
|
+
# @private
|
21
|
+
class Async::Node
|
22
|
+
def description
|
23
|
+
@object_name ||= "#{self.class}:0x#{object_id.to_s(16)}#{@transient ? " transient" : nil}"
|
24
|
+
|
25
|
+
if @annotation
|
26
|
+
"#{@object_name} #{@annotation}"
|
27
|
+
elsif line = self.backtrace(0, 1)&.first
|
28
|
+
"#{@object_name} #{line}"
|
29
|
+
else
|
30
|
+
@object_name
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_s
|
35
|
+
"\#<#{self.description}>"
|
36
|
+
end
|
37
|
+
|
38
|
+
alias inspect to_s
|
39
|
+
end
|
data/lib/discorb/extension.rb
CHANGED
@@ -2,65 +2,78 @@
|
|
2
2
|
|
3
3
|
module Discorb
|
4
4
|
#
|
5
|
-
#
|
6
|
-
#
|
5
|
+
# Abstract class to make extension.
|
6
|
+
# Inherit from this class to make your own extension.
|
7
7
|
# @see file:docs/extension.md
|
8
8
|
# @abstract
|
9
9
|
#
|
10
|
-
|
11
|
-
|
12
|
-
undef setup_commands
|
10
|
+
class Extension
|
11
|
+
extend Discorb::ApplicationCommand::Handler
|
13
12
|
|
14
13
|
@events = {}
|
15
|
-
@client = nil
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
#
|
20
|
-
# @param [Symbol] event_name The name of the event.
|
21
|
-
# @param [Symbol] id The id of the event. Used to delete the event.
|
22
|
-
# @param [Hash] metadata Other metadata.
|
23
|
-
# @param [Proc] block The block to execute when the event is triggered.
|
24
|
-
#
|
25
|
-
# @return [Discorb::Event] The event.
|
26
|
-
#
|
27
|
-
def event(event_name, id: nil, **metadata, &block)
|
28
|
-
raise ArgumentError, "Event name must be a symbol" unless event_name.is_a?(Symbol)
|
29
|
-
raise ArgumentError, "block must be a Proc" unless block.is_a?(Proc)
|
30
|
-
|
31
|
-
@events[event_name] ||= []
|
32
|
-
metadata[:extension] = self.name
|
33
|
-
@events[event_name] << Discorb::Event.new(block, id, metadata)
|
15
|
+
def initialize(client)
|
16
|
+
@client = client
|
34
17
|
end
|
35
18
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
#
|
46
|
-
def once_event(event_name, id: nil, **metadata, &block)
|
47
|
-
event(event_name, id: id, once: true, **metadata, &block)
|
19
|
+
def events
|
20
|
+
return @events if @events
|
21
|
+
ret = {}
|
22
|
+
self.class.events.each do |event, handlers|
|
23
|
+
ret[event] = handlers.map do |handler|
|
24
|
+
Discorb::Event.new(Proc.new { |*args, **kwargs| instance_exec(*args, **kwargs, &handler[2]) }, handler[0], handler[1])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
@events = ret
|
48
28
|
end
|
49
29
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
30
|
+
class << self
|
31
|
+
undef setup_commands
|
32
|
+
|
33
|
+
#
|
34
|
+
# Define a new event.
|
35
|
+
#
|
36
|
+
# @param [Symbol] event_name The name of the event.
|
37
|
+
# @param [Symbol] id The id of the event. Used to delete the event.
|
38
|
+
# @param [Hash] metadata Other metadata.
|
39
|
+
#
|
40
|
+
# @return [Discorb::Event] The event.
|
41
|
+
#
|
42
|
+
def event(event_name, id: nil, **metadata, &block)
|
43
|
+
raise ArgumentError, "Event name must be a symbol" unless event_name.is_a?(Symbol)
|
44
|
+
raise ArgumentError, "block must be given" unless block_given?
|
45
|
+
|
46
|
+
@events[event_name] ||= []
|
47
|
+
metadata[:extension] = self.name
|
48
|
+
@events[event_name] << [id, metadata, block]
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# Define a new once event.
|
53
|
+
#
|
54
|
+
# @param [Symbol] event_name The name of the event.
|
55
|
+
# @param [Symbol] id The id of the event. Used to delete the event.
|
56
|
+
# @param [Hash] metadata Other metadata.
|
57
|
+
# @param [Proc] block The block to execute when the event is triggered.
|
58
|
+
#
|
59
|
+
# @return [Discorb::Event] The event.
|
60
|
+
#
|
61
|
+
def once_event(event_name, id: nil, **metadata, &block)
|
62
|
+
event(event_name, id: id, once: true, **metadata, &block)
|
63
|
+
end
|
56
64
|
|
57
|
-
|
58
|
-
|
65
|
+
# @return [Hash{Symbol => Array<Discorb::Event>}] The events of the extension.
|
66
|
+
attr_reader :events
|
67
|
+
# @return [Array<Discorb::ApplicationCommand::Command>] The commands of the extension.
|
68
|
+
attr_reader :commands
|
69
|
+
# @private
|
70
|
+
attr_reader :bottom_commands
|
59
71
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
72
|
+
def inherited(klass)
|
73
|
+
klass.instance_variable_set(:@commands, [])
|
74
|
+
klass.instance_variable_set(:@bottom_commands, [])
|
75
|
+
klass.instance_variable_set(:@events, {})
|
76
|
+
end
|
64
77
|
end
|
65
78
|
end
|
66
79
|
end
|
data/lib/discorb/file.rb
CHANGED
@@ -32,7 +32,7 @@ module Discorb
|
|
32
32
|
# @!attribute [r] image?
|
33
33
|
# @return [Boolean] whether the file is an image.
|
34
34
|
|
35
|
-
#
|
35
|
+
# @private
|
36
36
|
def initialize(data)
|
37
37
|
@id = Snowflake.new(data[:id])
|
38
38
|
@filename = data[:filename]
|
@@ -60,6 +60,14 @@ module Discorb
|
|
60
60
|
# @return [String] The content type of the file. If not set, it is guessed from the filename.
|
61
61
|
attr_accessor :content_type
|
62
62
|
|
63
|
+
#
|
64
|
+
# Creates a new file from IO.
|
65
|
+
#
|
66
|
+
# @param [#read] io The IO of the file.
|
67
|
+
# @param [String] filename The filename of the file. If not set, path or object_id of the IO is used.
|
68
|
+
# @param [String] content_type The content type of the file. If not set, it is guessed from the filename.
|
69
|
+
# If failed to guess, it is set to `application/octet-stream`.
|
70
|
+
#
|
63
71
|
def initialize(io, filename = nil, content_type: nil)
|
64
72
|
@io = io
|
65
73
|
@filename = filename || (io.respond_to?(:path) ? io.path : io.object_id)
|
@@ -67,8 +75,18 @@ module Discorb
|
|
67
75
|
@content_type = "application/octet-stream" if @content_type == ""
|
68
76
|
end
|
69
77
|
|
78
|
+
#
|
79
|
+
# Creates a new file from a string.
|
80
|
+
#
|
81
|
+
# @param [String] string The string to create the file from.
|
82
|
+
# @param [String] filename The filename of the file. object_id of the string is used if not set.
|
83
|
+
# @param [String] content_type The content type of the file. If not set, it is guessed from the filename.
|
84
|
+
#
|
85
|
+
# @return [File] The new file.
|
86
|
+
#
|
70
87
|
def self.from_string(string, filename: nil, content_type: nil)
|
71
88
|
io = StringIO.new(string)
|
89
|
+
filename ||= string.object_id.to_s + ".txt"
|
72
90
|
new(io, filename, content_type: content_type)
|
73
91
|
end
|
74
92
|
end
|
data/lib/discorb/gateway.rb
CHANGED
@@ -16,7 +16,7 @@ module Discorb
|
|
16
16
|
# Represents an event.
|
17
17
|
#
|
18
18
|
class GatewayEvent
|
19
|
-
#
|
19
|
+
# @private
|
20
20
|
def initialize(data)
|
21
21
|
@data = data
|
22
22
|
end
|
@@ -61,7 +61,7 @@ module Discorb
|
|
61
61
|
alias reactor fired_by
|
62
62
|
alias from fired_by
|
63
63
|
|
64
|
-
#
|
64
|
+
# @private
|
65
65
|
def initialize(client, data)
|
66
66
|
@client = client
|
67
67
|
@data = data
|
@@ -129,7 +129,7 @@ module Discorb
|
|
129
129
|
# @return [Discorb::Message] The message the reaction was sent in.
|
130
130
|
attr_reader :message
|
131
131
|
|
132
|
-
#
|
132
|
+
# @private
|
133
133
|
def initialize(client, data)
|
134
134
|
@client = client
|
135
135
|
@data = data
|
@@ -180,7 +180,7 @@ module Discorb
|
|
180
180
|
# @return [Discorb::UnicodeEmoji, Discorb::PartialEmoji] The emoji that was reacted with.
|
181
181
|
attr_reader :emoji
|
182
182
|
|
183
|
-
#
|
183
|
+
# @private
|
184
184
|
def initialize(client, data)
|
185
185
|
@client = client
|
186
186
|
@data = data
|
@@ -296,7 +296,7 @@ module Discorb
|
|
296
296
|
# @macro client_cache
|
297
297
|
# @return [Discorb::Guild] The guild the message was sent in.
|
298
298
|
|
299
|
-
#
|
299
|
+
# @private
|
300
300
|
def initialize(client, id, data)
|
301
301
|
@client = client
|
302
302
|
@id = id
|
@@ -328,7 +328,7 @@ module Discorb
|
|
328
328
|
# @macro client_cache
|
329
329
|
# @return [Discorb::Guild] The guild the message was sent in.
|
330
330
|
|
331
|
-
#
|
331
|
+
# @private
|
332
332
|
def initialize(client, data)
|
333
333
|
@client = client
|
334
334
|
@data = data
|
@@ -381,7 +381,7 @@ module Discorb
|
|
381
381
|
# @macro client_cache
|
382
382
|
# @return [Discorb::Member, Discorb::User] The member or user that started typing.
|
383
383
|
|
384
|
-
#
|
384
|
+
# @private
|
385
385
|
def initialize(client, data)
|
386
386
|
@client = client
|
387
387
|
@data = data
|
@@ -458,7 +458,7 @@ module Discorb
|
|
458
458
|
# @macro client_cache
|
459
459
|
# @return [Discorb::Guild] The guild where the webhook was updated.
|
460
460
|
|
461
|
-
#
|
461
|
+
# @private
|
462
462
|
def initialize(client, data)
|
463
463
|
@client = client
|
464
464
|
@data = data
|