discorb 0.16.0 → 0.17.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 +1 -1
- data/.github/workflows/spec.yml +30 -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 +14 -1
- data/Gemfile +14 -8
- data/Rakefile +41 -26
- data/bin/console +3 -3
- data/docs/Examples.md +1 -1
- data/docs/application_command.md +138 -46
- 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 +209 -211
- data/docs/extension.md +1 -2
- data/docs/faq.md +0 -1
- data/docs/tutorial.md +12 -12
- data/docs/voice_events.md +106 -106
- data/examples/commands/message.rb +63 -0
- data/examples/commands/permission.rb +18 -0
- data/examples/commands/slash.rb +44 -0
- data/examples/commands/user.rb +51 -0
- data/examples/components/authorization_button.rb +2 -2
- data/examples/components/select_menu.rb +2 -2
- data/examples/extension/main.rb +1 -1
- data/examples/extension/message_expander.rb +5 -2
- data/examples/simple/eval.rb +2 -2
- data/examples/simple/ping_pong.rb +1 -1
- data/examples/simple/rolepanel.rb +1 -1
- data/examples/simple/shard.rb +1 -1
- data/examples/simple/wait_for_message.rb +1 -1
- data/exe/discorb +31 -16
- data/lefthook.yml +45 -0
- data/lib/discorb/allowed_mentions.rb +1 -0
- data/lib/discorb/app_command/command.rb +127 -65
- data/lib/discorb/app_command/common.rb +25 -0
- data/lib/discorb/app_command/handler.rb +115 -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 +11 -8
- 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 +245 -0
- data/lib/discorb/channel/stage.rb +140 -0
- data/lib/discorb/channel/text.rb +345 -0
- data/lib/discorb/channel/thread.rb +321 -0
- data/lib/discorb/channel/voice.rb +79 -0
- data/lib/discorb/channel.rb +2 -1165
- data/lib/discorb/client.rb +38 -26
- 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/embed.rb +22 -7
- data/lib/discorb/emoji.rb +30 -3
- data/lib/discorb/emoji_table.rb +4969 -3
- data/lib/discorb/event.rb +29 -4
- data/lib/discorb/exe/about.rb +1 -0
- data/lib/discorb/exe/irb.rb +2 -4
- data/lib/discorb/exe/new.rb +90 -23
- 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 -3
- data/lib/discorb/flag.rb +11 -0
- data/lib/discorb/gateway.rb +67 -19
- data/lib/discorb/guild.rb +188 -56
- data/lib/discorb/guild_template.rb +10 -4
- data/lib/discorb/http.rb +16 -9
- data/lib/discorb/integration.rb +4 -1
- data/lib/discorb/intents.rb +1 -1
- data/lib/discorb/interaction/autocomplete.rb +28 -16
- data/lib/discorb/interaction/command.rb +36 -12
- data/lib/discorb/interaction/components.rb +5 -2
- data/lib/discorb/interaction/modal.rb +0 -1
- data/lib/discorb/interaction/response.rb +61 -22
- 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 +25 -5
- data/lib/discorb/message.rb +47 -14
- data/lib/discorb/message_meta.rb +1 -0
- data/lib/discorb/modules.rb +56 -14
- data/lib/discorb/presence.rb +2 -2
- data/lib/discorb/rate_limit.rb +7 -2
- data/lib/discorb/reaction.rb +4 -4
- data/lib/discorb/role.rb +19 -4
- data/lib/discorb/shard.rb +1 -1
- data/lib/discorb/sticker.rb +8 -7
- data/lib/discorb/user.rb +2 -1
- data/lib/discorb/utils/colored_puts.rb +1 -0
- data/lib/discorb/voice_state.rb +10 -6
- data/lib/discorb/webhook.rb +36 -24
- data/lib/discorb.rb +5 -3
- data/po/yard.pot +9 -9
- data/sig/discorb.rbs +7232 -7235
- metadata +21 -5
- 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
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,9 +219,9 @@ end
|
|
|
160
219
|
def git_init
|
|
161
220
|
create_file(".gitignore")
|
|
162
221
|
iputs "Initializing git repository..."
|
|
163
|
-
system "git init"
|
|
164
|
-
system "git add ."
|
|
165
|
-
system "git commit -m \"Initial commit\""
|
|
222
|
+
system "git init", chdir: $path
|
|
223
|
+
system "git add .", chdir: $path
|
|
224
|
+
system "git commit -m \"Initial commit\"", chdir: $path
|
|
166
225
|
sputs "Initialized repository, use " \
|
|
167
226
|
"\e[32mgit commit --amend -m '...'\e[92m" \
|
|
168
227
|
" to change commit message of initial commit.\n"
|
|
@@ -191,6 +250,7 @@ $values = {
|
|
|
191
250
|
token: "TOKEN",
|
|
192
251
|
descs: false,
|
|
193
252
|
name: nil,
|
|
253
|
+
comment: true,
|
|
194
254
|
}
|
|
195
255
|
|
|
196
256
|
opt.on("--[no-]bundle", "Whether to use bundle. Default to true.") do |v|
|
|
@@ -205,6 +265,10 @@ opt.on("--[no-]descs", "Whether to put some file for description. Default to fal
|
|
|
205
265
|
$values[:descs] = v
|
|
206
266
|
end
|
|
207
267
|
|
|
268
|
+
opt.on("--[no-]comment", "Whether to write comment. Default to true.") do |v|
|
|
269
|
+
$values[:comment] = v
|
|
270
|
+
end
|
|
271
|
+
|
|
208
272
|
opt.on("-t NAME", "--token NAME", "The name of token environment variable. Default to TOKEN.") do |v|
|
|
209
273
|
$values[:token] = v
|
|
210
274
|
end
|
|
@@ -213,16 +277,16 @@ opt.on("-n NAME", "--name NAME", "The name of your project. Default to the direc
|
|
|
213
277
|
$values[:name] = v
|
|
214
278
|
end
|
|
215
279
|
|
|
216
|
-
opt.on("
|
|
280
|
+
opt.on("--force", "-f", "Whether to force use directory. Default to false.") do |v|
|
|
217
281
|
$values[:force] = v
|
|
218
282
|
end
|
|
219
283
|
|
|
220
|
-
ARGV.delete_at(0)
|
|
221
|
-
|
|
222
284
|
opt.parse!(ARGV)
|
|
223
285
|
|
|
224
286
|
if (dir = ARGV[0])
|
|
225
287
|
$path += "/#{dir}"
|
|
288
|
+
$path = File.expand_path($path)
|
|
289
|
+
dir = File.basename($path)
|
|
226
290
|
if Dir.exist?($path)
|
|
227
291
|
if Dir.empty?($path)
|
|
228
292
|
iputs "Found \e[30m#{dir}\e[90m and empty, using this directory."
|
|
@@ -237,6 +301,9 @@ if (dir = ARGV[0])
|
|
|
237
301
|
iputs "Couldn't find \e[30m#{dir}\e[90m, created directory."
|
|
238
302
|
end
|
|
239
303
|
Dir.chdir($path)
|
|
304
|
+
else
|
|
305
|
+
puts opt
|
|
306
|
+
abort
|
|
240
307
|
end
|
|
241
308
|
|
|
242
309
|
$values[:name] ||= Dir.pwd.split("/").last
|
|
@@ -249,4 +316,4 @@ make_descs if $values[:descs]
|
|
|
249
316
|
|
|
250
317
|
git_init if $values[:git]
|
|
251
318
|
|
|
252
|
-
sputs "\nSuccessfully made a new project at \e[32m#{$path}\e[92m."
|
|
319
|
+
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
|
|
@@ -72,11 +75,11 @@ module Discorb
|
|
|
72
75
|
# @return [Array<Discorb::ApplicationCommand::Command>] The commands of the extension.
|
|
73
76
|
attr_reader :commands
|
|
74
77
|
# @private
|
|
75
|
-
attr_reader :
|
|
78
|
+
attr_reader :callable_commands
|
|
76
79
|
|
|
77
80
|
def self.extended(klass)
|
|
78
81
|
klass.instance_variable_set(:@commands, [])
|
|
79
|
-
klass.instance_variable_set(:@
|
|
82
|
+
klass.instance_variable_set(:@callable_commands, [])
|
|
80
83
|
klass.instance_variable_set(:@events, {})
|
|
81
84
|
end
|
|
82
85
|
end
|
data/lib/discorb/flag.rb
CHANGED
|
@@ -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
|