discorb 0.18.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 +25 -0
- data/Gemfile +4 -4
- data/README.md +2 -1
- data/Rakefile +482 -459
- data/Steepfile +8 -6
- data/docs/application_command.md +1 -0
- data/docs/events.md +2 -2
- data/docs/voice_events.md +6 -6
- data/lib/discorb/allowed_mentions.rb +68 -72
- data/lib/discorb/app_command/command.rb +466 -394
- data/lib/discorb/app_command/common.rb +65 -25
- data/lib/discorb/app_command/handler.rb +304 -265
- 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 -623
- 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 -794
- 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 -330
- data/lib/discorb/interaction/root.rb +271 -118
- 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 -289
- 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/activity.rbs +1 -0
- data/sig/discorb/allowed_mentions.rbs +1 -0
- data/sig/discorb/app_command/base.rbs +7 -1
- data/sig/discorb/application.rbs +6 -0
- data/sig/discorb/asset.rbs +2 -0
- data/sig/discorb/attachment.rbs +8 -0
- data/sig/discorb/audit_log.rbs +7 -0
- data/sig/discorb/automod.rbs +32 -6
- data/sig/discorb/avatar.rbs +1 -0
- data/sig/discorb/channel/base.rbs +8 -1
- data/sig/discorb/channel/category.rbs +1 -0
- data/sig/discorb/channel/container.rbs +4 -0
- data/sig/discorb/channel/stage.rbs +4 -0
- data/sig/discorb/channel/text.rbs +2 -2
- data/sig/discorb/channel/thread.rbs +11 -0
- data/sig/discorb/channel/voice.rbs +2 -0
- data/sig/discorb/client.rbs +21 -20
- data/sig/discorb/color.rbs +6 -0
- data/sig/discorb/component/base.rbs +1 -0
- data/sig/discorb/component/button.rbs +2 -0
- data/sig/discorb/component/select_menu.rbs +4 -0
- data/sig/discorb/component/text_input.rbs +1 -0
- data/sig/discorb/custom_emoji.rbs +5 -1
- data/sig/discorb/dictionary.rbs +2 -0
- data/sig/discorb/discord_model.rbs +2 -0
- data/sig/discorb/embed.rbs +7 -0
- data/sig/discorb/emoji.rbs +1 -0
- data/sig/discorb/event_handler.rbs +2 -1
- data/sig/discorb/extension.rbs +13 -12
- data/sig/discorb/flag.rbs +2 -0
- data/sig/discorb/gateway.rbs +5 -0
- data/sig/discorb/guild.rbs +8 -4
- data/sig/discorb/guild_template.rbs +1 -1
- data/sig/discorb/http.rbs +4 -1
- data/sig/discorb/image.rbs +2 -0
- data/sig/discorb/integration.rbs +1 -1
- data/sig/discorb/intents.rbs +4 -3
- data/sig/discorb/interaction/base.rbs +36 -0
- data/sig/discorb/interaction/message_component.rbs +1 -2
- data/sig/discorb/interaction/modal.rbs +1 -2
- data/sig/discorb/interaction/responder.rbs +49 -49
- data/sig/discorb/invite.rbs +1 -1
- data/sig/discorb/member.rbs +2 -0
- data/sig/discorb/message.rbs +8 -1
- data/sig/discorb/messageable.rbs +1 -4
- data/sig/discorb/partial_emoji.rbs +3 -0
- data/sig/discorb/permissions.rbs +7 -0
- data/sig/discorb/presence.rbs +2 -0
- data/sig/discorb/reaction.rbs +5 -1
- data/sig/discorb/role.rbs +7 -1
- data/sig/discorb/scheduled_event.rbs +2 -1
- data/sig/discorb/shard.rbs +2 -1
- data/sig/discorb/snowflake.rbs +2 -0
- data/sig/discorb/stage_instance.rbs +9 -3
- data/sig/discorb/sticker.rbs +1 -1
- data/sig/discorb/unicode_emoji.rbs +4 -0
- data/sig/discorb/user.rbs +24 -20
- data/sig/discorb/webhook.rbs +17 -6
- data/sig/discorb/welcome_screen.rbs +1 -0
- data/sig/override.rbs +2 -0
- metadata +3 -3
data/lib/discorb/exe/run.rb
CHANGED
@@ -1,68 +1,69 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# description: Run a client.
|
4
|
-
require "optparse"
|
5
|
-
require "json"
|
6
|
-
require "discorb/utils/colored_puts"
|
7
|
-
require "io/console"
|
8
|
-
require "discorb"
|
9
|
-
|
10
|
-
opt = OptionParser.new <<~BANNER
|
11
|
-
This command will run a client.
|
12
|
-
|
13
|
-
Usage: discorb run [options] [script]
|
14
|
-
|
15
|
-
script The script to run. Defaults to 'main.rb'.
|
16
|
-
BANNER
|
17
|
-
options = {
|
18
|
-
|
19
|
-
setup
|
20
|
-
|
21
|
-
|
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
|
-
end
|
49
|
-
|
50
|
-
|
51
|
-
ENV["
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# description: Run a client.
|
4
|
+
require "optparse"
|
5
|
+
require "json"
|
6
|
+
require "discorb/utils/colored_puts"
|
7
|
+
require "io/console"
|
8
|
+
require "discorb"
|
9
|
+
|
10
|
+
opt = OptionParser.new <<~BANNER
|
11
|
+
This command will run a client.
|
12
|
+
|
13
|
+
Usage: discorb run [options] [script]
|
14
|
+
|
15
|
+
script The script to run. Defaults to 'main.rb'.
|
16
|
+
BANNER
|
17
|
+
options = { title: nil, setup: nil, token: false }
|
18
|
+
opt.on("-s", "--setup", "Whether to setup application commands.") do |v|
|
19
|
+
options[:setup] = v
|
20
|
+
end
|
21
|
+
opt.on(
|
22
|
+
"-e",
|
23
|
+
"--env [ENV]",
|
24
|
+
"The name of the environment variable to use for token, or just `-e` or `--env` for intractive prompt."
|
25
|
+
) { |v| options[:token] = v }
|
26
|
+
opt.on("-t", "--title TITLE", "The title of process.") do |v|
|
27
|
+
options[:title] = v
|
28
|
+
end
|
29
|
+
opt.parse!(ARGV)
|
30
|
+
|
31
|
+
script = ARGV[0]
|
32
|
+
|
33
|
+
if script.nil?
|
34
|
+
script = "main.rb"
|
35
|
+
dir = Dir.pwd
|
36
|
+
loop do
|
37
|
+
if File.exist?(File.join(dir, "main.rb"))
|
38
|
+
script = File.join(dir, "main.rb")
|
39
|
+
break
|
40
|
+
end
|
41
|
+
break if dir == File.dirname(dir)
|
42
|
+
|
43
|
+
dir = File.dirname(dir)
|
44
|
+
end
|
45
|
+
if File.dirname(script) != Dir.pwd
|
46
|
+
Dir.chdir(File.dirname(script))
|
47
|
+
iputs "Changed directory to \e[m#{File.dirname(script)}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
ENV["DISCORB_CLI_FLAG"] = "run"
|
52
|
+
ENV["DISCORB_CLI_OPTIONS"] = JSON.generate(options)
|
53
|
+
|
54
|
+
if options[:token]
|
55
|
+
ENV["DISCORB_CLI_TOKEN"] = ENV.fetch(options[:token], nil)
|
56
|
+
raise "#{options[:token]} is not set." if ENV["DISCORB_CLI_TOKEN"].nil?
|
57
|
+
elsif options[:token].nil? || options[:token] == "-"
|
58
|
+
print "\e[90mPlease enter your token: \e[m"
|
59
|
+
ENV["DISCORB_CLI_TOKEN"] = $stdin.noecho(&:gets).chomp
|
60
|
+
puts ""
|
61
|
+
end
|
62
|
+
|
63
|
+
ENV["DISCORB_CLI_TITLE"] = options[:title]
|
64
|
+
|
65
|
+
if File.exist? script
|
66
|
+
exec "ruby #{script}"
|
67
|
+
else
|
68
|
+
eputs "Could not load script: \e[31m#{script}\e[91m"
|
69
|
+
end
|
data/lib/discorb/exe/setup.rb
CHANGED
@@ -1,55 +1,57 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# description: Setup application commands.
|
4
|
-
require "optparse"
|
5
|
-
require "discorb/utils/colored_puts"
|
6
|
-
|
7
|
-
options = {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
ENV["
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
ENV["
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# description: Setup application commands.
|
4
|
+
require "optparse"
|
5
|
+
require "discorb/utils/colored_puts"
|
6
|
+
|
7
|
+
options = { guilds: nil, script: true }
|
8
|
+
|
9
|
+
opt = OptionParser.new <<~BANNER
|
10
|
+
This command will setup application commands.
|
11
|
+
|
12
|
+
Usage: discorb setup [options] [script]
|
13
|
+
|
14
|
+
script The script to setup.
|
15
|
+
BANNER
|
16
|
+
opt.on(
|
17
|
+
"-g",
|
18
|
+
"--guild ID",
|
19
|
+
Array,
|
20
|
+
"The guild ID to setup, use comma for setup commands in multiple guilds, " \
|
21
|
+
"or `global` for setup global commands."
|
22
|
+
) { |v| options[:guilds] = v }
|
23
|
+
opt.on(
|
24
|
+
"-c",
|
25
|
+
"--clear-guild ID",
|
26
|
+
Array,
|
27
|
+
"The guild ID to clear command, use comma for clear commands in multiple guilds, " \
|
28
|
+
"or `global` for clear global commands."
|
29
|
+
) { |v| options[:clear_guilds] = v }
|
30
|
+
opt.on(
|
31
|
+
"-s",
|
32
|
+
"--[no-]script",
|
33
|
+
"Whether to run `:setup` event. " \
|
34
|
+
"This may be useful if setup script includes operation that shouldn't run twice. Default to true."
|
35
|
+
) { |v| options[:script] = v }
|
36
|
+
opt.parse!(ARGV)
|
37
|
+
|
38
|
+
script = ARGV[0]
|
39
|
+
script ||= "main.rb"
|
40
|
+
ENV["DISCORB_CLI_FLAG"] = "setup"
|
41
|
+
|
42
|
+
ENV["DISCORB_SETUP_GUILDS"] = if options[:guilds] == ["global"]
|
43
|
+
"global"
|
44
|
+
elsif options[:guilds]
|
45
|
+
options[:guilds].join(",")
|
46
|
+
end
|
47
|
+
|
48
|
+
ENV["DISCORB_SETUP_CLEAR_GUILDS"] = options[:clear_guilds]&.join(",")
|
49
|
+
|
50
|
+
ENV["DISCORB_SETUP_SCRIPT"] = options[:script].to_s if options[:script]
|
51
|
+
|
52
|
+
if File.exist? script
|
53
|
+
load script
|
54
|
+
sputs "Successfully set up commands for \e[32m#{script}\e[m."
|
55
|
+
else
|
56
|
+
eputs "Could not load script: \e[31m#{script}\e[m"
|
57
|
+
end
|
data/lib/discorb/exe/show.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# description: Show information of your environment.
|
4
|
-
|
5
|
-
require "etc"
|
6
|
-
require "discorb"
|
7
|
-
|
8
|
-
puts "\e[90m Ruby:\e[m #{RUBY_VERSION}"
|
9
|
-
puts "\e[90m discorb:\e[m #{Discorb::VERSION}"
|
10
|
-
uname = Etc.uname
|
11
|
-
puts "\e[90m System:\e[m #{uname[:sysname]} #{uname[:release]}"
|
12
|
-
puts "\e[90mPlatform:\e[m #{RUBY_PLATFORM}"
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# description: Show information of your environment.
|
4
|
+
|
5
|
+
require "etc"
|
6
|
+
require "discorb"
|
7
|
+
|
8
|
+
puts "\e[90m Ruby:\e[m #{RUBY_VERSION}"
|
9
|
+
puts "\e[90m discorb:\e[m #{Discorb::VERSION}"
|
10
|
+
uname = Etc.uname
|
11
|
+
puts "\e[90m System:\e[m #{uname[:sysname]} #{uname[:release]}"
|
12
|
+
puts "\e[90mPlatform:\e[m #{RUBY_PLATFORM}"
|
data/lib/discorb/extend.rb
CHANGED
@@ -1,45 +1,25 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# rubocop: disable Style/Documentation
|
4
|
-
|
5
|
-
class Time
|
6
|
-
#
|
7
|
-
# Format a time object to a Discord formatted string.
|
8
|
-
#
|
9
|
-
# @param ["f", "F", "d", "D", "t", "T", "R"] type The format to use.
|
10
|
-
#
|
11
|
-
# @return [String] The formatted time.
|
12
|
-
#
|
13
|
-
def to_df(type = nil)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
@object_name ||= "#{self.class}:0x#{object_id.to_s(16)}#{@transient ? " transient" : nil}"
|
27
|
-
|
28
|
-
if @annotation
|
29
|
-
"#{@object_name} #{@annotation}"
|
30
|
-
elsif line = self.backtrace(0, 1)&.first
|
31
|
-
"#{@object_name} #{line}"
|
32
|
-
else
|
33
|
-
@object_name
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def to_s
|
38
|
-
"\#<#{self.description}>"
|
39
|
-
end
|
40
|
-
|
41
|
-
alias inspect to_s
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# rubocop: enable Style/Documentation
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop: disable Style/Documentation
|
4
|
+
|
5
|
+
class Time
|
6
|
+
#
|
7
|
+
# Format a time object to a Discord formatted string.
|
8
|
+
#
|
9
|
+
# @param ["f", "F", "d", "D", "t", "T", "R"] type The format to use.
|
10
|
+
#
|
11
|
+
# @return [String] The formatted time.
|
12
|
+
#
|
13
|
+
def to_df(type = nil)
|
14
|
+
type.nil? ? "<t:#{to_i}>" : "<t:#{to_i}:#{type}>"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# @private
|
19
|
+
module Async
|
20
|
+
class Node
|
21
|
+
alias inspect to_s
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# rubocop: enable Style/Documentation
|
data/lib/discorb/extension.rb
CHANGED
@@ -1,83 +1,89 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Discorb
|
4
|
-
#
|
5
|
-
# Abstract class to make extension.
|
6
|
-
# Include from this module to make your own extension.
|
7
|
-
# @see file:docs/extension.md Extension
|
8
|
-
# @abstract
|
9
|
-
#
|
10
|
-
module Extension
|
11
|
-
def initialize(client)
|
12
|
-
@client = client
|
13
|
-
end
|
14
|
-
|
15
|
-
def events
|
16
|
-
return @events if @events
|
17
|
-
|
18
|
-
ret = {}
|
19
|
-
self.class.events.each do |event, handlers|
|
20
|
-
ret[event] = handlers.map do |handler|
|
21
|
-
Discorb::EventHandler.new(
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
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
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discorb
|
4
|
+
#
|
5
|
+
# Abstract class to make extension.
|
6
|
+
# Include from this module to make your own extension.
|
7
|
+
# @see file:docs/extension.md Extension
|
8
|
+
# @abstract
|
9
|
+
#
|
10
|
+
module Extension
|
11
|
+
def initialize(client)
|
12
|
+
@client = client
|
13
|
+
end
|
14
|
+
|
15
|
+
def events
|
16
|
+
return @events if @events
|
17
|
+
|
18
|
+
ret = {}
|
19
|
+
self.class.events.each do |event, handlers|
|
20
|
+
ret[event] = handlers.map do |handler|
|
21
|
+
Discorb::EventHandler.new(
|
22
|
+
proc do |*args, **kwargs|
|
23
|
+
instance_exec(*args, **kwargs, &handler[2])
|
24
|
+
end,
|
25
|
+
handler[0],
|
26
|
+
handler[1]
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
@events = ret
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.included(base)
|
34
|
+
base.extend(ClassMethods)
|
35
|
+
end
|
36
|
+
|
37
|
+
#
|
38
|
+
# @private
|
39
|
+
# Module for adding class methods to the extension class.
|
40
|
+
#
|
41
|
+
module ClassMethods
|
42
|
+
include Discorb::ApplicationCommand::Handler
|
43
|
+
undef setup_commands
|
44
|
+
|
45
|
+
#
|
46
|
+
# Define a new event.
|
47
|
+
#
|
48
|
+
# @param [Symbol] event_name The name of the event.
|
49
|
+
# @param [Symbol] id The id of the event. Used to delete the event.
|
50
|
+
# @param [Hash] metadata Other metadata.
|
51
|
+
#
|
52
|
+
def event(event_name, id: nil, **metadata, &block)
|
53
|
+
unless event_name.is_a?(Symbol)
|
54
|
+
raise ArgumentError, "Event name must be a symbol"
|
55
|
+
end
|
56
|
+
raise ArgumentError, "block must be given" unless block_given?
|
57
|
+
|
58
|
+
@events[event_name] ||= []
|
59
|
+
metadata[:extension] = name
|
60
|
+
@events[event_name] << [id, metadata, block]
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# Define a new once event.
|
65
|
+
#
|
66
|
+
# @param [Symbol] event_name The name of the event.
|
67
|
+
# @param [Symbol] id The id of the event. Used to delete the event.
|
68
|
+
# @param [Hash] metadata Other metadata.
|
69
|
+
# @param [Proc] block The block to execute when the event is triggered.
|
70
|
+
#
|
71
|
+
def once_event(event_name, id: nil, **metadata, &block)
|
72
|
+
event(event_name, id: id, once: true, **metadata, &block)
|
73
|
+
end
|
74
|
+
|
75
|
+
# @return [Hash{Symbol => Array<Discorb::EventHandler>}] The events of the extension.
|
76
|
+
attr_reader :events
|
77
|
+
# @return [Array<Discorb::ApplicationCommand::Command>] The commands of the extension.
|
78
|
+
attr_reader :commands
|
79
|
+
# @private
|
80
|
+
attr_reader :callable_commands
|
81
|
+
|
82
|
+
def self.extended(klass)
|
83
|
+
klass.instance_variable_set(:@commands, [])
|
84
|
+
klass.instance_variable_set(:@callable_commands, [])
|
85
|
+
klass.instance_variable_set(:@events, {})
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|