advanced_ruby_command_handler 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97c6a7076b47b7d2dda46986b94f2972363dc81c17c55d619a7d668e8c39df09
4
- data.tar.gz: 3b6a580272ef1e6f5f86b49719fc50c5616aeb2a729592b913ea45ffb88857d3
3
+ metadata.gz: b97941216c2de5b7a5c5eac1d8613b3fb6e0670e2c52e9efb01337ab7d9be3ff
4
+ data.tar.gz: 1d11b79ca18ebb54e0fd7463e359955e005b022c326866a412cbe491d757e759
5
5
  SHA512:
6
- metadata.gz: e8133e6028b5acb9095b4e48a653db545840091de10e4d0c6af5d390c21f2aab4762b1250a951ebf9f3545b81d31fd7a905a5f7ae39f7edd680780e70b8a7fcc
7
- data.tar.gz: 52d14801db9f0d424dd18a13b732e16fdcb504131c966b6ce243c12f3f8d4c961da6e5563445b7beda70ab0edfe008d1d75dedffa5795db1176404534287f0cf
6
+ metadata.gz: 5ba9dca758046935b6fe4e888401eda55575461325d76fe5afbac37037de4c2b84f52f0d9ce9aa8004b121a7e2b8b3ae7e00a8c9aa7c601fa05d99a5c0176de7
7
+ data.tar.gz: e21cd5ddac2ad88a7604eac57fa1b0919f723ef995d44758322053339a03820013ba05b7e72103fec3f5979c89942a1569c96950445bb29e924fcdfc5d4053b7
data/.gitignore CHANGED
@@ -6,4 +6,6 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
- /.idea/
9
+ /.idea/
10
+ *.gem
11
+ *.yml
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- advanced_ruby_command_handler (0.1.3)
4
+ advanced_ruby_command_handler (0.1.5)
5
+ discordrb
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
@@ -29,8 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ["lib"]
31
31
 
32
- # Uncomment to register a new dependency of your gem
33
- # spec.add_dependency "example-gem", "~> 1.0"
32
+ spec.add_dependency "discordrb"
34
33
 
35
34
  # For more information and examples about making a new gem, checkout our
36
35
  # guide at: https://bundler.io/guides/creating_gem.html
@@ -5,6 +5,7 @@ require "fileutils"
5
5
  require "yaml"
6
6
  require_relative "command_handler"
7
7
  require_relative "event_handler"
8
+ require_relative "utils"
8
9
 
9
10
  module AdvancedRubyCommandHandler
10
11
  class Client < Discordrb::Bot
@@ -41,6 +42,8 @@ module AdvancedRubyCommandHandler
41
42
  .each do |event|
42
43
  Events.method(event).call(self)
43
44
  end
45
+
46
+ at_exit { @console_logger.info("Application exited") }
44
47
  end
45
48
 
46
49
  def run
@@ -49,8 +52,9 @@ module AdvancedRubyCommandHandler
49
52
  Thread.new do
50
53
  @console_logger.info("Type '.exit' to turn off the bot")
51
54
  # @console_logger.info("Type '.reload' to reload the bot")
52
-
53
- exit if $stdin.gets.chomp == ".exit"
55
+ loop do
56
+ Process.exit!(true) if $stdin.gets.chomp == ".exit"
57
+ end
54
58
  end
55
59
 
56
60
  super.run
@@ -5,8 +5,51 @@ module CommandHandler
5
5
  attr_reader :props, :run
6
6
 
7
7
  def initialize(props, &run)
8
- @props = props
8
+ @props = load_proprieties(props)
9
9
  @run = run
10
10
  end
11
+
12
+ def load_proprieties(props)
13
+ return props unless props.instance_of?(Hash)
14
+
15
+ props[:aliases] ||= nil
16
+ props[:description] ||= nil
17
+ props[:args] ||= nil
18
+ props[:strict_args] ||= false
19
+ props[:use_example] ||= nil
20
+ props[:category] ||= nil
21
+ props[:user_permissions] ||= []
22
+ props[:client_permissions] ||= []
23
+ if props[:client_permissions].instance_of?(Array) && props[:client_permissions].empty?
24
+ props[:client_permissions].push(
25
+ :add_reactions,
26
+ :send_messages,
27
+ :embed_links,
28
+ :attach_files,
29
+ :use_external_emoji
30
+ )
31
+ elsif props[:client_permissions] == :default
32
+ props[:client_permissions] = %i[
33
+ add_reactions
34
+ send_messages
35
+ embed_links
36
+ attach_files
37
+ use_external_emoji
38
+ ]
39
+ end
40
+
41
+ Hash[
42
+ :name => props[:name],
43
+ :aliases => props[:aliases],
44
+ :description => props[:description],
45
+ :args => props[:args],
46
+ :strict_args => props[:strict_args],
47
+ :use_example => props[:use_example],
48
+ :category => props[:category],
49
+ :user_permissions => props[:user_permissions],
50
+ :client_permissions => props[:client_permissions]
51
+ ]
52
+ end
53
+ private :load_proprieties
11
54
  end
12
55
  end
@@ -10,7 +10,9 @@ module AdvancedRubyCommandHandler
10
10
  next if %w[. ..].include?(dir)
11
11
 
12
12
  Dir.entries("#{client.commands_dir}/#{dir}").each do |file|
13
- next if %w(. ..).include?(file)
13
+ next if %w[. ..].include?(file)
14
+
15
+ p "#{client.commands_dir}/#{dir}/#{file}"
14
16
 
