discorb 0.16.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitattributes +1 -0
- data/.github/workflows/build_main.yml +2 -2
- data/.github/workflows/build_version.yml +1 -1
- data/.github/workflows/codeql-analysis.yml +1 -1
- data/.github/workflows/lint-push.yml +3 -5
- data/.github/workflows/lint.yml +2 -4
- data/.github/workflows/spec.yml +33 -0
- data/.github/workflows/validate.yml +21 -0
- data/.gitignore +2 -0
- data/.lefthook/commit-msg/validator.rb +5 -0
- data/.rspec +2 -0
- data/.rspec_parallel +2 -0
- data/.rubocop.yml +43 -6
- data/Changelog.md +30 -1
- data/Gemfile +20 -8
- data/Rakefile +226 -98
- data/Steepfile +28 -0
- data/bin/console +3 -3
- data/docs/Examples.md +1 -1
- data/docs/application_command.md +156 -47
- data/docs/cli/irb.md +2 -2
- data/docs/cli/new.md +14 -9
- data/docs/cli/run.md +7 -11
- data/docs/cli.md +17 -10
- data/docs/events.md +247 -213
- data/docs/extension.md +1 -2
- data/docs/faq.md +0 -1
- data/docs/tutorial.md +18 -18
- data/docs/voice_events.md +106 -106
- data/examples/commands/message.rb +68 -0
- data/examples/commands/permission.rb +19 -0
- data/examples/commands/slash.rb +48 -0
- data/examples/commands/user.rb +54 -0
- data/examples/components/authorization_button.rb +4 -3
- data/examples/components/select_menu.rb +6 -3
- data/examples/extension/main.rb +2 -1
- data/examples/extension/message_expander.rb +6 -2
- data/examples/sig/commands/message.rbs +5 -0
- data/examples/simple/eval.rb +3 -2
- data/examples/simple/ping_pong.rb +2 -1
- data/examples/simple/rolepanel.rb +17 -6
- data/examples/simple/shard.rb +3 -2
- data/examples/simple/wait_for_message.rb +4 -1
- data/exe/discorb +33 -18
- data/lefthook.yml +45 -0
- data/lib/discorb/allowed_mentions.rb +2 -1
- data/lib/discorb/app_command/command.rb +130 -72
- data/lib/discorb/app_command/common.rb +25 -0
- data/lib/discorb/app_command/handler.rb +130 -33
- data/lib/discorb/app_command.rb +2 -1
- data/lib/discorb/application.rb +1 -0
- data/lib/discorb/asset.rb +1 -2
- data/lib/discorb/attachment.rb +1 -1
- data/lib/discorb/audit_logs.rb +19 -10
- data/lib/discorb/automod.rb +269 -0
- data/lib/discorb/channel/base.rb +108 -0
- data/lib/discorb/channel/category.rb +32 -0
- data/lib/discorb/channel/container.rb +44 -0
- data/lib/discorb/channel/dm.rb +28 -0
- data/lib/discorb/channel/guild.rb +246 -0
- data/lib/discorb/channel/stage.rb +140 -0
- data/lib/discorb/channel/text.rb +336 -0
- data/lib/discorb/channel/thread.rb +325 -0
- data/lib/discorb/channel/voice.rb +79 -0
- data/lib/discorb/channel.rb +2 -1165
- data/lib/discorb/client.rb +50 -36
- data/lib/discorb/color.rb +37 -60
- data/lib/discorb/common.rb +2 -1
- data/lib/discorb/components/button.rb +2 -1
- data/lib/discorb/components/select_menu.rb +4 -2
- data/lib/discorb/components/text_input.rb +12 -2
- data/lib/discorb/components.rb +1 -1
- data/lib/discorb/dictionary.rb +1 -1
- data/lib/discorb/embed.rb +26 -10
- data/lib/discorb/emoji.rb +31 -4
- data/lib/discorb/emoji_table.rb +4969 -3
- data/lib/discorb/event.rb +29 -4
- data/lib/discorb/exe/about.rb +2 -1
- data/lib/discorb/exe/irb.rb +2 -4
- data/lib/discorb/exe/new.rb +89 -26
- data/lib/discorb/exe/run.rb +8 -22
- data/lib/discorb/exe/setup.rb +25 -12
- data/lib/discorb/exe/show.rb +4 -3
- data/lib/discorb/extend.rb +1 -0
- data/lib/discorb/extension.rb +6 -7
- data/lib/discorb/flag.rb +13 -2
- data/lib/discorb/gateway.rb +79 -589
- data/lib/discorb/gateway_events.rb +638 -0
- data/lib/discorb/guild.rb +318 -67
- data/lib/discorb/guild_template.rb +11 -5
- data/lib/discorb/http.rb +53 -24
- data/lib/discorb/integration.rb +4 -1
- data/lib/discorb/intents.rb +28 -19
- data/lib/discorb/interaction/autocomplete.rb +28 -16
- data/lib/discorb/interaction/command.rb +42 -14
- data/lib/discorb/interaction/components.rb +5 -2
- data/lib/discorb/interaction/modal.rb +0 -1
- data/lib/discorb/interaction/response.rb +125 -26
- data/lib/discorb/interaction/root.rb +13 -13
- data/lib/discorb/interaction.rb +1 -0
- data/lib/discorb/invite.rb +5 -2
- data/lib/discorb/member.rb +28 -8
- data/lib/discorb/message.rb +60 -25
- data/lib/discorb/message_meta.rb +3 -3
- data/lib/discorb/modules.rb +59 -16
- data/lib/discorb/presence.rb +2 -0
- data/lib/discorb/rate_limit.rb +7 -2
- data/lib/discorb/reaction.rb +2 -2
- data/lib/discorb/role.rb +20 -5
- data/lib/discorb/shard.rb +1 -1
- data/lib/discorb/sticker.rb +9 -8
- data/lib/discorb/user.rb +4 -3
- data/lib/discorb/utils/colored_puts.rb +1 -0
- data/lib/discorb/voice_state.rb +6 -2
- data/lib/discorb/webhook.rb +64 -31
- data/lib/discorb.rb +7 -5
- data/po/yard.pot +20 -20
- data/rbs_collection.lock.yaml +88 -0
- data/rbs_collection.yaml +21 -0
- data/sig/async.rbs +11 -0
- data/sig/discorb/activity.rbs +23 -0
- data/sig/discorb/allowed_mentions.rbs +44 -0
- data/sig/discorb/app_command/base.rbs +282 -0
- data/sig/discorb/app_command/handler.rbs +171 -0
- data/sig/discorb/application.rbs +142 -0
- data/sig/discorb/asset.rbs +32 -0
- data/sig/discorb/attachment.rbs +91 -0
- data/sig/discorb/audit_log.rbs +231 -0
- data/sig/discorb/automod.rbs +128 -0
- data/sig/discorb/avatar.rbs +26 -0
- data/sig/discorb/channel/base.rbs +179 -0
- data/sig/discorb/channel/category.rbs +56 -0
- data/sig/discorb/channel/container.rbs +29 -0
- data/sig/discorb/channel/dm.rbs +14 -0
- data/sig/discorb/channel/news.rbs +20 -0
- data/sig/discorb/channel/stage.rbs +77 -0
- data/sig/discorb/channel/text.rbs +158 -0
- data/sig/discorb/channel/thread.rbs +185 -0
- data/sig/discorb/channel/voice.rbs +41 -0
- data/sig/discorb/client.rbs +2495 -0
- data/sig/discorb/color.rbs +142 -0
- data/sig/discorb/component/base.rbs +28 -0
- data/sig/discorb/component/button.rbs +65 -0
- data/sig/discorb/component/select_menu.rbs +107 -0
- data/sig/discorb/component/text_input.rbs +69 -0
- data/sig/discorb/connectable.rbs +8 -0
- data/sig/discorb/custom_emoji.rbs +90 -0
- data/sig/discorb/dictionary.rbs +85 -0
- data/sig/discorb/discord_model.rbs +15 -0
- data/sig/discorb/embed.rbs +279 -0
- data/sig/discorb/emoji.rbs +13 -0
- data/sig/discorb/error.rbs +73 -0
- data/sig/discorb/event_handler.rbs +27 -0
- data/sig/discorb/extension.rbs +1734 -0
- data/sig/discorb/flag.rbs +72 -0
- data/sig/discorb/gateway.rbs +481 -0
- data/sig/discorb/guild.rbs +870 -0
- data/sig/discorb/guild_template.rbs +174 -0
- data/sig/discorb/http.rbs +147 -0
- data/sig/discorb/image.rbs +20 -0
- data/sig/discorb/integration.rbs +118 -0
- data/sig/discorb/intents.rbs +97 -0
- data/sig/discorb/interaction/autocomplete.rbs +9 -0
- data/sig/discorb/interaction/base.rbs +66 -0
- data/sig/discorb/interaction/command.rbs +66 -0
- data/sig/discorb/interaction/message_component.rbs +140 -0
- data/sig/discorb/interaction/modal.rbs +50 -0
- data/sig/discorb/interaction/responder.rbs +157 -0
- data/sig/discorb/invite.rbs +86 -0
- data/sig/discorb/member.rbs +187 -0
- data/sig/discorb/message.rbs +469 -0
- data/sig/discorb/messageable.rbs +153 -0
- data/sig/discorb/partial_emoji.rbs +35 -0
- data/sig/discorb/permissions.rbs +149 -0
- data/sig/discorb/presence.rbs +237 -0
- data/sig/discorb/reaction.rbs +33 -0
- data/sig/discorb/role.rbs +145 -0
- data/sig/discorb/scheduled_event.rbs +148 -0
- data/sig/discorb/shard.rbs +62 -0
- data/sig/discorb/snowflake.rbs +56 -0
- data/sig/discorb/stage_instance.rbs +63 -0
- data/sig/discorb/sticker.rbs +116 -0
- data/sig/discorb/system_channel_flag.rbs +17 -0
- data/sig/discorb/unicode_emoji.rbs +49 -0
- data/sig/discorb/user.rbs +93 -0
- data/sig/discorb/utils.rbs +8 -0
- data/sig/discorb/voice_region.rbs +30 -0
- data/sig/discorb/voice_state.rbs +71 -0
- data/sig/discorb/webhook.rbs +327 -0
- data/sig/discorb/welcome_screen.rbs +78 -0
- data/sig/discorb.rbs +6 -7230
- data/sig/manifest.yaml +3 -0
- data/sig/override.rbs +19 -0
- data/template-replace/files/css/common.css +4 -0
- metadata +102 -6
- data/examples/commands/bookmarker.rb +0 -42
- data/examples/commands/hello.rb +0 -10
- data/examples/commands/inspect.rb +0 -25
data/lib/discorb/client.rb
CHANGED
@@ -54,7 +54,7 @@ module Discorb
|
|
54
54
|
attr_reader :shards
|
55
55
|
# @private
|
56
56
|
# @return [Hash{Discorb::Snowflake => Discorb::ApplicationCommand::Command}] The commands on the top level.
|
57
|
-
attr_reader :
|
57
|
+
attr_reader :callable_commands
|
58
58
|
# @private
|
59
59
|
# @return [{String => Thread::Mutex}] A hash of mutexes.
|
60
60
|
attr_reader :mutex
|
@@ -66,7 +66,7 @@ module Discorb
|
|
66
66
|
# @return [Discorb::Shard] The current shard. This is implemented with Thread variables.
|
67
67
|
# @return [nil] If client has no shard.
|
68
68
|
# @!attribute [r] shard_id
|
69
|
-
# @return [
|
69
|
+
# @return [Integer] The current shard ID. This is implemented with Thread variables.
|
70
70
|
# @return [nil] If client has no shard.
|
71
71
|
# @!attribute [r] logger
|
72
72
|
# @return [Logger] The logger.
|
@@ -81,7 +81,8 @@ module Discorb
|
|
81
81
|
# @param [:debug, :info, :warn, :error, :critical] log_level The log level.
|
82
82
|
# @param [Boolean] wait_until_ready Whether to delay event dispatch until ready.
|
83
83
|
# @param [Boolean] fetch_member Whether to fetch member on ready. This may slow down the client. Default to `false`.
|
84
|
-
# @param [String] title
|
84
|
+
# @param [String] title
|
85
|
+
# The title of the process. `false` to default of ruby, `nil` to `discorb: User#0000`. Default to `nil`.
|
85
86
|
#
|
86
87
|
def initialize(
|
87
88
|
allowed_mentions: nil, intents: nil, message_caches: 1000,
|
@@ -93,7 +94,11 @@ module Discorb
|
|
93
94
|
@intents = (intents or Intents.default)
|
94
95
|
@events = {}
|
95
96
|
@api_version = nil
|
96
|
-
@logger = logger || Logger.new(
|
97
|
+
@logger = logger || Logger.new(
|
98
|
+
$stdout,
|
99
|
+
progname: "discorb",
|
100
|
+
level: Logger::ERROR,
|
101
|
+
)
|
97
102
|
@user = nil
|
98
103
|
@users = Discorb::Dictionary.new
|
99
104
|
@channels = Discorb::Dictionary.new
|
@@ -108,7 +113,7 @@ module Discorb
|
|
108
113
|
@tasks = []
|
109
114
|
@conditions = {}
|
110
115
|
@commands = []
|
111
|
-
@
|
116
|
+
@callable_commands = []
|
112
117
|
@status = :initialized
|
113
118
|
@fetch_member = fetch_member
|
114
119
|
@title = title
|
@@ -206,7 +211,11 @@ module Discorb
|
|
206
211
|
block.call(*args)
|
207
212
|
logger.debug "Dispatched proc with ID #{block.id.inspect}"
|
208
213
|
rescue StandardError, ScriptError => e
|
209
|
-
|
214
|
+
if event_name == :error
|
215
|
+
raise e
|
216
|
+
else
|
217
|
+
dispatch(:error, event_name, args, e)
|
218
|
+
end
|
210
219
|
end
|
211
220
|
end
|
212
221
|
end
|
@@ -276,7 +285,13 @@ module Discorb
|
|
276
285
|
#
|
277
286
|
def fetch_invite(code, with_count: true, with_expiration: true)
|
278
287
|
Async do
|
279
|
-
_resp, data = @http.request(
|
288
|
+
_resp, data = @http.request(
|
289
|
+
Route.new(
|
290
|
+
"/invites/#{code}?with_count=#{with_count}&with_expiration=#{with_expiration}",
|
291
|
+
"//invites/:code",
|
292
|
+
:get
|
293
|
+
)
|
294
|
+
).wait
|
280
295
|
Invite.new(self, data, false)
|
281
296
|
end
|
282
297
|
end
|
@@ -387,6 +402,7 @@ module Discorb
|
|
387
402
|
case ext
|
388
403
|
when Class
|
389
404
|
raise ArgumentError, "#{ext} is not a extension" unless ext < Discorb::Extension
|
405
|
+
|
390
406
|
ins = ext.new(self, ...)
|
391
407
|
when Discorb::Extension
|
392
408
|
ins = ext
|
@@ -415,13 +431,13 @@ module Discorb
|
|
415
431
|
|
416
432
|
cls = ins.class
|
417
433
|
cls.loaded(self, ...) if cls.respond_to? :loaded
|
418
|
-
ins.class.
|
434
|
+
ins.class.callable_commands.each do |cmd|
|
419
435
|
unless cmd.respond_to? :self_replaced
|
420
436
|
cmd.define_singleton_method(:extension) { ins.class.name }
|
421
437
|
cmd.replace_block(ins)
|
422
438
|
cmd.block.define_singleton_method(:self_replaced) { true }
|
423
439
|
end
|
424
|
-
@
|
440
|
+
@callable_commands << cmd
|
425
441
|
end
|
426
442
|
@extensions[ins.class.name] = ins
|
427
443
|
ins
|
@@ -440,9 +456,10 @@ module Discorb
|
|
440
456
|
# @note If the token is nil, you should use `discorb run` with the `-e` or `--env` option.
|
441
457
|
#
|
442
458
|
def run(token = nil, shards: nil, shard_count: nil)
|
443
|
-
token ||= ENV
|
459
|
+
token ||= ENV.fetch("DISCORB_CLI_TOKEN", nil)
|
444
460
|
raise ArgumentError, "Token is not specified, and -e/--env is not specified" if token.nil?
|
445
|
-
|
461
|
+
|
462
|
+
case ENV.fetch("DISCORB_CLI_FLAG", nil)
|
446
463
|
when nil
|
447
464
|
start_client(token, shards: shards, shard_count: shard_count)
|
448
465
|
when "run"
|
@@ -458,7 +475,7 @@ module Discorb
|
|
458
475
|
#
|
459
476
|
def close!
|
460
477
|
if @shards.any?
|
461
|
-
@shards.
|
478
|
+
@shards.each_value(&:close!)
|
462
479
|
else
|
463
480
|
@connection.send_close
|
464
481
|
end
|
@@ -490,18 +507,20 @@ module Discorb
|
|
490
507
|
|
491
508
|
def before_run(token)
|
492
509
|
require "json"
|
493
|
-
options = JSON.parse(ENV
|
510
|
+
options = JSON.parse(ENV.fetch("DISCORB_CLI_OPTIONS", nil), symbolize_names: true)
|
494
511
|
setup_commands(token) if options[:setup]
|
495
512
|
end
|
496
513
|
|
497
514
|
def run_setup(token)
|
498
|
-
guild_ids
|
499
|
-
|
515
|
+
# @type var guild_ids: Array[String] | false
|
516
|
+
guild_ids = false
|
517
|
+
if guilds = ENV.fetch("DISCORB_SETUP_GUILDS", nil)
|
500
518
|
guild_ids = guilds.split(",")
|
501
519
|
end
|
502
520
|
guild_ids = false if guild_ids == ["global"]
|
503
521
|
setup_commands(token, guild_ids: guild_ids).wait
|
504
|
-
|
522
|
+
clear_commands(token, ENV.fetch("DISCORB_SETUP_CLEAR_GUILDS", "").split(","))
|
523
|
+
if ENV.fetch("DISCORB_SETUP_SCRIPT", nil) == "true"
|
505
524
|
@events[:setup]&.each do |event|
|
506
525
|
event.call
|
507
526
|
end
|
@@ -534,8 +553,9 @@ module Discorb
|
|
534
553
|
end
|
535
554
|
|
536
555
|
def session_id=(value)
|
537
|
-
|
538
|
-
|
556
|
+
sid = shard_id
|
557
|
+
if sid
|
558
|
+
@shards[sid].session_id = value
|
539
559
|
else
|
540
560
|
@session_id = value
|
541
561
|
end
|
@@ -552,28 +572,22 @@ module Discorb
|
|
552
572
|
if shards.nil?
|
553
573
|
main_loop(nil)
|
554
574
|
else
|
555
|
-
@shards = shards.
|
556
|
-
Shard.new(self, shard, shard_count, i)
|
575
|
+
@shards = shards.to_h.with_index do |shard, i|
|
576
|
+
[shard, Shard.new(self, shard, shard_count, i)]
|
557
577
|
end
|
558
|
-
@shards[..-1].each_with_index do |shard, i|
|
559
|
-
shard.next_shard = @shards[i + 1]
|
578
|
+
@shards.values[..-1].each_with_index do |shard, i|
|
579
|
+
shard.next_shard = @shards.values[i + 1]
|
560
580
|
end
|
561
|
-
@shards.
|
581
|
+
@shards.each_value { |s| s.thread.join }
|
562
582
|
end
|
563
583
|
end
|
564
584
|
|
565
585
|
def main_loop(shard)
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
set_status(:running, shard)
|
572
|
-
close_condition.signal
|
573
|
-
raise
|
574
|
-
end
|
575
|
-
close_condition.wait
|
576
|
-
main_task.stop
|
586
|
+
set_status(:running, shard)
|
587
|
+
connect_gateway(false).wait
|
588
|
+
rescue StandardError
|
589
|
+
set_status(:closed, shard)
|
590
|
+
raise
|
577
591
|
end
|
578
592
|
|
579
593
|
def main_task
|
@@ -595,13 +609,13 @@ module Discorb
|
|
595
609
|
def set_default_events
|
596
610
|
on :error, override: true do |event_name, _args, e|
|
597
611
|
message = "An error occurred while dispatching #{event_name}:\n#{e.full_message}"
|
598
|
-
logger.error message
|
612
|
+
logger.error message
|
599
613
|
end
|
600
614
|
|
601
615
|
once :standby do
|
602
616
|
next if @title == false
|
603
617
|
|
604
|
-
title = @title || ENV
|
618
|
+
title = @title || ENV.fetch("DISCORB_CLI_TITLE", nil) || "discorb: #{@user}"
|
605
619
|
Process.setproctitle title
|
606
620
|
end
|
607
621
|
end
|
data/lib/discorb/color.rb
CHANGED
@@ -85,7 +85,11 @@ module Discorb
|
|
85
85
|
# @return [Hash{:r, :g, :b => Integer}] A RGB hash.
|
86
86
|
#
|
87
87
|
def to_rgb_hash
|
88
|
-
|
88
|
+
{
|
89
|
+
r: @value / (256 * 256),
|
90
|
+
g: @value / 256 % 256,
|
91
|
+
b: @value % 256,
|
92
|
+
}
|
89
93
|
end
|
90
94
|
|
91
95
|
alias deconstruct_keys to_rgb_hash
|
@@ -131,65 +135,38 @@ module Discorb
|
|
131
135
|
# Create a color from a Discord's color.
|
132
136
|
# Currently these colors are supported:
|
133
137
|
#
|
134
|
-
# | Color
|
135
|
-
#
|
136
|
-
# | `:teal`
|
137
|
-
# | `:dark_teal`
|
138
|
-
# | `:green`
|
139
|
-
# | `:dark_green`
|
140
|
-
# | `:blue`
|
141
|
-
# | `:dark_blue`
|
142
|
-
# | `:purple`
|
143
|
-
# | `:dark_purple`
|
144
|
-
# | `:magenta`
|
145
|
-
# | `:dark_magenta` | `#ad1457`
|
146
|
-
# | `:gold`
|
147
|
-
# | `:dark_gold`
|
148
|
-
# | `:orange`
|
149
|
-
# | `:dark_orange`
|
150
|
-
# | `:red`
|
151
|
-
# | `:dark_red`
|
152
|
-
# | `:lighter_grey` | `#95a5a6`
|
153
|
-
# | `:lighter_gray` | `#95a5a6`
|
154
|
-
# | `:dark_grey`
|
155
|
-
# | `:dark_gray`
|
156
|
-
# | `:light_grey`
|
157
|
-
# | `:light_gray`
|
158
|
-
# | `:darker_grey`
|
159
|
-
# | `:darker_gray`
|
160
|
-
# | `:og_blurple`
|
161
|
-
# | `:blurple`
|
162
|
-
# | `:greyple`
|
163
|
-
# | `:dark_theme`
|
164
|
-
# | `:fuchsia`
|
165
|
-
# | `:
|
166
|
-
# | `:green` | `#2ecc71` |
|
167
|
-
# | `:dark_green` | `#1f8b4c` |
|
168
|
-
# | `:blue` | `#3498db` |
|
169
|
-
# | `:dark_blue` | `#206694` |
|
170
|
-
# | `:purple` | `#9b59b6` |
|
171
|
-
# | `:dark_purple` | `#71368a` |
|
172
|
-
# | `:magenta` | `#e91e63` |
|
173
|
-
# | `:dark_magenta` | `#ad1457` |
|
174
|
-
# | `:gold` | `#f1c40f` |
|
175
|
-
# | `:dark_gold` | `#c27c0e` |
|
176
|
-
# | `:orange` | `#e67e22` |
|
177
|
-
# | `:dark_orange` | `#a84300` |
|
178
|
-
# | `:red` | `#e74c3c` |
|
179
|
-
# | `:dark_red` | `#992d22` |
|
180
|
-
# | `:lighter_grey` | `#95a5a6` |
|
181
|
-
# | `:lighter_gray` | `#95a5a6` |
|
182
|
-
# | `:dark_grey` | `#607d8b` |
|
183
|
-
# | `:dark_gray` | `#607d8b` |
|
184
|
-
# | `:light_grey` | `#979c9f` |
|
185
|
-
# | `:light_gray` | `#979c9f` |
|
186
|
-
# | `:darker_grey` | `#546e7a` |
|
187
|
-
# | `:darker_gray` | `#546e7a` |
|
188
|
-
# | `:og_blurple` | `#7289da` |
|
189
|
-
# | `:blurple` | `#5865f2` |
|
190
|
-
# | `:greyple` | `#99aab5` |
|
191
|
-
# | `:dark_theme` | `#36393f` |
|
192
|
-
# | `:fuchsia` | `#eb459e` |
|
138
|
+
# | Color name | Color code |
|
139
|
+
# |-----------------|------------|
|
140
|
+
# | `:teal` | `#1abc9c` |
|
141
|
+
# | `:dark_teal` | `#11806a` |
|
142
|
+
# | `:green` | `#2ecc71` |
|
143
|
+
# | `:dark_green` | `#1f8b4c` |
|
144
|
+
# | `:blue` | `#3498db` |
|
145
|
+
# | `:dark_blue` | `#206694` |
|
146
|
+
# | `:purple` | `#9b59b6` |
|
147
|
+
# | `:dark_purple` | `#71368a` |
|
148
|
+
# | `:magenta` | `#e91e63` |
|
149
|
+
# | `:dark_magenta` | `#ad1457` |
|
150
|
+
# | `:gold` | `#f1c40f` |
|
151
|
+
# | `:dark_gold` | `#c27c0e` |
|
152
|
+
# | `:orange` | `#e67e22` |
|
153
|
+
# | `:dark_orange` | `#a84300` |
|
154
|
+
# | `:red` | `#e74c3c` |
|
155
|
+
# | `:dark_red` | `#992d22` |
|
156
|
+
# | `:lighter_grey` | `#95a5a6` |
|
157
|
+
# | `:lighter_gray` | `#95a5a6` |
|
158
|
+
# | `:dark_grey` | `#607d8b` |
|
159
|
+
# | `:dark_gray` | `#607d8b` |
|
160
|
+
# | `:light_grey` | `#979c9f` |
|
161
|
+
# | `:light_gray` | `#979c9f` |
|
162
|
+
# | `:darker_grey` | `#546e7a` |
|
163
|
+
# | `:darker_gray` | `#546e7a` |
|
164
|
+
# | `:og_blurple` | `#7289da` |
|
165
|
+
# | `:blurple` | `#5865f2` |
|
166
|
+
# | `:greyple` | `#99aab5` |
|
167
|
+
# | `:dark_theme` | `#36393f` |
|
168
|
+
# | `:fuchsia` | `#eb459e` |
|
169
|
+
# | `:yellow` | `#fee75c` |
|
193
170
|
#
|
194
171
|
# @param [Symbol] color A Discord color name.
|
195
172
|
#
|
data/lib/discorb/common.rb
CHANGED
@@ -4,7 +4,7 @@ module Discorb
|
|
4
4
|
# @return [String] The API base URL.
|
5
5
|
API_BASE_URL = "https://discord.com/api/v10"
|
6
6
|
# @return [String] The version of discorb.
|
7
|
-
VERSION = "0.
|
7
|
+
VERSION = "0.18.0"
|
8
8
|
# @return [Array<Integer>] The version array of discorb.
|
9
9
|
VERSION_ARRAY = VERSION.split(".").map(&:to_i).freeze
|
10
10
|
# @return [String] The user agent for the bot.
|
@@ -152,6 +152,7 @@ module Discorb
|
|
152
152
|
def major_param
|
153
153
|
param_type = @key.split("/").find { |k| k.start_with?(":") }
|
154
154
|
return "" unless param_type
|
155
|
+
|
155
156
|
param = url.gsub(API_BASE_URL, "").split("/")[@key.split("/").index(param_type) - 1]
|
156
157
|
%w[:channel_id :guild_id :webhook_id].include?(param_type) ? param : ""
|
157
158
|
end
|
@@ -53,7 +53,8 @@ module Discorb
|
|
53
53
|
#
|
54
54
|
# Converts the button to a hash.
|
55
55
|
#
|
56
|
-
# @see https://discord.com/developers/docs/interactions/message-components#button-object-button-structure
|
56
|
+
# @see https://discord.com/developers/docs/interactions/message-components#button-object-button-structure
|
57
|
+
# Official Discord API docs
|
57
58
|
# @return [Hash] A hash representation of the button.
|
58
59
|
#
|
59
60
|
def to_hash
|
@@ -37,7 +37,8 @@ module Discorb
|
|
37
37
|
#
|
38
38
|
# Converts the select menu to a hash.
|
39
39
|
#
|
40
|
-
# @see https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-menu-structure
|
40
|
+
# @see https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-menu-structure
|
41
|
+
# Official Discord API docs
|
41
42
|
# @return [Hash] A hash representation of the select menu.
|
42
43
|
#
|
43
44
|
def to_hash
|
@@ -109,7 +110,8 @@ module Discorb
|
|
109
110
|
#
|
110
111
|
# Converts the option to a hash.
|
111
112
|
#
|
112
|
-
# @see https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-option-structure
|
113
|
+
# @see https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-option-structure
|
114
|
+
# Official Discord API docs
|
113
115
|
# @return [Hash] Hash representation of the option.
|
114
116
|
#
|
115
117
|
def to_hash
|
@@ -40,7 +40,16 @@ module Discorb
|
|
40
40
|
# @param [String, nil] value The prefilled value of the text input.
|
41
41
|
# @param [String, nil] placeholder The placeholder of the text input.
|
42
42
|
#
|
43
|
-
def initialize(
|
43
|
+
def initialize(
|
44
|
+
label,
|
45
|
+
custom_id,
|
46
|
+
style,
|
47
|
+
min_length: nil,
|
48
|
+
max_length: nil,
|
49
|
+
required: false,
|
50
|
+
value: nil,
|
51
|
+
placeholder: nil
|
52
|
+
)
|
44
53
|
@label = label
|
45
54
|
@custom_id = custom_id
|
46
55
|
@style = style
|
@@ -54,7 +63,8 @@ module Discorb
|
|
54
63
|
#
|
55
64
|
# Converts the select menu to a hash.
|
56
65
|
#
|
57
|
-
# @see https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-structure
|
66
|
+
# @see https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-structure
|
67
|
+
# Official Discord API docs
|
58
68
|
# @return [Hash] A hash representation of the text input.
|
59
69
|
#
|
60
70
|
def to_hash
|
data/lib/discorb/components.rb
CHANGED
data/lib/discorb/dictionary.rb
CHANGED
data/lib/discorb/embed.rb
CHANGED
@@ -35,7 +35,7 @@ module Discorb
|
|
35
35
|
#
|
36
36
|
# @param [String] title The title of embed.
|
37
37
|
# @param [String] description The description of embed.
|
38
|
-
# @param [Discorb::Color] color The color of embed.
|
38
|
+
# @param [Discorb::Color, Integer] color The color of embed.
|
39
39
|
# @param [String] url The url of embed.
|
40
40
|
# @param [Time] timestamp The timestamp of embed.
|
41
41
|
# @param [Discorb::Embed::Author] author The author field of embed.
|
@@ -44,19 +44,29 @@ module Discorb
|
|
44
44
|
# @param [Discorb::Embed::Image, String] image The image of embed.
|
45
45
|
# @param [Discorb::Embed::Thumbnail, String] thumbnail The thumbnail of embed.
|
46
46
|
#
|
47
|
-
def initialize(
|
48
|
-
|
47
|
+
def initialize(
|
48
|
+
title = nil,
|
49
|
+
description = nil,
|
50
|
+
color: nil,
|
51
|
+
url: nil,
|
52
|
+
timestamp: nil,
|
53
|
+
author: nil,
|
54
|
+
fields: nil,
|
55
|
+
footer: nil,
|
56
|
+
image: nil,
|
57
|
+
thumbnail: nil
|
58
|
+
)
|
49
59
|
@title = title
|
50
60
|
@description = description
|
51
61
|
@url = url
|
52
62
|
@timestamp = timestamp
|
53
|
-
@color = color
|
63
|
+
@color = color && (color.is_a?(Color) ? color : Color.new(color))
|
54
64
|
@author = author
|
55
65
|
@fields = fields || []
|
56
66
|
@footer = footer
|
57
67
|
@image = image && (image.is_a?(String) ? Image.new(image) : image)
|
58
68
|
@thumbnail = thumbnail && (thumbnail.is_a?(String) ? Thumbnail.new(thumbnail) : thumbnail)
|
59
|
-
@type =
|
69
|
+
@type = :rich
|
60
70
|
end
|
61
71
|
|
62
72
|
#
|
@@ -103,6 +113,7 @@ module Discorb
|
|
103
113
|
# @return [Hash] Converted embed.
|
104
114
|
#
|
105
115
|
def to_hash
|
116
|
+
# @type var ret: Hash[untyped, untyped]
|
106
117
|
ret = { type: "rich" }
|
107
118
|
ret[:title] = @title if @title
|
108
119
|
ret[:description] = @description if @description
|
@@ -161,7 +172,8 @@ module Discorb
|
|
161
172
|
#
|
162
173
|
# Convert author to hash.
|
163
174
|
#
|
164
|
-
# @see https://discord.com/developers/docs/resources/channel#embed-object-embed-author-structure
|
175
|
+
# @see https://discord.com/developers/docs/resources/channel#embed-object-embed-author-structure
|
176
|
+
# Offical Discord API Docs
|
165
177
|
# @return [Hash] Converted author.
|
166
178
|
#
|
167
179
|
def to_hash
|
@@ -193,7 +205,8 @@ module Discorb
|
|
193
205
|
#
|
194
206
|
# Convert footer to hash.
|
195
207
|
#
|
196
|
-
# @see https://discord.com/developers/docs/resources/channel#embed-object-embed-footer-structure
|
208
|
+
# @see https://discord.com/developers/docs/resources/channel#embed-object-embed-footer-structure
|
209
|
+
# Offical Discord API Docs
|
197
210
|
# @return [Hash] Converted footer.
|
198
211
|
#
|
199
212
|
def to_hash
|
@@ -231,7 +244,8 @@ module Discorb
|
|
231
244
|
#
|
232
245
|
# Convert field to hash.
|
233
246
|
#
|
234
|
-
# @see https://discord.com/developers/docs/resources/channel#embed-object-embed-field-structure
|
247
|
+
# @see https://discord.com/developers/docs/resources/channel#embed-object-embed-field-structure
|
248
|
+
# Offical Discord API Docs
|
235
249
|
# @return [Hash] Converted field.
|
236
250
|
#
|
237
251
|
def to_hash
|
@@ -279,7 +293,8 @@ module Discorb
|
|
279
293
|
#
|
280
294
|
# Convert image to hash for sending.
|
281
295
|
#
|
282
|
-
# @see https://discord.com/developers/docs/resources/channel#embed-object-embed-image-structure
|
296
|
+
# @see https://discord.com/developers/docs/resources/channel#embed-object-embed-image-structure
|
297
|
+
# Offical Discord API Docs
|
283
298
|
# @return [Hash] Converted image.
|
284
299
|
#
|
285
300
|
def to_hash
|
@@ -323,7 +338,8 @@ module Discorb
|
|
323
338
|
#
|
324
339
|
# Convert thumbnail to hash for sending.
|
325
340
|
#
|
326
|
-
# @see https://discord.com/developers/docs/resources/channel#embed-object-embed-thumbnail-structure
|
341
|
+
# @see https://discord.com/developers/docs/resources/channel#embed-object-embed-thumbnail-structure
|
342
|
+
# Offical Discord API Docs
|
327
343
|
# @return [Hash] Converted thumbnail.
|
328
344
|
#
|
329
345
|
def to_hash
|
data/lib/discorb/emoji.rb
CHANGED
@@ -29,7 +29,7 @@ module Discorb
|
|
29
29
|
attr_reader :roles
|
30
30
|
# @return [Discorb::User] The user that created this emoji.
|
31
31
|
attr_reader :user
|
32
|
-
# @return [
|
32
|
+
# @return [Discorb::Guild] The guild that owns this emoji.
|
33
33
|
attr_reader :guild
|
34
34
|
# @return [Boolean] whether the emoji is managed by integration (ex: Twitch).
|
35
35
|
attr_reader :managed
|
@@ -103,7 +103,10 @@ module Discorb
|
|
103
103
|
payload = {}
|
104
104
|
payload[:name] = name if name != Discorb::Unset
|
105
105
|
payload[:roles] = roles.map { |r| Discorb::Utils.try(r, :id) } if roles != Discorb::Unset
|
106
|
-
@client.http.request(
|
106
|
+
@client.http.request(
|
107
|
+
Route.new("/guilds/#{@guild.id}/emojis/#{@id}", "//guilds/:guild_id/emojis/:emoji_id",
|
108
|
+
:patch), payload, audit_log_reason: reason,
|
109
|
+
)
|
107
110
|
self
|
108
111
|
end
|
109
112
|
end
|
@@ -120,7 +123,10 @@ module Discorb
|
|
120
123
|
#
|
121
124
|
def delete!(reason: nil)
|
122
125
|
Async do
|
123
|
-
@client.http.request(
|
126
|
+
@client.http.request(
|
127
|
+
Route.new("/guilds/#{@guild.id}/emojis/#{@id}", "//guilds/:guild_id/emojis/:emoji_id",
|
128
|
+
:delete), {}, audit_log_reason: reason,
|
129
|
+
).wait
|
124
130
|
@available = false
|
125
131
|
self
|
126
132
|
end
|
@@ -230,10 +236,31 @@ module Discorb
|
|
230
236
|
elsif EmojiTable::UNICODE_TO_DISCORD.key?(name)
|
231
237
|
@name = EmojiTable::UNICODE_TO_DISCORD[name][0]
|
232
238
|
@value = name
|
239
|
+
elsif EmojiTable::SKIN_TONES.any? { |t| name.include?(t) }
|
240
|
+
name2 = name.dup
|
241
|
+
EmojiTable::SKIN_TONES.each.with_index do |t, i|
|
242
|
+
next unless name2.include?(t)
|
243
|
+
|
244
|
+
@skin_tone = i
|
245
|
+
name2.sub!(t, "")
|
246
|
+
break
|
247
|
+
end
|
248
|
+
raise ArgumentError, "Invalid skin tone: #{tone}" unless @skin_tone
|
249
|
+
|
250
|
+
@name = EmojiTable::UNICODE_TO_DISCORD[name2].first
|
251
|
+
@value = name
|
233
252
|
else
|
234
253
|
raise ArgumentError, "No such emoji: #{name}"
|
235
254
|
end
|
236
|
-
|
255
|
+
if tone.positive?
|
256
|
+
unless @value = EmojiTable::DISCORD_TO_UNICODE["#{name}_tone#{tone}"]
|
257
|
+
raise ArgumentError,
|
258
|
+
"Invalid skin tone for emoji: #{name}"
|
259
|
+
end
|
260
|
+
|
261
|
+
@name = "#{name}_tone#{tone}"
|
262
|
+
@skin_tone = tone
|
263
|
+
end
|
237
264
|
end
|
238
265
|
|
239
266
|
# @return [String] The unicode string of the emoji.
|