advanced_ruby_command_handler 0.1.1 → 0.1.6

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: 29ce9948b2b75e95125369d796c72f092a42892bffc7a66a768dc52d6bebaf18
4
- data.tar.gz: 74cc5f8f368f366335e011a07de894dcabe6a59a613d552651de81485a881683
3
+ metadata.gz: e70e9c870edb9511be72ddda44180add9a4d0e3651a9e1158836f55c0cd24dbd
4
+ data.tar.gz: ffdcb7bf02966eb556801c36c559712744b9be93553e5c82ec1d36fc3edf40f3
5
5
  SHA512:
6
- metadata.gz: 7c08da956a0b831f157c37b79cbe251f0176a6b57f8f65b0f153031547411d5b809bf872e8f6e5da60257676bcce72ecf190ddd8eb8ad26a158f9091545cc8f4
7
- data.tar.gz: 4f6c83b2a00a332d20e1e7c6e5048fa1fdb4dc71620171064c0febe7adb619e22e8ae7d8810e44693f382c71b23a651adb4c3f7dff5eb684bdcca277623a8b11
6
+ metadata.gz: d4252035f4338480983222c7ffe97f598e9b887936b0abf693d60cc4673f130c3fa3a00d8c148c40090f0723fa082d422e4ed97d7631442ab5e7fbf3114cb44b
7
+ data.tar.gz: a0a4ef7f06ef3af9e8144af41b44c2ee9f71d842add17cfb653409d0a962fdbf7f017e11c5a657b1b596e1d686bd17cc1f65073b415ea3a61f86180aa5a0cd92
@@ -0,0 +1,37 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ main ]
13
+ pull_request:
14
+ branches: [ main ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+ strategy:
21
+ matrix:
22
+ ruby-version: ['2.6', '2.7', '3.0']
23
+
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+ - name: Set up Ruby
27
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
+ # uses: ruby/setup-ruby@v1
30
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
31
+ with:
32
+ ruby-version: ${{ matrix.ruby-version }}
33
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
34
+ - name: Install dependencies
35
+ run: bundle install
36
+ - name: Run tests
37
+ run: bundle exec rake
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
@@ -0,0 +1,128 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ .
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series
86
+ of actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or
93
+ permanent ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within
113
+ the community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.0, available at
119
+ https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120
+
121
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct
122
+ enforcement ladder](https://github.com/mozilla/diversity).
123
+
124
+ [homepage]: https://www.contributor-covenant.org
125
+
126
+ For answers to common questions about this code of conduct, see the FAQ at
127
+ https://www.contributor-covenant.org/faq. Translations are available at
128
+ https://www.contributor-covenant.org/translations.
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- advanced_ruby_command_handler (0.1.1)
4
+ advanced_ruby_command_handler (0.1.5)
5
+ discordrb
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,3 +1,8 @@
1
+
2
+ [![forthebadge](https://forthebadge.com/images/badges/made-with-ruby.svg)](https://forthebadge.com)
3
+
4
+ [![Les Laboratoires Ruby](https://invidget.switchblade.xyz/4P7XcmbDnt)](https://discord.gg/4P7XcmbDnt)
5
+
1
6
  # AdvancedRubyCommandHandler
2
7
  ## Installation
3
8
 
@@ -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
@@ -34,13 +35,15 @@ module AdvancedRubyCommandHandler
34
35
  raise "'#{prop}' missing or empty"
35
36
  end
36
37
 
37
- super(:token => @config[:token])
38
+ super(:token => @config[:token], :ignore_bots => true)
38
39
 
39
40
  @commands = AdvancedRubyCommandHandler::CommandHandler.load_commands(self)
40
41
  AdvancedRubyCommandHandler::EventHandler.load_events(self)
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
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../app/utils"
3
+ require_relative "../../utils"
4
4
 
5
5
  module Events
6
6
  def self.message(client)
@@ -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,12 +13,10 @@ module AdvancedRubyCommandHandler
13
13
  events << File.basename(file, ".rb")
14
14
  end
15
15
 
16
- Dir.entries("lib/advanced_ruby_command_handler/defaults/events").each do |file|
17
- next if %w(. ..).include?(file)
18
-
16
+ Dir["#{File.dirname(__FILE__)}/defaults/events/*.rb"].sort.each do |file|
19
17
  next if events.include?(File.basename(file, ".rb"))
20
18
 
21
- load "lib/advanced_ruby_command_handler/defaults/events/#{file}"
19
+ require file
22
20
 
23
21
  events << File.basename(file, ".rb")
24
22
  end
@@ -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.1"
4
+ VERSION = "0.1.6"
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]
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Events
4
+ def self.ready(client)
5
+ client.ready do
6
+ client.console_logger.info("Client ready!")
7
+ end
8
+ end
9
+ end
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.1
4
+ version: 0.1.6
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-26 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2021-09-26 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
@@ -17,9 +31,11 @@ executables: []
17
31
  extensions: []
18
32
  extra_rdoc_files: []
19
33
  files:
34
+ - ".github/workflows/ruby.yml"
20
35
  - ".gitignore"
21
36
  - ".rubocop.yml"
22
37
  - CHANGELOG.md
38
+ - CODE_OF_CONDUCT.md
23
39
  - Gemfile
24
40
  - Gemfile.lock
25
41
  - LICENSE.txt
@@ -33,14 +49,15 @@ files:
33
49
  - lib/advanced_ruby_command_handler/app/client.rb
34
50
  - lib/advanced_ruby_command_handler/app/command.rb
35
51
  - lib/advanced_ruby_command_handler/app/command_handler.rb
52
+ - lib/advanced_ruby_command_handler/app/defaults/events/message.rb
53
+ - lib/advanced_ruby_command_handler/app/defaults/events/ready.rb
36
54
  - lib/advanced_ruby_command_handler/app/event_handler.rb
37
55
  - lib/advanced_ruby_command_handler/app/logger.rb
38
56
  - lib/advanced_ruby_command_handler/app/utils.rb
39
- - lib/advanced_ruby_command_handler/defaults/events/message.rb
40
- - lib/advanced_ruby_command_handler/defaults/events/ready.rb
41
57
  - lib/advanced_ruby_command_handler/version.rb
42
58
  - tests/commands/test/test.rb
43
59
  - tests/config.yml
60
+ - tests/events/ready.rb
44
61
  - tests/index.rb
45
62
  homepage: https://github.com/Senchuu/Advanced-Bot.rb
46
63
  licenses: