advanced_ruby_command_handler 0.1.2 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +37 -0
- data/.gitignore +3 -1
- data/CODE_OF_CONDUCT.md +128 -0
- data/Gemfile.lock +2 -1
- data/README.md +5 -0
- data/advanced_ruby_command_handler.gemspec +1 -2
- data/lib/advanced_ruby_command_handler/app/client.rb +7 -4
- data/lib/advanced_ruby_command_handler/app/command.rb +48 -1
- data/lib/advanced_ruby_command_handler/app/command_handler.rb +3 -1
- data/lib/advanced_ruby_command_handler/{defaults → app/defaults}/events/message.rb +9 -2
- data/lib/advanced_ruby_command_handler/{defaults → app/defaults}/events/ready.rb +0 -0
- data/lib/advanced_ruby_command_handler/app/event_handler.rb +2 -4
- data/lib/advanced_ruby_command_handler/app/logger.rb +0 -1
- data/lib/advanced_ruby_command_handler/app/utils.rb +8 -0
- data/lib/advanced_ruby_command_handler/version.rb +1 -1
- data/lib/advanced_ruby_command_handler.rb +19 -12
- data/tests/commands/test/test.rb +9 -3
- data/tests/config.yml +1 -1
- data/tests/events/ready.rb +9 -0
- metadata +22 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ff0519b7620fc722603e4463f4f55ee780ba86a9726965bfa3a372b86ba1f94
|
4
|
+
data.tar.gz: 8a8a5e9356334d747b6d5ba1df0ba02541e89e1f9c637cf37b1a894c2a8b7c83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b353e418c6371687b1c0a5801312aed5daa7f13a5901dec76dbcba7117822bb998ba62bfc65d4297e20c296c9b1edab365576eeabf03f0e5e74e50f52b0e109
|
7
|
+
data.tar.gz: e0975bcfc510b3a024e8aff381b9e10a8fdea2f350cb5aac36cd3cae36900de1b360228ff20a6ad8197f5bde7f373f108154b276911f0691802a0a28b2ee67da
|
@@ -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
data/CODE_OF_CONDUCT.md
ADDED
@@ -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
data/README.md
CHANGED
@@ -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
|
-
|
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
|
@@ -48,9 +51,9 @@ module AdvancedRubyCommandHandler
|
|
48
51
|
|
49
52
|
Thread.new do
|
50
53
|
@console_logger.info("Type '.exit' to turn off the bot")
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
+
loop do
|
55
|
+
Process.exit!(true) if $stdin.gets.chomp == ".exit"
|
56
|
+
end
|
54
57
|
end
|
55
58
|
|
56
59
|
super.run
|
@@ -5,8 +5,55 @@ 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.is_a?(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[:server_only] ||= false
|
22
|
+
props[:owner_only] ||= false
|
23
|
+
props[:user_permissions] ||= []
|
24
|
+
props[:client_permissions] ||= []
|
25
|
+
if props[:client_permissions].is_a?(Array) && props[:client_permissions].empty?
|
26
|
+
props[:client_permissions].push(
|
27
|
+
:add_reactions,
|
28
|
+
:send_messages,
|
29
|
+
:embed_links,
|
30
|
+
:attach_files,
|
31
|
+
:use_external_emoji
|
32
|
+
)
|
33
|
+
elsif props[:client_permissions] == :default
|
34
|
+
props[:client_permissions] = %i[
|
35
|
+
add_reactions
|
36
|
+
send_messages
|
37
|
+
embed_links
|
38
|
+
attach_files
|
39
|
+
use_external_emoji
|
40
|
+
]
|
41
|
+
end
|
42
|
+
|
43
|
+
Hash[
|
44
|
+
:name => props[:name],
|
45
|
+
:aliases => props[:aliases],
|
46
|
+
:description => props[:description],
|
47
|
+
:args => props[:args],
|
48
|
+
:strict_args => props[:strict_args],
|
49
|
+
:use_example => props[:use_example],
|
50
|
+
:category => props[:category],
|
51
|
+
:user_permissions => props[:user_permissions],
|
52
|
+
:client_permissions => props[:client_permissions],
|
53
|
+
:owner_only => props[:owner_only],
|
54
|
+
:server_only => props[:server_only]
|
55
|
+
]
|
56
|
+
end
|
57
|
+
private :load_proprieties
|
11
58
|
end
|
12
59
|
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
|
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 "../../
|
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
|
-
|
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
|
File without changes
|
@@ -13,12 +13,10 @@ module AdvancedRubyCommandHandler
|
|
13
13
|
events << File.basename(file, ".rb")
|
14
14
|
end
|
15
15
|
|
16
|
-
Dir
|
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
|
-
|
19
|
+
require file
|
22
20
|
|
23
21
|
events << File.basename(file, ".rb")
|
24
22
|
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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
data/tests/commands/test/test.rb
CHANGED
@@ -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
|
-
|
10
|
-
|
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
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.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- senchuu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
12
|
-
dependencies:
|
11
|
+
date: 2021-10-03 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:
|