discorb 0.16.0 → 0.18.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/.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/event.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
module Discorb
|
|
3
4
|
#
|
|
4
5
|
# Represents an event in guild.
|
|
@@ -38,6 +39,7 @@ module Discorb
|
|
|
38
39
|
class Metadata
|
|
39
40
|
# @return [String, nil] The location of the event. Only present if the event is a external event.
|
|
40
41
|
attr_reader :location
|
|
42
|
+
|
|
41
43
|
# @!visibility private
|
|
42
44
|
def initialize(data)
|
|
43
45
|
@location = data[:location]
|
|
@@ -137,6 +139,7 @@ module Discorb
|
|
|
137
139
|
payload = case type == Discorb::Unset ? @entity_type : type
|
|
138
140
|
when :stage_instance
|
|
139
141
|
raise ArgumentError, "channel must be provided for stage_instance events" unless channel
|
|
142
|
+
|
|
140
143
|
{
|
|
141
144
|
name: name,
|
|
142
145
|
description: description,
|
|
@@ -149,6 +152,7 @@ module Discorb
|
|
|
149
152
|
}.reject { |_, v| v == Discorb::Unset }
|
|
150
153
|
when :voice
|
|
151
154
|
raise ArgumentError, "channel must be provided for voice events" unless channel
|
|
155
|
+
|
|
152
156
|
{
|
|
153
157
|
name: name,
|
|
154
158
|
description: description,
|
|
@@ -162,6 +166,7 @@ module Discorb
|
|
|
162
166
|
when :external
|
|
163
167
|
raise ArgumentError, "location must be provided for external events" unless location
|
|
164
168
|
raise ArgumentError, "end_time must be provided for external events" unless end_time
|
|
169
|
+
|
|
165
170
|
{
|
|
166
171
|
name: name,
|
|
167
172
|
description: description,
|
|
@@ -178,7 +183,13 @@ module Discorb
|
|
|
178
183
|
else
|
|
179
184
|
raise ArgumentError, "Invalid scheduled event type: #{type}"
|
|
180
185
|
end
|
|
181
|
-
@client.http.request(
|
|
186
|
+
@client.http.request(
|
|
187
|
+
Route.new(
|
|
188
|
+
"/guilds/#{@guild_id}/scheduled-events/#{@id}",
|
|
189
|
+
"//guilds/:guild_id/scheduled-events/:scheduled_event_id",
|
|
190
|
+
:patch
|
|
191
|
+
), payload
|
|
192
|
+
).wait
|
|
182
193
|
end
|
|
183
194
|
end
|
|
184
195
|
|
|
@@ -215,7 +226,8 @@ module Discorb
|
|
|
215
226
|
#
|
|
216
227
|
def delete!
|
|
217
228
|
Async do
|
|
218
|
-
@client.http.request(Route.new("/guilds/#{@guild_id}/scheduled-events/#{@id}",
|
|
229
|
+
@client.http.request(Route.new("/guilds/#{@guild_id}/scheduled-events/#{@id}",
|
|
230
|
+
"//guilds/:guild_id/scheduled-events/:scheduled_event_id", :delete)).wait
|
|
219
231
|
end
|
|
220
232
|
end
|
|
221
233
|
|
|
@@ -241,8 +253,15 @@ module Discorb
|
|
|
241
253
|
after = 0
|
|
242
254
|
res = []
|
|
243
255
|
loop do
|
|
244
|
-
_resp, users = @client.http.request(
|
|
256
|
+
_resp, users = @client.http.request(
|
|
257
|
+
Route.new(
|
|
258
|
+
"/guilds/#{@guild_id}/scheduled-events/#{@id}/users?limit=100&after=#{after}&with_member=true",
|
|
259
|
+
"//guilds/:guild_id/scheduled-events/:scheduled_event_id/users",
|
|
260
|
+
:get
|
|
261
|
+
)
|
|
262
|
+
).wait
|
|
245
263
|
break if users.empty?
|
|
264
|
+
|
|
246
265
|
res += users.map { |u| Member.new(@client, @guild_id, u[:user], u[:member]) }
|
|
247
266
|
after = users.last[:user][:id]
|
|
248
267
|
end
|
|
@@ -254,7 +273,13 @@ module Discorb
|
|
|
254
273
|
after: Discorb::Utils.try(after, :id),
|
|
255
274
|
with_member: with_member,
|
|
256
275
|
}.filter { |_k, v| !v.nil? }.to_h
|
|
257
|
-
_resp, messages = @client.http.request(
|
|
276
|
+
_resp, messages = @client.http.request(
|
|
277
|
+
Route.new(
|
|
278
|
+
"/channels/#{channel_id.wait}/messages?#{URI.encode_www_form(params)}",
|
|
279
|
+
"//channels/:channel_id/messages",
|
|
280
|
+
:get
|
|
281
|
+
)
|
|
282
|
+
).wait
|
|
258
283
|
messages.map { |m| Message.new(@client, m.merge({ guild_id: @guild_id.to_s })) }
|
|
259
284
|
end
|
|
260
285
|
end
|
data/lib/discorb/exe/about.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
# description: Show information of discorb.
|
|
3
4
|
|
|
4
5
|
puts " disco\e[31mrb\e[m - A new Discord API wrapper in Ruby. \n\n"
|
|
@@ -12,5 +13,5 @@ informations = {
|
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
informations.each do |key, value|
|
|
15
|
-
puts "\e[90m#{key.rjust(informations.keys.map(&:
|
|
16
|
+
puts "\e[90m#{key.rjust(informations.keys.map(&:length).max)}:\e[m #{value}"
|
|
16
17
|
end
|
data/lib/discorb/exe/irb.rb
CHANGED
|
@@ -10,8 +10,6 @@ require "optparse"
|
|
|
10
10
|
intents_value = Discorb::Intents.all.value
|
|
11
11
|
token_file = "token"
|
|
12
12
|
|
|
13
|
-
ARGV.delete_at 0
|
|
14
|
-
|
|
15
13
|
opt = OptionParser.new <<~BANNER
|
|
16
14
|
This command will start an interactive Ruby shell with connected client.
|
|
17
15
|
|
|
@@ -43,7 +41,7 @@ client.on :standby do
|
|
|
43
41
|
|
|
44
42
|
puts <<~FIRST_MESSAGE
|
|
45
43
|
Running on \e[31mRuby #{RUBY_VERSION}\e[m, disco\e[31mrb #{Discorb::VERSION}\e[m
|
|
46
|
-
|
|
44
|
+
Type \e[90mdirb_help\e[m to help.
|
|
47
45
|
FIRST_MESSAGE
|
|
48
46
|
|
|
49
47
|
binding.irb
|
|
@@ -55,7 +53,7 @@ client.on :message do |message|
|
|
|
55
53
|
$messages << message
|
|
56
54
|
end
|
|
57
55
|
|
|
58
|
-
token = ENV
|
|
56
|
+
token = ENV.fetch("DISCORD_BOT_TOKEN", nil) || ENV.fetch("DISCORD_TOKEN", nil)
|
|
59
57
|
if token.nil?
|
|
60
58
|
if File.exist?(token_file)
|
|
61
59
|
token = File.read(token_file)
|
data/lib/discorb/exe/new.rb
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
# description: Make files for the discorb project.
|
|
3
4
|
|
|
4
5
|
require "optparse"
|
|
5
6
|
require "discorb"
|
|
7
|
+
require "pathname"
|
|
6
8
|
require_relative "../utils/colored_puts"
|
|
7
9
|
|
|
8
10
|
$path = Dir.pwd
|
|
@@ -10,10 +12,10 @@ $path = Dir.pwd
|
|
|
10
12
|
# @private
|
|
11
13
|
FILES = {
|
|
12
14
|
"main.rb" => <<~'RUBY',
|
|
13
|
-
|
|
14
|
-
require "dotenv"
|
|
15
|
+
# frozen_string_literal: true
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
require "discorb"
|
|
18
|
+
require "dotenv/load" # Load environment variables from .env file.
|
|
17
19
|
|
|
18
20
|
client = Discorb::Client.new # Create client for connecting to Discord
|
|
19
21
|
|
|
@@ -23,8 +25,26 @@ FILES = {
|
|
|
23
25
|
|
|
24
26
|
client.run ENV["%<token>s"] # Starts client
|
|
25
27
|
RUBY
|
|
28
|
+
"main.rb_nc" => <<~'RUBY',
|
|
29
|
+
# frozen_string_literal: true
|
|
30
|
+
|
|
31
|
+
require "discorb"
|
|
32
|
+
require "dotenv/load"
|
|
33
|
+
|
|
34
|
+
client = Discorb::Client.new
|
|
35
|
+
|
|
36
|
+
client.once :standby do
|
|
37
|
+
puts "Logged in as #{client.user}"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
client.run ENV["%<token>s"]
|
|
41
|
+
RUBY
|
|
26
42
|
".env" => <<~BASH,
|
|
27
|
-
|
|
43
|
+
# Put your token after `%<token>s=`
|
|
44
|
+
%<token>s=
|
|
45
|
+
BASH
|
|
46
|
+
".env_nc" => <<~BASH,
|
|
47
|
+
%<token>s=
|
|
28
48
|
BASH
|
|
29
49
|
".gitignore" => <<~GITIGNORE,
|
|
30
50
|
*.gem
|
|
@@ -38,13 +58,13 @@ FILES = {
|
|
|
38
58
|
/test/tmp/
|
|
39
59
|
/test/version_tmp/
|
|
40
60
|
/tmp/
|
|
41
|
-
|
|
61
|
+
|
|
42
62
|
# Used by dotenv library to load environment variables.
|
|
43
63
|
.env
|
|
44
|
-
|
|
64
|
+
|
|
45
65
|
# Ignore Byebug command history file.
|
|
46
66
|
.byebug_history
|
|
47
|
-
|
|
67
|
+
|
|
48
68
|
## Specific to RubyMotion:
|
|
49
69
|
.dat*
|
|
50
70
|
.repl_history
|
|
@@ -52,7 +72,7 @@ FILES = {
|
|
|
52
72
|
*.bridgesupport
|
|
53
73
|
build-iPhoneOS/
|
|
54
74
|
build-iPhoneSimulator/
|
|
55
|
-
|
|
75
|
+
|
|
56
76
|
## Specific to RubyMotion (use of CocoaPods):
|
|
57
77
|
#
|
|
58
78
|
# We recommend against adding the Pods directory to your .gitignore. However
|
|
@@ -60,33 +80,68 @@ FILES = {
|
|
|
60
80
|
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
|
61
81
|
#
|
|
62
82
|
# vendor/Pods/
|
|
63
|
-
|
|
83
|
+
|
|
64
84
|
## Documentation cache and generated files:
|
|
65
85
|
/.yardoc/
|
|
66
86
|
/_yardoc/
|
|
67
87
|
/doc/
|
|
68
88
|
/rdoc/
|
|
69
|
-
|
|
89
|
+
|
|
70
90
|
## Environment normalization:
|
|
71
91
|
/.bundle/
|
|
72
92
|
/vendor/bundle
|
|
73
93
|
/lib/bundler/man/
|
|
74
|
-
|
|
94
|
+
|
|
75
95
|
# for a library or gem, you might want to ignore these files since the code is
|
|
76
96
|
# intended to run in multiple environments; otherwise, check them in:
|
|
77
97
|
# Gemfile.lock
|
|
78
98
|
# .ruby-version
|
|
79
99
|
# .ruby-gemset
|
|
80
|
-
|
|
100
|
+
|
|
81
101
|
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
82
102
|
.rvmrc
|
|
83
|
-
|
|
103
|
+
|
|
84
104
|
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
|
85
105
|
# .rubocop-https?--*
|
|
86
106
|
|
|
87
107
|
# This gitignore is from github/gitignore.
|
|
88
108
|
# https://github.com/github/gitignore/blob/master/Ruby.gitignore
|
|
89
109
|
GITIGNORE
|
|
110
|
+
".gitignore_nc" => <<~GITIGNORE,
|
|
111
|
+
*.gem
|
|
112
|
+
*.rbc
|
|
113
|
+
/.config
|
|
114
|
+
/coverage/
|
|
115
|
+
/InstalledFiles
|
|
116
|
+
/pkg/
|
|
117
|
+
/spec/reports/
|
|
118
|
+
/spec/examples.txt
|
|
119
|
+
/test/tmp/
|
|
120
|
+
/test/version_tmp/
|
|
121
|
+
/tmp/
|
|
122
|
+
|
|
123
|
+
.env
|
|
124
|
+
|
|
125
|
+
.byebug_history
|
|
126
|
+
|
|
127
|
+
.dat*
|
|
128
|
+
.repl_history
|
|
129
|
+
build/
|
|
130
|
+
*.bridgesupport
|
|
131
|
+
build-iPhoneOS/
|
|
132
|
+
build-iPhoneSimulator/
|
|
133
|
+
|
|
134
|
+
/.yardoc/
|
|
135
|
+
/_yardoc/
|
|
136
|
+
/doc/
|
|
137
|
+
/rdoc/
|
|
138
|
+
|
|
139
|
+
/.bundle/
|
|
140
|
+
/vendor/bundle
|
|
141
|
+
/lib/bundler/man/
|
|
142
|
+
|
|
143
|
+
.rvmrc
|
|
144
|
+
GITIGNORE
|
|
90
145
|
"Gemfile" => <<~RUBY,
|
|
91
146
|
# frozen_string_literal: true
|
|
92
147
|
|
|
@@ -96,6 +151,8 @@ FILES = {
|
|
|
96
151
|
|
|
97
152
|
gem "discorb", "~> #{Discorb::VERSION}"
|
|
98
153
|
gem "dotenv", "~> 2.7"
|
|
154
|
+
|
|
155
|
+
ruby "~> #{RUBY_VERSION.split(".")[0]}.#{RUBY_VERSION.split(".")[1]}"
|
|
99
156
|
RUBY
|
|
100
157
|
".env.sample" => <<~BASH,
|
|
101
158
|
%<token>s=
|
|
@@ -129,14 +186,16 @@ FILES = {
|
|
|
129
186
|
|
|
130
187
|
TODO: Write your bot's license here.
|
|
131
188
|
See https://choosealicense.com/ for more information.
|
|
132
|
-
https://rubygems.org/gems/license-cli may be useful.
|
|
133
189
|
|
|
134
190
|
MARKDOWN
|
|
135
191
|
}.freeze
|
|
136
192
|
|
|
137
193
|
# @private
|
|
138
194
|
def create_file(name)
|
|
139
|
-
|
|
195
|
+
template_name = name
|
|
196
|
+
template_name += "_nc" if !$values[:comment] && FILES.key?(name + "_nc")
|
|
197
|
+
content = format(FILES[template_name], token: $values[:token], name: $values[:name])
|
|
198
|
+
File.write($path + "/#{name}", content, mode: "wb")
|
|
140
199
|
end
|
|
141
200
|
|
|
142
201
|
# @private
|
|
@@ -152,7 +211,7 @@ def bundle_init
|
|
|
152
211
|
iputs "Initializing bundle..."
|
|
153
212
|
create_file("Gemfile")
|
|
154
213
|
iputs "Installing gems..."
|
|
155
|
-
system "bundle install"
|
|
214
|
+
system({ "BUNDLE_GEMFILE" => nil }, "bundle install", chdir: $path)
|
|
156
215
|
sputs "Installed gems.\n"
|
|
157
216
|
end
|
|
158
217
|
|
|
@@ -160,12 +219,8 @@ end
|
|
|
160
219
|
def git_init
|
|
161
220
|
create_file(".gitignore")
|
|
162
221
|
iputs "Initializing git repository..."
|
|
163
|
-
system "git init"
|
|
164
|
-
|
|
165
|
-
system "git commit -m \"Initial commit\""
|
|
166
|
-
sputs "Initialized repository, use " \
|
|
167
|
-
"\e[32mgit commit --amend -m '...'\e[92m" \
|
|
168
|
-
" to change commit message of initial commit.\n"
|
|
222
|
+
system "git init", chdir: $path
|
|
223
|
+
sputs "Initialized repository.\n"
|
|
169
224
|
end
|
|
170
225
|
|
|
171
226
|
# @private
|
|
@@ -191,6 +246,7 @@ $values = {
|
|
|
191
246
|
token: "TOKEN",
|
|
192
247
|
descs: false,
|
|
193
248
|
name: nil,
|
|
249
|
+
comment: true,
|
|
194
250
|
}
|
|
195
251
|
|
|
196
252
|
opt.on("--[no-]bundle", "Whether to use bundle. Default to true.") do |v|
|
|
@@ -205,6 +261,10 @@ opt.on("--[no-]descs", "Whether to put some file for description. Default to fal
|
|
|
205
261
|
$values[:descs] = v
|
|
206
262
|
end
|
|
207
263
|
|
|
264
|
+
opt.on("--[no-]comment", "Whether to write comment. Default to true.") do |v|
|
|
265
|
+
$values[:comment] = v
|
|
266
|
+
end
|
|
267
|
+
|
|
208
268
|
opt.on("-t NAME", "--token NAME", "The name of token environment variable. Default to TOKEN.") do |v|
|
|
209
269
|
$values[:token] = v
|
|
210
270
|
end
|
|
@@ -213,16 +273,16 @@ opt.on("-n NAME", "--name NAME", "The name of your project. Default to the direc
|
|
|
213
273
|
$values[:name] = v
|
|
214
274
|
end
|
|
215
275
|
|
|
216
|
-
opt.on("
|
|
276
|
+
opt.on("--force", "-f", "Whether to force use directory. Default to false.") do |v|
|
|
217
277
|
$values[:force] = v
|
|
218
278
|
end
|
|
219
279
|
|
|
220
|
-
ARGV.delete_at(0)
|
|
221
|
-
|
|
222
280
|
opt.parse!(ARGV)
|
|
223
281
|
|
|
224
282
|
if (dir = ARGV[0])
|
|
225
283
|
$path += "/#{dir}"
|
|
284
|
+
$path = File.expand_path($path)
|
|
285
|
+
dir = File.basename($path)
|
|
226
286
|
if Dir.exist?($path)
|
|
227
287
|
if Dir.empty?($path)
|
|
228
288
|
iputs "Found \e[30m#{dir}\e[90m and empty, using this directory."
|
|
@@ -237,6 +297,9 @@ if (dir = ARGV[0])
|
|
|
237
297
|
iputs "Couldn't find \e[30m#{dir}\e[90m, created directory."
|
|
238
298
|
end
|
|
239
299
|
Dir.chdir($path)
|
|
300
|
+
else
|
|
301
|
+
puts opt
|
|
302
|
+
abort
|
|
240
303
|
end
|
|
241
304
|
|
|
242
305
|
$values[:name] ||= Dir.pwd.split("/").last
|
|
@@ -249,4 +312,4 @@ make_descs if $values[:descs]
|
|
|
249
312
|
|
|
250
313
|
git_init if $values[:git]
|
|
251
314
|
|
|
252
|
-
sputs "\nSuccessfully made a new project at \e[32m#{$path}\e[92m."
|
|
315
|
+
sputs "\nSuccessfully made a new project at \e[32m#{Pathname.new($path).cleanpath.split[-1]}\e[92m."
|
data/lib/discorb/exe/run.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
# description: Run a client.
|
|
3
4
|
require "optparse"
|
|
4
5
|
require "json"
|
|
@@ -6,8 +7,6 @@ require "discorb/utils/colored_puts"
|
|
|
6
7
|
require "io/console"
|
|
7
8
|
require "discorb"
|
|
8
9
|
|
|
9
|
-
ARGV.delete_at 0
|
|
10
|
-
|
|
11
10
|
opt = OptionParser.new <<~BANNER
|
|
12
11
|
This command will run a client.
|
|
13
12
|
|
|
@@ -19,12 +18,13 @@ options = {
|
|
|
19
18
|
title: nil,
|
|
20
19
|
setup: nil,
|
|
21
20
|
token: false,
|
|
22
|
-
bundler: :default,
|
|
23
21
|
}
|
|
24
22
|
opt.on("-s", "--setup", "Whether to setup application commands.") { |v| options[:setup] = v }
|
|
25
|
-
opt.on("-e", "--env [ENV]",
|
|
23
|
+
opt.on("-e", "--env [ENV]",
|
|
24
|
+
"The name of the environment variable to use for token, or just `-e` or `--env` for intractive prompt.") do |v|
|
|
25
|
+
options[:token] = v
|
|
26
|
+
end
|
|
26
27
|
opt.on("-t", "--title TITLE", "The title of process.") { |v| options[:title] = v }
|
|
27
|
-
opt.on("-b", "--[no-]bundler", "Whether to use bundler. Default to true if Gemfile exists, otherwise false.") { |v| options[:bundler] = v }
|
|
28
28
|
opt.parse!(ARGV)
|
|
29
29
|
|
|
30
30
|
script = ARGV[0]
|
|
@@ -38,6 +38,7 @@ if script.nil?
|
|
|
38
38
|
break
|
|
39
39
|
end
|
|
40
40
|
break if dir == File.dirname(dir)
|
|
41
|
+
|
|
41
42
|
dir = File.dirname(dir)
|
|
42
43
|
end
|
|
43
44
|
if File.dirname(script) != Dir.pwd
|
|
@@ -50,7 +51,7 @@ ENV["DISCORB_CLI_FLAG"] = "run"
|
|
|
50
51
|
ENV["DISCORB_CLI_OPTIONS"] = JSON.generate(options)
|
|
51
52
|
|
|
52
53
|
if options[:token]
|
|
53
|
-
ENV["DISCORB_CLI_TOKEN"] = ENV
|
|
54
|
+
ENV["DISCORB_CLI_TOKEN"] = ENV.fetch(options[:token], nil)
|
|
54
55
|
raise "#{options[:token]} is not set." if ENV["DISCORB_CLI_TOKEN"].nil?
|
|
55
56
|
elsif options[:token].nil? || options[:token] == "-"
|
|
56
57
|
print "\e[90mPlease enter your token: \e[m"
|
|
@@ -58,25 +59,10 @@ elsif options[:token].nil? || options[:token] == "-"
|
|
|
58
59
|
puts ""
|
|
59
60
|
end
|
|
60
61
|
|
|
61
|
-
if options[:bundler] == :default
|
|
62
|
-
dir = Dir.pwd.split("/")
|
|
63
|
-
options[:bundler] = false
|
|
64
|
-
dir.length.times.reverse_each do |i|
|
|
65
|
-
if File.exist? "#{dir[0..i].join("/")}/Gemfile"
|
|
66
|
-
options[:bundler] = true
|
|
67
|
-
break
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
62
|
ENV["DISCORB_CLI_TITLE"] = options[:title]
|
|
73
63
|
|
|
74
64
|
if File.exist? script
|
|
75
|
-
|
|
76
|
-
exec "bundle exec ruby #{script}"
|
|
77
|
-
else
|
|
78
|
-
exec "ruby #{script}"
|
|
79
|
-
end
|
|
65
|
+
exec "ruby #{script}"
|
|
80
66
|
else
|
|
81
67
|
eputs "Could not load script: \e[31m#{script}\e[91m"
|
|
82
68
|
end
|
data/lib/discorb/exe/setup.rb
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
# description: Setup application commands.
|
|
3
4
|
require "optparse"
|
|
4
5
|
require "discorb/utils/colored_puts"
|
|
5
6
|
|
|
6
|
-
ARGV.delete_at 0
|
|
7
|
-
|
|
8
7
|
options = {
|
|
9
8
|
guilds: nil,
|
|
10
9
|
script: true,
|
|
@@ -17,8 +16,21 @@ opt = OptionParser.new <<~BANNER
|
|
|
17
16
|
|
|
18
17
|
script The script to setup.
|
|
19
18
|
BANNER
|
|
20
|
-
opt.on("-g", "--guild ID", Array,
|
|
21
|
-
|
|
19
|
+
opt.on("-g", "--guild ID", Array,
|
|
20
|
+
"The guild ID to setup, use comma for setup commands in multiple guilds, " \
|
|
21
|
+
"or `global` for setup global commands.") do |v|
|
|
22
|
+
options[:guilds] = v
|
|
23
|
+
end
|
|
24
|
+
opt.on("-c", "--clear-guild ID", Array,
|
|
25
|
+
"The guild ID to clear command, use comma for clear commands in multiple guilds, " \
|
|
26
|
+
"or `global` for clear global commands.") do |v|
|
|
27
|
+
options[:clear_guilds] = v
|
|
28
|
+
end
|
|
29
|
+
opt.on("-s", "--[no-]script",
|
|
30
|
+
"Whether to run `:setup` event. " \
|
|
31
|
+
"This may be useful if setup script includes operation that shouldn't run twice. Default to true.") do |v|
|
|
32
|
+
options[:script] = v
|
|
33
|
+
end
|
|
22
34
|
opt.parse!(ARGV)
|
|
23
35
|
|
|
24
36
|
script = ARGV[0]
|
|
@@ -26,17 +38,18 @@ script ||= "main.rb"
|
|
|
26
38
|
ENV["DISCORB_CLI_FLAG"] = "setup"
|
|
27
39
|
|
|
28
40
|
ENV["DISCORB_SETUP_GUILDS"] = if options[:guilds] == ["global"]
|
|
29
|
-
|
|
30
|
-
elsif options[:guilds]
|
|
31
|
-
|
|
32
|
-
end
|
|
41
|
+
"global"
|
|
42
|
+
elsif options[:guilds]
|
|
43
|
+
options[:guilds].join(",")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
ENV["DISCORB_SETUP_CLEAR_GUILDS"] = options[:clear_guilds]&.join(",")
|
|
33
47
|
|
|
34
48
|
ENV["DISCORB_SETUP_SCRIPT"] = options[:script].to_s if options[:script]
|
|
35
49
|
|
|
36
|
-
|
|
50
|
+
if File.exist? script
|
|
37
51
|
load script
|
|
38
|
-
rescue LoadError
|
|
39
|
-
eputs "Could not load script: \e[31m#{script}\e[m"
|
|
40
|
-
else
|
|
41
52
|
sputs "Successfully set up commands for \e[32m#{script}\e[m."
|
|
53
|
+
else
|
|
54
|
+
eputs "Could not load script: \e[31m#{script}\e[m"
|
|
42
55
|
end
|
data/lib/discorb/exe/show.rb
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
# description: Show information of your environment.
|
|
3
4
|
|
|
4
5
|
require "etc"
|
|
5
6
|
require "discorb"
|
|
6
7
|
|
|
7
|
-
puts "\e[
|
|
8
|
-
puts "\e[
|
|
8
|
+
puts "\e[90m Ruby:\e[m #{RUBY_VERSION}"
|
|
9
|
+
puts "\e[90m discorb:\e[m #{Discorb::VERSION}"
|
|
9
10
|
uname = Etc.uname
|
|
10
|
-
puts "\e[
|
|
11
|
+
puts "\e[90m System:\e[m #{uname[:sysname]} #{uname[:release]}"
|
|
11
12
|
puts "\e[90mPlatform:\e[m #{RUBY_PLATFORM}"
|
data/lib/discorb/extend.rb
CHANGED
data/lib/discorb/extension.rb
CHANGED
|
@@ -14,10 +14,13 @@ module Discorb
|
|
|
14
14
|
|
|
15
15
|
def events
|
|
16
16
|
return @events if @events
|
|
17
|
+
|
|
17
18
|
ret = {}
|
|
18
19
|
self.class.events.each do |event, handlers|
|
|
19
20
|
ret[event] = handlers.map do |handler|
|
|
20
|
-
Discorb::EventHandler.new(proc { |*args, **kwargs|
|
|
21
|
+
Discorb::EventHandler.new(proc { |*args, **kwargs|
|
|
22
|
+
instance_exec(*args, **kwargs, &handler[2])
|
|
23
|
+
}, handler[0], handler[1])
|
|
21
24
|
end
|
|
22
25
|
end
|
|
23
26
|
@events = ret
|
|
@@ -42,8 +45,6 @@ module Discorb
|
|
|
42
45
|
# @param [Symbol] id The id of the event. Used to delete the event.
|
|
43
46
|
# @param [Hash] metadata Other metadata.
|
|
44
47
|
#
|
|
45
|
-
# @return [Discorb::EventHandler] The event.
|
|
46
|
-
#
|
|
47
48
|
def event(event_name, id: nil, **metadata, &block)
|
|
48
49
|
raise ArgumentError, "Event name must be a symbol" unless event_name.is_a?(Symbol)
|
|
49
50
|
raise ArgumentError, "block must be given" unless block_given?
|
|
@@ -61,8 +62,6 @@ module Discorb
|
|
|
61
62
|
# @param [Hash] metadata Other metadata.
|
|
62
63
|
# @param [Proc] block The block to execute when the event is triggered.
|
|
63
64
|
#
|
|
64
|
-
# @return [Discorb::EventHandler] The event.
|
|
65
|
-
#
|
|
66
65
|
def once_event(event_name, id: nil, **metadata, &block)
|
|
67
66
|
event(event_name, id: id, once: true, **metadata, &block)
|
|
68
67
|
end
|
|
@@ -72,11 +71,11 @@ module Discorb
|
|
|
72
71
|
# @return [Array<Discorb::ApplicationCommand::Command>] The commands of the extension.
|
|
73
72
|
attr_reader :commands
|
|
74
73
|
# @private
|
|
75
|
-
attr_reader :
|
|
74
|
+
attr_reader :callable_commands
|
|
76
75
|
|
|
77
76
|
def self.extended(klass)
|
|
78
77
|
klass.instance_variable_set(:@commands, [])
|
|
79
|
-
klass.instance_variable_set(:@
|
|
78
|
+
klass.instance_variable_set(:@callable_commands, [])
|
|
80
79
|
klass.instance_variable_set(:@events, {})
|
|
81
80
|
end
|
|
82
81
|
end
|
data/lib/discorb/flag.rb
CHANGED
|
@@ -21,7 +21,7 @@ module Discorb
|
|
|
21
21
|
def initialize(value)
|
|
22
22
|
@value = value
|
|
23
23
|
@values = {}
|
|
24
|
-
self.class.bits.
|
|
24
|
+
self.class.bits.each do |bn, bv|
|
|
25
25
|
@values[bn] = value & (1 << bv) != 0
|
|
26
26
|
end
|
|
27
27
|
end
|
|
@@ -29,7 +29,7 @@ module Discorb
|
|
|
29
29
|
#
|
|
30
30
|
# Returns the value of the flag.
|
|
31
31
|
#
|
|
32
|
-
def method_missing(name,
|
|
32
|
+
def method_missing(name, *_args, **_kwargs)
|
|
33
33
|
if @values.key?(name.to_s.delete_suffix("?").to_sym)
|
|
34
34
|
@values[name.to_s.delete_suffix("?").to_sym]
|
|
35
35
|
else
|
|
@@ -96,6 +96,10 @@ module Discorb
|
|
|
96
96
|
self.class.new(~@value)
|
|
97
97
|
end
|
|
98
98
|
|
|
99
|
+
def to_i
|
|
100
|
+
@value
|
|
101
|
+
end
|
|
102
|
+
|
|
99
103
|
def inspect
|
|
100
104
|
"#<#{self.class}: #{@value}>"
|
|
101
105
|
end
|
|
@@ -112,6 +116,13 @@ module Discorb
|
|
|
112
116
|
def max_value
|
|
113
117
|
2 ** @bits.values.max - 1
|
|
114
118
|
end
|
|
119
|
+
|
|
120
|
+
#
|
|
121
|
+
# Initialize a new flag with keys.
|
|
122
|
+
#
|
|
123
|
+
def from_keys(*keys)
|
|
124
|
+
new(keys.sum { |k| 1 << @bits[k] })
|
|
125
|
+
end
|
|
115
126
|
end
|
|
116
127
|
end
|
|
117
128
|
end
|