discorb 0.10.0 → 0.10.1
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/Changelog.md +6 -0
- data/docs/cli/run.md +5 -1
- data/lib/discorb/client.rb +14 -3
- data/lib/discorb/common.rb +1 -1
- data/lib/discorb/exe/run.rb +20 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 711fc9fac1407a6de44da571555d6b5eb0575983453a8371bbb1df960ae376ac
|
4
|
+
data.tar.gz: 33defa63e7f65c82eee318a4d3783c2640fc1dcb54ffdf4941694cef7e72b1a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a58931cea651763d030c14a61f1f463b7959449bcd70599819c0140884a2a0d86cde1706f97fb3af81013eb6fe2d5372df743a5275dc86f454d01618ba1a90a
|
7
|
+
data.tar.gz: 884bdcfa59ff7612bcf9f0f12186c5e4cf51313b22a71dac308edc2abaaf45f33cf5e6f85c48681beb976309a245610d16dfd5c781bc6e50c90c0f9e215bc11a
|
data/Changelog.md
CHANGED
data/docs/cli/run.md
CHANGED
@@ -53,4 +53,8 @@ Whether to setup application commands.
|
|
53
53
|
|
54
54
|
#### `-e`, `--env`
|
55
55
|
|
56
|
-
The name of the environment variable to use for token, or just `-t` or `--token` for intractive prompt.
|
56
|
+
The name of the environment variable to use for token, or just `-t` or `--token` for intractive prompt.
|
57
|
+
|
58
|
+
#### `-b`, `--bundler`
|
59
|
+
|
60
|
+
Whether to use bundler to load the script.
|
data/lib/discorb/client.rb
CHANGED
@@ -52,6 +52,8 @@ module Discorb
|
|
52
52
|
attr_reader :status
|
53
53
|
# @return [Integer] The session ID of connection.
|
54
54
|
attr_reader :session_id
|
55
|
+
# @return [Hash{String => Discorb::Extension}] The loaded extensions.
|
56
|
+
attr_reader :extensions
|
55
57
|
# @private
|
56
58
|
attr_reader :bottom_commands
|
57
59
|
|
@@ -97,6 +99,7 @@ module Discorb
|
|
97
99
|
@status = :initialized
|
98
100
|
@fetch_member = fetch_member
|
99
101
|
@title = title
|
102
|
+
@extensions = {}
|
100
103
|
set_default_events
|
101
104
|
end
|
102
105
|
|
@@ -369,12 +372,19 @@ module Discorb
|
|
369
372
|
#
|
370
373
|
# Load the extension.
|
371
374
|
#
|
372
|
-
# @param [Class] ext The extension to load.
|
375
|
+
# @param [Class, Discorb::Extension] ext The extension to load.
|
373
376
|
# @param [Object] ... The arguments to pass to the `ext#initialize`.
|
374
377
|
#
|
375
378
|
def load_extension(ext, ...)
|
376
|
-
|
377
|
-
|
379
|
+
if ext.is_a?(Class)
|
380
|
+
raise ArgumentError, "#{ext} is not a extension" unless ext < Discorb::Extension
|
381
|
+
ins = ext.new(self, ...)
|
382
|
+
elsif ext.is_a?(Discorb::Extension)
|
383
|
+
ins = ext
|
384
|
+
else
|
385
|
+
raise ArgumentError, "#{ext} is not a extension"
|
386
|
+
end
|
387
|
+
|
378
388
|
@events.each_value do |event|
|
379
389
|
event.delete_if { |c| c.metadata[:extension] == ins.class.name }
|
380
390
|
end
|
@@ -392,6 +402,7 @@ module Discorb
|
|
392
402
|
@commands << cmd
|
393
403
|
end
|
394
404
|
@bottom_commands += ins.class.bottom_commands
|
405
|
+
@extensions[ins.class.name] = ins
|
395
406
|
ins
|
396
407
|
end
|
397
408
|
|
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/v9"
|
6
6
|
# @return [String] The version of discorb.
|
7
|
-
VERSION = "0.10.
|
7
|
+
VERSION = "0.10.1"
|
8
8
|
# @return [String] The user agent for the bot.
|
9
9
|
USER_AGENT = "DiscordBot (https://discorb-lib.github.io #{VERSION}) Ruby/#{RUBY_VERSION}"
|
10
10
|
|
data/lib/discorb/exe/run.rb
CHANGED
@@ -22,6 +22,7 @@ options = {
|
|
22
22
|
log_color: nil,
|
23
23
|
setup: nil,
|
24
24
|
token: false,
|
25
|
+
bundler: :default,
|
25
26
|
}
|
26
27
|
opt.on("-l", "--log-level LEVEL", "Log level.") do |v|
|
27
28
|
unless LOG_LEVELS.include? v.downcase
|
@@ -36,6 +37,7 @@ opt.on("-c", "--[no-]log-color", "Whether to colorize log output.") { |v| option
|
|
36
37
|
opt.on("-s", "--setup", "Whether to setup application commands.") { |v| options[:setup] = v }
|
37
38
|
opt.on("-e", "--env [ENV]", "The name of the environment variable to use for token, or just `-e` or `--env` for intractive prompt.") { |v| options[:token] = v }
|
38
39
|
opt.on("-t", "--title TITLE", "The title of process.") { |v| options[:title] = v }
|
40
|
+
opt.on("-b", "--[no-]bundler", "Whether to use bundler. Default to true if Gemfile exists, otherwise false.") { |v| options[:bundler] = v }
|
39
41
|
opt.parse!(ARGV)
|
40
42
|
|
41
43
|
script = ARGV[0]
|
@@ -54,10 +56,25 @@ elsif options[:token].nil? || options[:token] == "-"
|
|
54
56
|
puts ""
|
55
57
|
end
|
56
58
|
|
59
|
+
if options[:bundler] == :default
|
60
|
+
dir = Dir.pwd.split("/")
|
61
|
+
options[:bundler] = false
|
62
|
+
dir.length.times.reverse_each do |i|
|
63
|
+
if File.exist? "#{dir[0..i].join("/")}/Gemfile"
|
64
|
+
options[:bundler] = true
|
65
|
+
break
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
57
70
|
ENV["DISCORB_CLI_TITLE"] = options[:title]
|
58
71
|
|
59
|
-
|
60
|
-
|
61
|
-
|
72
|
+
if File.exist? script
|
73
|
+
if options[:bundler]
|
74
|
+
system "bundle exec ruby #{script}"
|
75
|
+
else
|
76
|
+
system "ruby #{script}"
|
77
|
+
end
|
78
|
+
else
|
62
79
|
eputs "Could not load script: \e[31m#{script}\e[91m"
|
63
80
|
end
|