15
17
  load "#{client.commands_dir}/#{dir}/#{file}"
16
18
 
@@ -11,7 +11,14 @@ module Events
11
11
 
12
12
  next unless command
13
13
 
14
- command.run.call(message, client)
14
+ begin
15
+ command.run.call(message, client)
16
+ rescue StandardError => e
17
+ client.console_logger.error(e)
18
+ client.file_logger.write(e, :errors)
19
+ ensure
20
+ client.console_logger.info("Command '#{command.props[:name]}' used by #{message.author.username}")
21
+ end
15
22
  end
16
23
  end
17
24
  end
@@ -13,7 +13,7 @@ module AdvancedRubyCommandHandler
13
13
  events << File.basename(file, ".rb")
14
14
  end
15
15
 
16
- Dir["#{File.dirname(__FILE__)}/defaults/events/*.rb"].each do |file|
16
+ Dir["#{File.dirname(__FILE__)}/defaults/events/*.rb"].sort.each do |file|
17
17
  next if events.include?(File.basename(file, ".rb"))
18
18
 
19
19
  require file
@@ -57,7 +57,6 @@ module AdvancedRubyCommandHandler
57
57
  puts "[#{console_color(:magenta, time)}] - [#{console_color(color, mode.to_s.upcase)}] : #{message.to_s}"
58
58
  end
59
59
  end
60
-
61
60
  private :console_color
62
61
  end
63
62
  end
@@ -7,5 +7,13 @@ module CommandHandler
7
7
 
8
8
  false
9
9
  end
10
+
11
+ # Do NOT use that
12
+ # FIXME
13
+ def reload_files(dirs)
14
+ dirs.each do |dir|
15
+ Dir.glob("#{dir}/**/*.rb").each { |file| load file }
16
+ end
17
+ end
10
18
  end
11
19
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AdvancedRubyCommandHandler
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.5"
5
5
  end
@@ -1,12 +1,19 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "advanced_ruby_command_handler/app/app"
4
- require_relative "advanced_ruby_command_handler/app/command"
5
- require_relative "advanced_ruby_command_handler/app/utils"
6
-
7
-
8
- module CommandHandler
9
- def self.new(commands_dir: "commands", events_dir: "events", config_file: "config.yml")
10
- AdvancedRubyCommandHandler::Client.new(:commands_dir => commands_dir, :events_dir => events_dir, :config_file => config_file)
11
- end
12
- end
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "advanced_ruby_command_handler/app/app"
4
+ require_relative "advanced_ruby_command_handler/app/command"
5
+ require_relative "advanced_ruby_command_handler/app/utils"
6
+
7
+ ##
8
+ # Represent the CommandHandler as a simply class
9
+ module CommandHandler
10
+ ##
11
+ # @!method new
12
+ # @param [String] commands_dir The command's directory path
13
+ # @param [String] events_dir The event's directory path
14
+ # @param [String] config_file The config's file path
15
+ # @return [AdvancedRubyCommandHandler::Client] the created client
16
+ def self.new(commands_dir: "commands", events_dir: "events", config_file: "config.yml")
17
+ AdvancedRubyCommandHandler::Client.new(:commands_dir => commands_dir, :events_dir => events_dir, :config_file => config_file)
18
+ end
19
+ end
@@ -1,13 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "../../../lib/advanced_ruby_command_handler/app/command"
4
+ require_relative "../../../lib/advanced_ruby_command_handler/app/utils"
4
5
 
5
6
  module Commands
6
7
  def self.test
7
8
  CommandHandler::Command.new({
8
- :name => "test"
9
- }) do |message, client|
10
- message.respond "Command test!"
9
+ :name => "test",
10
+ :aliases => ["t"],
11
+ :description => "Une commande pour faire des tests!",
12
+ :args => false,
13
+ :use_example => :default,
14
+ :category => :default
15
+ }) do |message, _client|
16
+ message.respond "Test"
11
17
  end
12
18
  end
13
19
  end
data/tests/config.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :token: 'NzEwMTIxODk2OTM0NjM3NjY5.Xrv2jQ.4v9551dYI5nqRSIGfYy19APUmbA'
2
+ :token: 'NzEwMTIxODk2OTM0NjM3NjY5.Xrv2jQ._ypS5jOkYr4onqigdoxGzF2dRj0'
3
3
  :prefix: '!'
4
4
  :owners: [123456789]
@@ -7,4 +7,3 @@ module Events
7
7
  end
8
8
  end
9
9
  end
10
-
data/tests/index.rb CHANGED
@@ -2,6 +2,5 @@
2
2
 
3
3
  require_relative "../lib/advanced_ruby_command_handler"
4
4
 
5
-
6
5
  CommandHandler.new(:commands_dir => "tests/commands", :events_dir => "tests/events", :config_file => "tests/config.yml")
7
6
  .run
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: advanced_ruby_command_handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - senchuu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-27 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2021-09-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: discordrb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: an advanced discord bot command handler
14
28
  email:
15
29
  - senchuuuu@gmail.com
@@ -27,8 +41,6 @@ files:
27
41
  - LICENSE.txt
28
42
  - README.md
29
43
  - Rakefile
30
- - advanced_ruby_command_handler-0.1.1.gem
31
- - advanced_ruby_command_handler-0.1.2.gem
32
44
  - advanced_ruby_command_handler.gemspec
33
45
  - bin/console
34
46
  - bin/setup