advanced_ruby_command_handler 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +38 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +75 -0
- data/LICENSE.txt +21 -0
- data/README.md +92 -0
- data/Rakefile +8 -0
- data/advanced_ruby_command_handler.gemspec +37 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/advanced_ruby_command_handler/app/app.rb +7 -0
- data/lib/advanced_ruby_command_handler/app/client.rb +59 -0
- data/lib/advanced_ruby_command_handler/app/command.rb +12 -0
- data/lib/advanced_ruby_command_handler/app/command_handler.rb +23 -0
- data/lib/advanced_ruby_command_handler/app/event_handler.rb +29 -0
- data/lib/advanced_ruby_command_handler/app/logger.rb +63 -0
- data/lib/advanced_ruby_command_handler/app/utils.rb +11 -0
- data/lib/advanced_ruby_command_handler/defaults/events/message.rb +17 -0
- data/lib/advanced_ruby_command_handler/defaults/events/ready.rb +9 -0
- data/lib/advanced_ruby_command_handler/version.rb +5 -0
- data/lib/advanced_ruby_command_handler.rb +12 -0
- data/tests/commands/test/test.rb +13 -0
- data/tests/config.yml +4 -0
- data/tests/index.rb +6 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 29ce9948b2b75e95125369d796c72f092a42892bffc7a66a768dc52d6bebaf18
|
4
|
+
data.tar.gz: 74cc5f8f368f366335e011a07de894dcabe6a59a613d552651de81485a881683
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7c08da956a0b831f157c37b79cbe251f0176a6b57f8f65b0f153031547411d5b809bf872e8f6e5da60257676bcce72ecf190ddd8eb8ad26a158f9091545cc8f4
|
7
|
+
data.tar.gz: 4f6c83b2a00a332d20e1e7c6e5048fa1fdb4dc71620171064c0febe7adb619e22e8ae7d8810e44693f382c71b23a651adb4c3f7dff5eb684bdcca277623a8b11
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.5
|
3
|
+
|
4
|
+
Style/StringLiterals:
|
5
|
+
Enabled: true
|
6
|
+
EnforcedStyle: double_quotes
|
7
|
+
|
8
|
+
Style/StringLiteralsInInterpolation:
|
9
|
+
Enabled: true
|
10
|
+
EnforcedStyle: double_quotes
|
11
|
+
|
12
|
+
Layout/LineLength:
|
13
|
+
Max: 200
|
14
|
+
|
15
|
+
Style/HashSyntax:
|
16
|
+
Enabled: true
|
17
|
+
EnforcedStyle: hash_rockets
|
18
|
+
|
19
|
+
Layout/EndOfLine:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Metrics/ModuleLength:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Metrics/MethodLength:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Lint/RedundantStringCoercion:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Style/Documentation:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Metrics/PerceivedComplexity:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Metris/AbcSize:
|
38
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
advanced_ruby_command_handler (0.1.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
discordrb (3.4.0)
|
11
|
+
discordrb-webhooks (~> 3.3.0)
|
12
|
+
ffi (>= 1.9.24)
|
13
|
+
opus-ruby
|
14
|
+
rest-client (>= 2.0.0)
|
15
|
+
websocket-client-simple (>= 0.3.0)
|
16
|
+
discordrb-webhooks (3.3.0)
|
17
|
+
rest-client (>= 2.1.0.rc1)
|
18
|
+
domain_name (0.5.20190701)
|
19
|
+
unf (>= 0.0.5, < 1.0.0)
|
20
|
+
event_emitter (0.2.6)
|
21
|
+
ffi (1.15.0-x64-mingw32)
|
22
|
+
http-accept (1.7.0)
|
23
|
+
http-cookie (1.0.3)
|
24
|
+
domain_name (~> 0.5)
|
25
|
+
mime-types (3.3.1)
|
26
|
+
mime-types-data (~> 3.2015)
|
27
|
+
mime-types-data (3.2020.1104)
|
28
|
+
netrc (0.11.0)
|
29
|
+
opus-ruby (1.0.1)
|
30
|
+
ffi
|
31
|
+
parallel (1.20.1)
|
32
|
+
parser (3.0.1.1)
|
33
|
+
ast (~> 2.4.1)
|
34
|
+
rainbow (3.0.0)
|
35
|
+
rake (13.0.3)
|
36
|
+
regexp_parser (2.1.1)
|
37
|
+
rest-client (2.1.0-x64-mingw32)
|
38
|
+
ffi (~> 1.9)
|
39
|
+
http-accept (>= 1.7.0, < 2.0)
|
40
|
+
http-cookie (>= 1.0.2, < 2.0)
|
41
|
+
mime-types (>= 1.16, < 4.0)
|
42
|
+
netrc (~> 0.8)
|
43
|
+
rexml (3.2.5)
|
44
|
+
rubocop (1.18.1)
|
45
|
+
parallel (~> 1.10)
|
46
|
+
parser (>= 3.0.0.0)
|
47
|
+
rainbow (>= 2.2.2, < 4.0)
|
48
|
+
regexp_parser (>= 1.8, < 3.0)
|
49
|
+
rexml
|
50
|
+
rubocop-ast (>= 1.7.0, < 2.0)
|
51
|
+
ruby-progressbar (~> 1.7)
|
52
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
53
|
+
rubocop-ast (1.7.0)
|
54
|
+
parser (>= 3.0.1.1)
|
55
|
+
ruby-progressbar (1.11.0)
|
56
|
+
unf (0.1.4)
|
57
|
+
unf_ext
|
58
|
+
unf_ext (0.0.7.7)
|
59
|
+
unicode-display_width (2.0.0)
|
60
|
+
websocket (1.2.9)
|
61
|
+
websocket-client-simple (0.3.0)
|
62
|
+
event_emitter
|
63
|
+
websocket
|
64
|
+
|
65
|
+
PLATFORMS
|
66
|
+
x64-mingw32
|
67
|
+
|
68
|
+
DEPENDENCIES
|
69
|
+
advanced_ruby_command_handler!
|
70
|
+
discordrb
|
71
|
+
rake (~> 13.0)
|
72
|
+
rubocop (~> 1.7)
|
73
|
+
|
74
|
+
BUNDLED WITH
|
75
|
+
2.2.26
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 senchuu
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# AdvancedRubyCommandHandler
|
2
|
+
## Installation
|
3
|
+
|
4
|
+
Add this line to your application's Gemfile:
|
5
|
+
|
6
|
+
```ruby
|
7
|
+
gem 'advanced_ruby_command_handler'
|
8
|
+
```
|
9
|
+
|
10
|
+
And then execute:
|
11
|
+
|
12
|
+
$ bundle install
|
13
|
+
|
14
|
+
Or install it yourself as:
|
15
|
+
|
16
|
+
$ gem install advenced_ruby_command_handler
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
### Base Usage
|
21
|
+
|
22
|
+
Firstly, you have to create a ruby file, where you put the followwing line:
|
23
|
+
```rb
|
24
|
+
require "advanced_ruby_command_handler"
|
25
|
+
```
|
26
|
+
|
27
|
+
Then, initialize the command handler. Specifying the directories and the config file path
|
28
|
+
|
29
|
+
```rb
|
30
|
+
client = CommandHandler.new(commands_dir: "src/commands", events_dir: "src/events", config_file: "src/private/config.yml")
|
31
|
+
```
|
32
|
+
Note: if these files dose not exist, the command handler will create them
|
33
|
+
|
34
|
+
And run the bot:
|
35
|
+
```ruby
|
36
|
+
client.run
|
37
|
+
```
|
38
|
+
|
39
|
+
### Events&Commands
|
40
|
+
|
41
|
+
The command handler have base events as message or ready, but you can create your owns events (in events directory).
|
42
|
+
|
43
|
+
Create a file with the name of your event (see https://www.rubydoc.info/github/meew0/discordrb/Discordrb/Events)
|
44
|
+
|
45
|
+
And use the following template:
|
46
|
+
```ruby
|
47
|
+
# frozen_string_literal: true
|
48
|
+
|
49
|
+
module Events
|
50
|
+
def self.<event>(client)
|
51
|
+
client.<event> do
|
52
|
+
client.console_logger.info("Event!")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
```
|
57
|
+
Now, when the event will be emitted, the program will puts "Event!"
|
58
|
+
|
59
|
+
If you want to add some commands in your bot, you can create sub directories in your command directory.
|
60
|
+
In these directories, you can create ruby files for commands, here's an example:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
# frozen_string_literal: true
|
64
|
+
|
65
|
+
require_relative "advanced_ruby_command_handler"
|
66
|
+
|
67
|
+
module Commands
|
68
|
+
def self.hello
|
69
|
+
CommandHandler::Command.new({
|
70
|
+
:name => "hello"
|
71
|
+
}) do |message, client|
|
72
|
+
message.respond "Hello Discord!"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
78
|
+
Now you can create events and commands ! ;)
|
79
|
+
|
80
|
+
## Development
|
81
|
+
|
82
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
83
|
+
|
84
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
85
|
+
|
86
|
+
## Contributing
|
87
|
+
|
88
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Senchuu/Advanced-Bot.rb.
|
89
|
+
|
90
|
+
## License
|
91
|
+
|
92
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/advanced_ruby_command_handler/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "advanced_ruby_command_handler"
|
7
|
+
spec.version = AdvancedRubyCommandHandler::VERSION
|
8
|
+
spec.authors = ["senchuu"]
|
9
|
+
spec.email = ["senchuuuu@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "an advanced discord bot command handler"
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://github.com/Senchuu/Advanced-Bot.rb"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.4.0"
|
16
|
+
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org/"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/Senchuu/Advanced-Bot.rb"
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/Senchuu/Advanced-Bot.rb"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features|logs)/}) }
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
# Uncomment to register a new dependency of your gem
|
33
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
34
|
+
|
35
|
+
# For more information and examples about making a new gem, checkout our
|
36
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
37
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "advanced_ruby_command_handler"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "discordrb"
|
4
|
+
require "fileutils"
|
5
|
+
require "yaml"
|
6
|
+
require_relative "command_handler"
|
7
|
+
require_relative "event_handler"
|
8
|
+
|
9
|
+
module AdvancedRubyCommandHandler
|
10
|
+
class Client < Discordrb::Bot
|
11
|
+
attr_reader :commands_dir, :events_dir, :commands, :config, :console_logger, :file_logger
|
12
|
+
|
13
|
+
def initialize(commands_dir: "commands", events_dir: "events", config_file: "config.yml")
|
14
|
+
FileUtils.mkdir_p [commands_dir, events_dir]
|
15
|
+
@commands_dir = commands_dir
|
16
|
+
@events_dir = events_dir
|
17
|
+
@file_logger = AdvancedRubyCommandHandler::Logger.new(:file)
|
18
|
+
@console_logger = AdvancedRubyCommandHandler::Logger.new(:console)
|
19
|
+
|
20
|
+
base_data = YAML.dump({
|
21
|
+
:token => "",
|
22
|
+
:prefix => "",
|
23
|
+
:owners => []
|
24
|
+
})
|
25
|
+
|
26
|
+
File.open(config_file, "w+") { |file| file.write(base_data) } unless File.exist? config_file
|
27
|
+
|
28
|
+
@config = YAML.load_file(config_file)
|
29
|
+
|
30
|
+
%i[token prefix owners].each do |prop|
|
31
|
+
next if @config[prop] && !@config[prop].empty?
|
32
|
+
|
33
|
+
@console_logger.error("You have to add '#{prop.to_s}' value in your config file")
|
34
|
+
raise "'#{prop}' missing or empty"
|
35
|
+
end
|
36
|
+
|
37
|
+
super(:token => @config[:token])
|
38
|
+
|
39
|
+
@commands = AdvancedRubyCommandHandler::CommandHandler.load_commands(self)
|
40
|
+
AdvancedRubyCommandHandler::EventHandler.load_events(self)
|
41
|
+
.each do |event|
|
42
|
+
Events.method(event).call(self)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def run
|
47
|
+
@console_logger.info("Client login!")
|
48
|
+
|
49
|
+
Thread.new do
|
50
|
+
@console_logger.info("Type '.exit' to turn off the bot")
|
51
|
+
# @console_logger.info("Type '.reload' to reload the bot")
|
52
|
+
|
53
|
+
exit if $stdin.gets.chomp == ".exit"
|
54
|
+
end
|
55
|
+
|
56
|
+
super.run
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "app"
|
4
|
+
|
5
|
+
module AdvancedRubyCommandHandler
|
6
|
+
module CommandHandler
|
7
|
+
def self.load_commands(client)
|
8
|
+
commands = []
|
9
|
+
Dir.entries(client.commands_dir).each do |dir|
|
10
|
+
next if %w[. ..].include?(dir)
|
11
|
+
|
12
|
+
Dir.entries("#{client.commands_dir}/#{dir}").each do |file|
|
13
|
+
next if %w(. ..).include?(file)
|
14
|
+
|
15
|
+
load "#{client.commands_dir}/#{dir}/#{file}"
|
16
|
+
|
17
|
+
commands << File.basename(file, ".rb")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
commands
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "app"
|
4
|
+
|
5
|
+
module AdvancedRubyCommandHandler
|
6
|
+
module EventHandler
|
7
|
+
def self.load_events(client)
|
8
|
+
events = []
|
9
|
+
Dir.entries(client.events_dir).each do |file|
|
10
|
+
next if %w[. ..].include?(file)
|
11
|
+
|
12
|
+
load "#{client.events_dir}/#{file}"
|
13
|
+
events << File.basename(file, ".rb")
|
14
|
+
end
|
15
|
+
|
16
|
+
Dir.entries("lib/advanced_ruby_command_handler/defaults/events").each do |file|
|
17
|
+
next if %w(. ..).include?(file)
|
18
|
+
|
19
|
+
next if events.include?(File.basename(file, ".rb"))
|
20
|
+
|
21
|
+
load "lib/advanced_ruby_command_handler/defaults/events/#{file}"
|
22
|
+
|
23
|
+
events << File.basename(file, ".rb")
|
24
|
+
end
|
25
|
+
|
26
|
+
events
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "fileutils"
|
4
|
+
|
5
|
+
module AdvancedRubyCommandHandler
|
6
|
+
class Logger
|
7
|
+
attr_reader :mode
|
8
|
+
attr_accessor :write_targets
|
9
|
+
|
10
|
+
COLORS = {
|
11
|
+
:default => "\e[38m",
|
12
|
+
:white => "\e[39m",
|
13
|
+
:black => "\e[30m",
|
14
|
+
:red => "\e[31m",
|
15
|
+
:green => "\e[32m",
|
16
|
+
:brown => "\e[33m",
|
17
|
+
:blue => "\e[34m",
|
18
|
+
:magenta => "\e[35m",
|
19
|
+
:cyan => "\e[36m",
|
20
|
+
:gray => "\e[37m",
|
21
|
+
:yellow => "\e[33m"
|
22
|
+
}.freeze
|
23
|
+
MODES = {
|
24
|
+
:info => :cyan,
|
25
|
+
:error => :red,
|
26
|
+
:warn => :yellow,
|
27
|
+
:check => :green
|
28
|
+
}.freeze
|
29
|
+
def initialize(mode = :console, write_targets = { :errors => "logs/errors.txt", :informations => "logs/infos.txt" })
|
30
|
+
@mode = mode.to_sym
|
31
|
+
@write_targets = write_targets if @mode == :file
|
32
|
+
end
|
33
|
+
|
34
|
+
def console_color(color, message)
|
35
|
+
"#{COLORS[color]}#{message}\e[0m"
|
36
|
+
end
|
37
|
+
|
38
|
+
def write(message, write_target = :informations)
|
39
|
+
return Logger.new(:console).warn("The file logs aren't available on #{@mode} mode") unless @mode == :file
|
40
|
+
|
41
|
+
time = Time.now.strftime("%Y-%m-%d-%H:%M:%S")
|
42
|
+
|
43
|
+
FileUtils.mkdir_p File.dirname @write_targets[write_target]
|
44
|
+
|
45
|
+
File.open(@write_targets[write_target], "w") unless File.exist? @write_targets[write_target]
|
46
|
+
|
47
|
+
File.open(@write_targets[write_target], "a+") do |file|
|
48
|
+
file.write("#{time} - #{write_target.to_s.upcase} : #{message}\n")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
MODES.each do |mode, color|
|
53
|
+
define_method(mode) do |message|
|
54
|
+
return Logger.new(:console).warn("The console logs aren't available on #{@mode} mode") unless @mode == :console
|
55
|
+
|
56
|
+
time = Time.now.strftime("%Y-%m-%d-%H:%M:%S")
|
57
|
+
puts "[#{console_color(:magenta, time)}] - [#{console_color(color, mode.to_s.upcase)}] : #{message.to_s}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private :console_color
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../app/utils"
|
4
|
+
|
5
|
+
module Events
|
6
|
+
def self.message(client)
|
7
|
+
client.message(:start_with => client.config[:prefix]) do |message|
|
8
|
+
args = message.content.slice(client.config[:prefix].size, message.content.size).split(" ")
|
9
|
+
name = args.shift
|
10
|
+
command = CommandHandler::Utils.get_command(name)
|
11
|
+
|
12
|
+
next unless command
|
13
|
+
|
14
|
+
command.run.call(message, client)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,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
|
+
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
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../../lib/advanced_ruby_command_handler/app/command"
|
4
|
+
|
5
|
+
module Commands
|
6
|
+
def self.test
|
7
|
+
CommandHandler::Command.new({
|
8
|
+
:name => "test"
|
9
|
+
}) do |message, client|
|
10
|
+
message.respond "Command test!"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/tests/config.yml
ADDED
data/tests/index.rb
ADDED
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: advanced_ruby_command_handler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- senchuu
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-08-26 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: an advanced discord bot command handler
|
14
|
+
email:
|
15
|
+
- senchuuuu@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".rubocop.yml"
|
22
|
+
- CHANGELOG.md
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
25
|
+
- LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- advanced_ruby_command_handler.gemspec
|
29
|
+
- bin/console
|
30
|
+
- bin/setup
|
31
|
+
- lib/advanced_ruby_command_handler.rb
|
32
|
+
- lib/advanced_ruby_command_handler/app/app.rb
|
33
|
+
- lib/advanced_ruby_command_handler/app/client.rb
|
34
|
+
- lib/advanced_ruby_command_handler/app/command.rb
|
35
|
+
- lib/advanced_ruby_command_handler/app/command_handler.rb
|
36
|
+
- lib/advanced_ruby_command_handler/app/event_handler.rb
|
37
|
+
- lib/advanced_ruby_command_handler/app/logger.rb
|
38
|
+
- 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
|
+
- lib/advanced_ruby_command_handler/version.rb
|
42
|
+
- tests/commands/test/test.rb
|
43
|
+
- tests/config.yml
|
44
|
+
- tests/index.rb
|
45
|
+
homepage: https://github.com/Senchuu/Advanced-Bot.rb
|
46
|
+
licenses:
|
47
|
+
- MIT
|
48
|
+
metadata:
|
49
|
+
allowed_push_host: https://rubygems.org/
|
50
|
+
homepage_uri: https://github.com/Senchuu/Advanced-Bot.rb
|
51
|
+
source_code_uri: https://github.com/Senchuu/Advanced-Bot.rb
|
52
|
+
changelog_uri: https://github.com/Senchuu/Advanced-Bot.rb
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.4.0
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubygems_version: 3.2.26
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: an advanced discord bot command handler
|
72
|
+
test_files: []
|