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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d1b87a672806fd34b5a1a3308bd96db493c13a645a2f4ae7cd6a3b9622cf7a01
4
- data.tar.gz: fc1b8e0b433489e1390b958b7b4ebeb9c39c1f2d38ff80c05334dda5f19f3bd8
3
+ metadata.gz: 711fc9fac1407a6de44da571555d6b5eb0575983453a8371bbb1df960ae376ac
4
+ data.tar.gz: 33defa63e7f65c82eee318a4d3783c2640fc1dcb54ffdf4941694cef7e72b1a9
5
5
  SHA512:
6
- metadata.gz: 4c666466d4c10d93e974ecd843d14d9e92b424c18e6fab784dba54ff8c0caf9c5f54feaaa7c03e32f640a237af4ee6795e653691035c3e80e3c7a4af79740143
7
- data.tar.gz: 344ecd871e7c1e98a1ad2b68f75f988ee2aabfbe78e24ecf4e8a58da069e04b8e3327f5348414c33a619381c520ea7dbb4fb173cbea6fa153cb2dd5b07b9f9e2
6
+ metadata.gz: 6a58931cea651763d030c14a61f1f463b7959449bcd70599819c0140884a2a0d86cde1706f97fb3af81013eb6fe2d5372df743a5275dc86f454d01618ba1a90a
7
+ data.tar.gz: 884bdcfa59ff7612bcf9f0f12186c5e4cf51313b22a71dac308edc2abaaf45f33cf5e6f85c48681beb976309a245610d16dfd5c781bc6e50c90c0f9e215bc11a
data/Changelog.md CHANGED
@@ -4,6 +4,12 @@
4
4
 
5
5
  ## v0.10
6
6
 
7
+ ### v0.10.1
8
+
9
+ - Add: Add `Client#extensions`
10
+ - Change: `Client#load_extension` allows instance of `Extension`
11
+ - Add: Add `-b` option to `discorb run`
12
+
7
13
  ### v0.10.0
8
14
 
9
15
  - Change: Sort versions
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.
@@ -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
- raise ArgumentError, "#{ext} is not a extension" unless ext.is_a?(Class) && ext < Discorb::Extension
377
- ins = ext.new(self, ...)
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
 
@@ -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.0"
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
 
@@ -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
- begin
60
- load script
61
- rescue LoadError
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discorb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - sevenc-nanashi