discord_rubot 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/Rubot.iml +3 -7
- data/.rubocop.yml +1 -1
- data/Gemfile +0 -2
- data/Gemfile.lock +10 -10
- data/README.md +88 -5
- data/lib/rubot/classes/client.rb +9 -17
- data/lib/rubot/classes/manager.rb +16 -12
- data/lib/rubot/modules/application_command.rb +48 -0
- data/lib/rubot/version.rb +1 -1
- data/lib/rubot.rb +3 -12
- data/rubot.gemspec +1 -1
- data/sig/application_command.rbs +6 -0
- data/sig/client.rbs +7 -7
- data/sig/manager.rbs +7 -4
- metadata +6 -7
- data/lib/rubot/classes/database.rb +0 -16
- data/lib/rubot/classes/rapplication_command.rb +0 -76
- data/sig/rapplication_command.rbs +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db7d6e3ac9c2e2181a4de55d3dc2ec7e2a6e3ec88321b21958f59d244e15dae9
|
4
|
+
data.tar.gz: d1cf0249feac27f7a67567b7ae940870e8066d8a23380a8667f2fb2c04fddab3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77df0e4d06c7c77f4e647ec165bf8191e99d3bb416a4fff1820a2a97d9483c91250aa651c6ab7e0d187aa9c8fa9960fd03c4ae20963cad940d43203d0432ddbb
|
7
|
+
data.tar.gz: 628cb080edcdf7db65b44b751ccb8f7622d35729d159b597e00cb50e414dfa82067f6e1ef1c89d513cc6ab734c4e0440aa5c31049f1a494c37a8dacc41c9a713
|
data/.idea/Rubot.iml
CHANGED
@@ -14,11 +14,10 @@
|
|
14
14
|
<orderEntry type="sourceFolder" forTests="false" />
|
15
15
|
<orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, RVM: ruby-3.0.0) [gem]" level="application" />
|
16
16
|
<orderEntry type="library" scope="PROVIDED" name="bson (v4.15.0, RVM: ruby-3.0.0) [gem]" level="application" />
|
17
|
-
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.3.4, RVM: ruby-3.0.0) [gem]" level="application" />
|
18
17
|
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.5.0, RVM: ruby-3.0.0) [gem]" level="application" />
|
19
|
-
<orderEntry type="library" scope="PROVIDED" name="discordrb (v3.4.2@
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="discordrb (v3.4.2@dc27fe, RVM: ruby-3.0.0) [gem]" level="application" />
|
20
19
|
<orderEntry type="library" scope="PROVIDED" name="domain_name (v0.5.20190701, RVM: ruby-3.0.0) [gem]" level="application" />
|
21
|
-
<orderEntry type="library" scope="PROVIDED" name="dotenv (v2.
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="dotenv (v2.8.1, RVM: ruby-3.0.0) [gem]" level="application" />
|
22
21
|
<orderEntry type="library" scope="PROVIDED" name="event_emitter (v0.2.6, RVM: ruby-3.0.0) [gem]" level="application" />
|
23
22
|
<orderEntry type="library" scope="PROVIDED" name="ffi (v1.15.5, RVM: ruby-3.0.0) [gem]" level="application" />
|
24
23
|
<orderEntry type="library" scope="PROVIDED" name="http-accept (v1.7.0, RVM: ruby-3.0.0) [gem]" level="application" />
|
@@ -26,11 +25,10 @@
|
|
26
25
|
<orderEntry type="library" scope="PROVIDED" name="json (v2.6.2, RVM: ruby-3.0.0) [gem]" level="application" />
|
27
26
|
<orderEntry type="library" scope="PROVIDED" name="mime-types (v3.4.1, RVM: ruby-3.0.0) [gem]" level="application" />
|
28
27
|
<orderEntry type="library" scope="PROVIDED" name="mime-types-data (v3.2022.0105, RVM: ruby-3.0.0) [gem]" level="application" />
|
29
|
-
<orderEntry type="library" scope="PROVIDED" name="mongo (v2.18.
|
28
|
+
<orderEntry type="library" scope="PROVIDED" name="mongo (v2.18.1, RVM: ruby-3.0.0) [gem]" level="application" />
|
30
29
|
<orderEntry type="library" scope="PROVIDED" name="netrc (v0.11.0, RVM: ruby-3.0.0) [gem]" level="application" />
|
31
30
|
<orderEntry type="library" scope="PROVIDED" name="opus-ruby (v1.0.1, RVM: ruby-3.0.0) [gem]" level="application" />
|
32
31
|
<orderEntry type="library" scope="PROVIDED" name="parallel (v1.22.1, RVM: ruby-3.0.0) [gem]" level="application" />
|
33
|
-
<orderEntry type="library" scope="PROVIDED" name="parser (v3.1.2.0, RVM: ruby-3.0.0) [gem]" level="application" />
|
34
32
|
<orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, RVM: ruby-3.0.0) [gem]" level="application" />
|
35
33
|
<orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, RVM: ruby-3.0.0) [gem]" level="application" />
|
36
34
|
<orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.5.0, RVM: ruby-3.0.0) [gem]" level="application" />
|
@@ -41,8 +39,6 @@
|
|
41
39
|
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.11.0, RVM: ruby-3.0.0) [gem]" level="application" />
|
42
40
|
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.11.1, RVM: ruby-3.0.0) [gem]" level="application" />
|
43
41
|
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.11.0, RVM: ruby-3.0.0) [gem]" level="application" />
|
44
|
-
<orderEntry type="library" scope="PROVIDED" name="rubocop (v1.31.2, RVM: ruby-3.0.0) [gem]" level="application" />
|
45
|
-
<orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.19.1, RVM: ruby-3.0.0) [gem]" level="application" />
|
46
42
|
<orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.11.0, RVM: ruby-3.0.0) [gem]" level="application" />
|
47
43
|
<orderEntry type="library" scope="PROVIDED" name="unf (v0.1.4, RVM: ruby-3.0.0) [gem]" level="application" />
|
48
44
|
<orderEntry type="library" scope="PROVIDED" name="unf_ext (v0.0.8.2, RVM: ruby-3.0.0) [gem]" level="application" />
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
GIT
|
2
2
|
remote: https://github.com/shardlab/discordrb
|
3
|
-
revision:
|
3
|
+
revision: dc27fe18463da3ccfd0f0266030aa7ad51b2c2b9
|
4
4
|
branch: main
|
5
5
|
specs:
|
6
6
|
discordrb (3.4.2)
|
@@ -15,7 +15,7 @@ GIT
|
|
15
15
|
PATH
|
16
16
|
remote: .
|
17
17
|
specs:
|
18
|
-
discord_rubot (0.1.
|
18
|
+
discord_rubot (0.1.4)
|
19
19
|
|
20
20
|
GEM
|
21
21
|
remote: https://rubygems.org/
|
@@ -25,7 +25,7 @@ GEM
|
|
25
25
|
diff-lcs (1.5.0)
|
26
26
|
domain_name (0.5.20190701)
|
27
27
|
unf (>= 0.0.5, < 1.0.0)
|
28
|
-
dotenv (2.
|
28
|
+
dotenv (2.8.1)
|
29
29
|
event_emitter (0.2.6)
|
30
30
|
ffi (1.15.5)
|
31
31
|
http-accept (1.7.0)
|
@@ -35,13 +35,13 @@ GEM
|
|
35
35
|
mime-types (3.4.1)
|
36
36
|
mime-types-data (~> 3.2015)
|
37
37
|
mime-types-data (3.2022.0105)
|
38
|
-
mongo (2.18.
|
38
|
+
mongo (2.18.1)
|
39
39
|
bson (>= 4.14.1, < 5.0.0)
|
40
40
|
netrc (0.11.0)
|
41
41
|
opus-ruby (1.0.1)
|
42
42
|
ffi
|
43
43
|
parallel (1.22.1)
|
44
|
-
parser (3.1.2.
|
44
|
+
parser (3.1.2.1)
|
45
45
|
ast (~> 2.4.1)
|
46
46
|
rainbow (3.1.1)
|
47
47
|
rake (13.0.6)
|
@@ -65,17 +65,17 @@ GEM
|
|
65
65
|
diff-lcs (>= 1.2.0, < 2.0)
|
66
66
|
rspec-support (~> 3.11.0)
|
67
67
|
rspec-support (3.11.0)
|
68
|
-
rubocop (1.
|
68
|
+
rubocop (1.35.1)
|
69
69
|
json (~> 2.3)
|
70
70
|
parallel (~> 1.10)
|
71
|
-
parser (>= 3.1.
|
71
|
+
parser (>= 3.1.2.1)
|
72
72
|
rainbow (>= 2.2.2, < 4.0)
|
73
73
|
regexp_parser (>= 1.8, < 3.0)
|
74
74
|
rexml (>= 3.2.5, < 4.0)
|
75
|
-
rubocop-ast (>= 1.
|
75
|
+
rubocop-ast (>= 1.20.1, < 2.0)
|
76
76
|
ruby-progressbar (~> 1.7)
|
77
77
|
unicode-display_width (>= 1.4.0, < 3.0)
|
78
|
-
rubocop-ast (1.
|
78
|
+
rubocop-ast (1.21.0)
|
79
79
|
parser (>= 3.1.1.0)
|
80
80
|
ruby-progressbar (1.11.0)
|
81
81
|
unf (0.1.4)
|
@@ -100,4 +100,4 @@ DEPENDENCIES
|
|
100
100
|
rubocop
|
101
101
|
|
102
102
|
BUNDLED WITH
|
103
|
-
2.3.
|
103
|
+
2.3.7
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[![Les Laboratoires Ruby](https://invidget.switchblade.xyz/4P7XcmbDnt)](https://discord.gg/4P7XcmbDnt)
|
2
|
+
|
1
3
|
# Rubot
|
2
4
|
|
3
5
|
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/Rubot`. To experiment with that code, run `bin/console` for an interactive prompt.
|
@@ -9,7 +11,7 @@ TODO: Delete this and the text above, and describe your gem
|
|
9
11
|
Add this line to your application's Gemfile:
|
10
12
|
|
11
13
|
```ruby
|
12
|
-
gem '
|
14
|
+
gem 'discord_rubot'
|
13
15
|
```
|
14
16
|
|
15
17
|
And then execute:
|
@@ -18,11 +20,92 @@ And then execute:
|
|
18
20
|
|
19
21
|
Or install it yourself as:
|
20
22
|
|
21
|
-
$ gem install
|
23
|
+
$ gem install discord_rubot
|
22
24
|
|
23
25
|
## Usage
|
24
26
|
|
25
|
-
|
27
|
+
### Install gems
|
28
|
+
Before starting to use the command handler. You have to figure some gem requirements in your Gemfile :
|
29
|
+
```rb
|
30
|
+
source "https://rubygems.org"
|
31
|
+
|
32
|
+
gem 'discord_rubot', "~> 0.1.3"
|
33
|
+
gem "discordrb", :git => "https://github.com/shardlab/discordrb", :branch => "main"
|
34
|
+
gem "dotenv"
|
35
|
+
gem "mongo", "~> 2.18"
|
36
|
+
```
|
37
|
+
Then run `bundle updte` and `bundle install` to install the gems. Now you can start using the command handler.
|
38
|
+
|
39
|
+
### Setting up the command handler
|
40
|
+
|
41
|
+
To create your environment you have 3 things to do.
|
42
|
+
First, you have to create a `.env` file where you register your bot token
|
43
|
+
```dotenv
|
44
|
+
BOT_TOKEN=<your bot token>
|
45
|
+
```
|
46
|
+
Then you have to create your main file where you set up Rubot
|
47
|
+
```ruby
|
48
|
+
require "rubot"
|
49
|
+
|
50
|
+
client = Rubot.new("<your commands directory>", "<your events directory>")
|
51
|
+
client.run
|
52
|
+
```
|
53
|
+
This simple code load the bot, and set up the commands and events (commands are regular commands and slash commands (known as application_commands)).
|
54
|
+
|
55
|
+
Before launching your application you have to create the `commands` and `events` directories.
|
56
|
+
|
57
|
+
### Start coding
|
58
|
+
|
59
|
+
Now, you can start coding your commands and events.
|
60
|
+
Register a command and an event is very simple.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
require "rubot"
|
64
|
+
|
65
|
+
Rubot.client.add_command(:ping, "Ping") do |event|
|
66
|
+
event.message.respond "Pong"
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
This is a command example, The simple commands are not very interesting because the application commands exist.
|
71
|
+
|
72
|
+
Now let's see an application_command
|
73
|
+
```ruby
|
74
|
+
require "rubot"
|
75
|
+
|
76
|
+
Rubot.client.add_application_command(**Hash[
|
77
|
+
:command => Hash[:name => "test", :description => "Test a command"],
|
78
|
+
:proprieties => [
|
79
|
+
Hash[:type => :user, :name => :user, :description => "Who's tested ?", :required => true],
|
80
|
+
]
|
81
|
+
]) do |event|
|
82
|
+
event.respond(:embeds => [Rubot::BetterEmbed.new(:default).description("Test")]) do |_, view|
|
83
|
+
view.row do |r|
|
84
|
+
r.button(:label => "Test!", :style => :success, :custom_id => "test_button:1")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
Rubot.client.button(:custom_id => /test_button:1/) do |_button_event|
|
89
|
+
embed = Rubot::BetterEmbed.new(:success)
|
90
|
+
embed.description("Wa")
|
91
|
+
event.edit_response(:embeds => [embed])
|
92
|
+
end
|
93
|
+
end
|
94
|
+
```
|
95
|
+
|
96
|
+
This is a simple example. You can add the :subcommand (use it as command) key in your hash to register a subcommand. You can add proprieties. See the discordrb doc.
|
97
|
+
|
98
|
+
And now an event example
|
99
|
+
```ruby
|
100
|
+
require "rubot"
|
101
|
+
|
102
|
+
Rubot.client.add_event(:name => "ready") do
|
103
|
+
puts "Ready to use!"
|
104
|
+
end
|
105
|
+
```
|
106
|
+
As simple as that !
|
107
|
+
|
108
|
+
Iy you have an issue, create a GitHub issue I'll help you. You can also join the Ruby Lab discord server.
|
26
109
|
|
27
110
|
## Development
|
28
111
|
|
@@ -32,7 +115,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
115
|
|
33
116
|
## Contributing
|
34
117
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
118
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Senchuu/Rubot. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/Senchuu/Rubot/blob/master/CODE_OF_CONDUCT.md).
|
36
119
|
|
37
120
|
## License
|
38
121
|
|
@@ -40,4 +123,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
40
123
|
|
41
124
|
## Code of Conduct
|
42
125
|
|
43
|
-
Everyone interacting in the Rubot project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
126
|
+
Everyone interacting in the Rubot project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Senchuu/Rubot/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/rubot/classes/client.rb
CHANGED
@@ -5,18 +5,22 @@ require "dotenv/load"
|
|
5
5
|
require File.expand_path("manager", File.dirname(__FILE__))
|
6
6
|
require File.expand_path("command", File.dirname(__FILE__))
|
7
7
|
require File.expand_path("event", File.dirname(__FILE__))
|
8
|
-
require File.expand_path("
|
8
|
+
require File.expand_path("../modules/application_command", File.dirname(__FILE__))
|
9
9
|
|
10
10
|
module Rubot
|
11
11
|
class Client < Discordrb::Bot
|
12
|
-
attr_reader :commands, :events, :
|
12
|
+
attr_reader :commands, :events, :application_commands_queue, :manager
|
13
13
|
|
14
|
-
|
14
|
+
include ApplicationCommand
|
15
|
+
def initialize(application_commands_path:, commands_path: nil, events_path: nil)
|
16
|
+
@manager = Manager.new(application_commands_path: application_commands_path, commands_path: commands_path, events_path: events_path)
|
15
17
|
super(:token => ENV["BOT_TOKEN"], :intents => :all, :ignore_bots => true)
|
16
18
|
end
|
17
19
|
|
18
20
|
def run(background = false)
|
19
|
-
@
|
21
|
+
@manager.load
|
22
|
+
launch_application_commands
|
23
|
+
@events&.each(&:run)
|
20
24
|
Thread.new do
|
21
25
|
loop do
|
22
26
|
stop if $stdin.gets.chomp.downcase.match?(/^\.exit/)
|
@@ -43,23 +47,11 @@ module Rubot
|
|
43
47
|
@events[name] || false
|
44
48
|
end
|
45
49
|
|
46
|
-
def add_application_command(command:, subcommand: nil, group: nil, proprieties: nil, default_permission: nil, &block)
|
47
|
-
@rapplication_commands ||= Array[]
|
48
|
-
command = RApplicationCommand.new(self, :command => command, :subcommand => subcommand, :group => group, :props => proprieties, :default_permissions => default_permission, &block)
|
49
|
-
command.create
|
50
|
-
@rapplication_commands << command
|
51
|
-
end
|
52
|
-
|
53
50
|
def remove_application_commands
|
54
51
|
get_application_commands.map(&:id).each do |id|
|
55
52
|
delete_application_command(id)
|
56
53
|
end
|
57
|
-
@
|
58
|
-
end
|
59
|
-
|
60
|
-
def stop(_no_sync = nil)
|
61
|
-
remove_application_commands
|
62
|
-
super
|
54
|
+
@application_commands = Array[]
|
63
55
|
end
|
64
56
|
end
|
65
57
|
end
|
@@ -4,38 +4,42 @@ require "fileutils"
|
|
4
4
|
|
5
5
|
module Rubot
|
6
6
|
class Manager
|
7
|
-
attr_accessor :commands_path, :events_path
|
7
|
+
attr_accessor :application_commands_path, :commands_path, :events_path
|
8
8
|
|
9
|
-
def initialize(commands_path, events_path)
|
9
|
+
def initialize(application_commands_path:, commands_path: nil, events_path: nil)
|
10
|
+
@application_commands_path = application_commands_path
|
10
11
|
@commands_path = commands_path
|
11
12
|
@events_path = events_path
|
12
13
|
end
|
13
14
|
|
14
15
|
def files(path)
|
15
|
-
|
16
|
-
Dir.entries(path).each do |entry|
|
16
|
+
Dir.entries(path).each_with_object([]) do |entry, files|
|
17
17
|
next if %w[. ..].include?(entry)
|
18
18
|
|
19
|
-
if Dir.exist?("#{@
|
19
|
+
if Dir.exist?("#{@application_commands_path}/#{entry}")
|
20
20
|
files.concat(files("#{path}/#{entry}"))
|
21
21
|
else
|
22
22
|
files << "#{path}/#{entry}" unless files.include?("#{path}/#{entry}")
|
23
23
|
end
|
24
24
|
end
|
25
|
-
files
|
26
25
|
end
|
27
26
|
|
28
|
-
def
|
29
|
-
files(@
|
27
|
+
def application_commands_files
|
28
|
+
files(@application_commands_path)
|
30
29
|
end
|
31
30
|
|
32
|
-
def
|
33
|
-
files(@
|
31
|
+
def commands_files
|
32
|
+
files(@commands_path) if @commands_path
|
33
|
+
end
|
34
|
+
|
35
|
+
def events_files
|
36
|
+
files(@events_path) if @events_path
|
34
37
|
end
|
35
38
|
|
36
39
|
def load
|
37
|
-
|
38
|
-
|
40
|
+
application_commands_files.each { |file| Kernel.load file }
|
41
|
+
commands_files&.each { |file| Kernel.load file }
|
42
|
+
events_files&.each { |file| Kernel.load file }
|
39
43
|
true
|
40
44
|
end
|
41
45
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "discordrb"
|
4
|
+
|
5
|
+
module Rubot
|
6
|
+
module ApplicationCommand
|
7
|
+
def add_application_command(command:, subcommand: nil, group: nil, options: ->(option_builder) { option_builder }, &block)
|
8
|
+
@application_commands_queue ||= Array[]
|
9
|
+
@application_commands_queue << Hash[
|
10
|
+
:command => command,
|
11
|
+
:subcommand => subcommand,
|
12
|
+
:group => group,
|
13
|
+
:options => options,
|
14
|
+
:run => block
|
15
|
+
]
|
16
|
+
end
|
17
|
+
|
18
|
+
def launch_application_commands
|
19
|
+
@application_commands_queue.each do |command|
|
20
|
+
command.transform_keys!(&:to_sym)
|
21
|
+
register_application_command(command[:command][:name].to_s, command[:command][:description].to_s) do |option_builder|
|
22
|
+
if command[:subcommand]
|
23
|
+
@application_commands_queue.each do |subcommand|
|
24
|
+
next unless subcommand[:command][:name] == command[:command][:name] && subcommand[:subcommand]
|
25
|
+
|
26
|
+
option_builder.subcommand(subcommand[:subcommand][:name].to_s, subcommand[:subcommand][:description].to_s) do |sub_option_builder|
|
27
|
+
command[:options].call(sub_option_builder)
|
28
|
+
end
|
29
|
+
@application_commands_queue.delete(subcommand)
|
30
|
+
end
|
31
|
+
else
|
32
|
+
command[:options].call(option_builder)
|
33
|
+
@application_commands_queue.delete(command)
|
34
|
+
end
|
35
|
+
|
36
|
+
cmd = application_command(command[:command][:name].to_sym) do |event|
|
37
|
+
command[:run].call(event) unless command[:subcommand]
|
38
|
+
end
|
39
|
+
next unless command[:subcommand]
|
40
|
+
|
41
|
+
cmd.subcommand(command[:subcommand][:name].to_sym) do |event|
|
42
|
+
command[:run].call(event) if command[:subcommand]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/rubot/version.rb
CHANGED
data/lib/rubot.rb
CHANGED
@@ -5,13 +5,10 @@ require File.expand_path("rubot/classes/client", File.dirname(__FILE__))
|
|
5
5
|
require File.expand_path("rubot/utils/better_embed", File.dirname(__FILE__))
|
6
6
|
|
7
7
|
module Rubot
|
8
|
-
def self.new(commands_path, events_path)
|
8
|
+
def self.new(application_commands_path:, commands_path: nil, events_path: nil)
|
9
9
|
raise "Rubot already initialized. Call Rubot.client to access client." if @client
|
10
10
|
|
11
|
-
@client = Rubot::Client.new
|
12
|
-
@manager = Rubot::Manager.new(commands_path, events_path)
|
13
|
-
@client.remove_application_commands
|
14
|
-
@manager.load
|
11
|
+
@client = Rubot::Client.new(application_commands_path: application_commands_path, commands_path: commands_path, events_path: events_path)
|
15
12
|
@client
|
16
13
|
end
|
17
14
|
|
@@ -19,12 +16,6 @@ module Rubot
|
|
19
16
|
def self.client
|
20
17
|
return @client if @client
|
21
18
|
|
22
|
-
raise "Rubot is not initialized. Call Rubot.new
|
19
|
+
raise "Rubot is not initialized. Call Rubot.new first."
|
23
20
|
end
|
24
|
-
|
25
|
-
# @return [Rubot::Manager]
|
26
|
-
def self.manager
|
27
|
-
return @manager if @manager
|
28
|
-
|
29
|
-
raise "Rubot is not initialized. Call Rubot.new(commands_path, events_path) first." end
|
30
21
|
end
|
data/rubot.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.description = "Use rubot as a command handler for, your ruby written discord bot. Simply to use, and fun!"
|
13
13
|
spec.homepage = "https://github.com/Senchuu/rubot"
|
14
14
|
spec.license = "MIT"
|
15
|
-
spec.required_ruby_version = ">=
|
15
|
+
spec.required_ruby_version = ">= 3.0.0"
|
16
16
|
|
17
17
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
18
|
|
data/sig/client.rbs
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
module Rubot
|
2
2
|
class Client
|
3
|
-
attr_reader commands: Array[Command]
|
4
|
-
attr_reader events: Array[Event]
|
5
|
-
attr_reader
|
3
|
+
attr_reader commands: Array[Command]?
|
4
|
+
attr_reader events: Array[Event]?
|
5
|
+
attr_reader application_commands_queue: Array[ApplicationCommand]?
|
6
|
+
attr_reader manager: Manager
|
6
7
|
|
7
8
|
def intialize: -> void
|
8
9
|
def run: (bool) -> void
|
9
|
-
def add_command: (name: String, block: Proc) -> Command
|
10
|
+
def add_command: (name: String, block: Proc) -> Array[Command]
|
10
11
|
def command: (String) -> (Command | false)
|
11
|
-
def add_event: (?Hash[Symbol, Object], Proc, name: String) -> Event
|
12
|
+
def add_event: (?Hash[Symbol, Object], Proc, name: String) -> Array[Event]
|
12
13
|
def event: (String) -> (Event | false)
|
13
|
-
def add_application_command: (command: Hash[Symbol, String], subcommand: Hash[Symbol, String]?, group:
|
14
|
+
def add_application_command: (command: Hash[Symbol, String], subcommand: Hash[Symbol, String]?, group: String?) -> void
|
14
15
|
def remove_application_commands: () -> []
|
15
|
-
def stop: () -> void
|
16
16
|
end
|
17
17
|
end
|
data/sig/manager.rbs
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
module Rubot
|
2
2
|
class Manager
|
3
|
-
attr_accessor
|
3
|
+
attr_accessor application_commands_path: String
|
4
|
+
attr_accessor commands_path: String?
|
5
|
+
attr_accessor events_path: String?
|
4
6
|
|
5
|
-
def initialize: (String) -> void
|
7
|
+
def initialize: (application_commands_path: String, commands_path: String?, events_path: String?) -> void
|
6
8
|
def files: (String) -> Array[String]
|
7
9
|
def load_commands: (Array[String]) -> void
|
8
|
-
def
|
9
|
-
def
|
10
|
+
def commands_files: -> Array[String]?
|
11
|
+
def events_files: -> Array[String]?
|
12
|
+
def application_commands_files: -> Array[String]
|
10
13
|
def load: -> bool
|
11
14
|
end
|
12
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discord_rubot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Senchuu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Use rubot as a command handler for, your ruby written discord bot. Simply
|
14
14
|
to use, and fun!
|
@@ -37,18 +37,17 @@ files:
|
|
37
37
|
- lib/rubot.rb
|
38
38
|
- lib/rubot/classes/client.rb
|
39
39
|
- lib/rubot/classes/command.rb
|
40
|
-
- lib/rubot/classes/database.rb
|
41
40
|
- lib/rubot/classes/event.rb
|
42
41
|
- lib/rubot/classes/manager.rb
|
43
|
-
- lib/rubot/
|
42
|
+
- lib/rubot/modules/application_command.rb
|
44
43
|
- lib/rubot/utils/better_embed.rb
|
45
44
|
- lib/rubot/version.rb
|
46
45
|
- rubot.gemspec
|
46
|
+
- sig/application_command.rbs
|
47
47
|
- sig/client.rbs
|
48
48
|
- sig/command.rbs
|
49
49
|
- sig/event.rbs
|
50
50
|
- sig/manager.rbs
|
51
|
-
- sig/rapplication_command.rbs
|
52
51
|
- sig/rubot.rbs
|
53
52
|
homepage: https://github.com/Senchuu/rubot
|
54
53
|
licenses:
|
@@ -65,14 +64,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
64
|
requirements:
|
66
65
|
- - ">="
|
67
66
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
67
|
+
version: 3.0.0
|
69
68
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
69
|
requirements:
|
71
70
|
- - ">="
|
72
71
|
- !ruby/object:Gem::Version
|
73
72
|
version: '0'
|
74
73
|
requirements: []
|
75
|
-
rubygems_version: 3.
|
74
|
+
rubygems_version: 3.3.7
|
76
75
|
signing_key:
|
77
76
|
specification_version: 4
|
78
77
|
summary: A most advanced version of Bot.rb
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "mongo"
|
4
|
-
|
5
|
-
module Rubot
|
6
|
-
class Database < Mongo::Client
|
7
|
-
def initialize(addresses_or_uri, options = nil)
|
8
|
-
super
|
9
|
-
end
|
10
|
-
|
11
|
-
def ensure(collection, schema)
|
12
|
-
c = self[collection]
|
13
|
-
c.insert_one(schema)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "discordrb"
|
4
|
-
|
5
|
-
module Rubot
|
6
|
-
class RApplicationCommand
|
7
|
-
attr_reader :client, :command, :subcommand, :group, :execute, :props, :id, :default_permissions
|
8
|
-
|
9
|
-
def initialize(client, command:, subcommand: nil, group: nil, props: nil, default_permissions: nil, &block)
|
10
|
-
@client = client
|
11
|
-
@command = command
|
12
|
-
@subcommand = subcommand
|
13
|
-
@group = group
|
14
|
-
@props = props
|
15
|
-
@default_permissions = default_permissions
|
16
|
-
@execute = block
|
17
|
-
end
|
18
|
-
|
19
|
-
def create
|
20
|
-
@client.register_application_command(@command[:name].to_sym, @command[:description]) do |command|
|
21
|
-
unless @subcommand
|
22
|
-
proprieties(command) if @props
|
23
|
-
permissions(command) if @default_permissions
|
24
|
-
next
|
25
|
-
end
|
26
|
-
|
27
|
-
if @group
|
28
|
-
command.group(@group[:name].to_sym, @group[:description]) do |group|
|
29
|
-
group.command(@subcommand[:name].to_sym, @subcommand[:description]) do |b|
|
30
|
-
proprieties(b) if @props
|
31
|
-
permissions(command) if @default_permissions
|
32
|
-
end
|
33
|
-
end
|
34
|
-
else
|
35
|
-
command.subcommand(@subcommand[:name].to_sym, @subcommand[:description]) do |b|
|
36
|
-
proprieties(b) if @props
|
37
|
-
permissions(command) if @default_permissions
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
command = @client.application_command(@command[:name].to_sym) do |event|
|
43
|
-
@id = event.command_id
|
44
|
-
@execute.call(event)
|
45
|
-
end
|
46
|
-
|
47
|
-
return unless @subcommand
|
48
|
-
|
49
|
-
command.subcommand(@subcommand[:name].to_sym) do |event|
|
50
|
-
@id = event.command_id
|
51
|
-
@execute.call(event)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def proprieties(builder)
|
56
|
-
attributes = %i[boolean integer channel number role string user]
|
57
|
-
@props.each do |prop|
|
58
|
-
next unless attributes.include?(prop[:type])
|
59
|
-
|
60
|
-
builder.method(prop[:type].to_sym).parameters.each do |type, name|
|
61
|
-
raise "Missing required key #{name} in #{prop[:type]} propriety" if type == :req && !prop.key?(name)
|
62
|
-
end
|
63
|
-
|
64
|
-
builder.method(prop.delete(:type)).call(prop.delete(:name), prop.delete(:description), **prop)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def permissions(builder); end
|
69
|
-
|
70
|
-
def application_command
|
71
|
-
return nil unless @id
|
72
|
-
|
73
|
-
@client.get_application_command(@id)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Rubot
|
2
|
-
class RApplicationCommand
|
3
|
-
attr_reader client: Rubot::Client
|
4
|
-
attr_reader command: Hash[Symbol, String]
|
5
|
-
attr_reader subcommand: Hash[Symbol, String]?
|
6
|
-
attr_reader group: Symbol?
|
7
|
-
attr_reader execute: Proc
|
8
|
-
attr_reader props: Hash[Symbol, String]?
|
9
|
-
attr_reader application_command: Discordrb::ApplicationCommand?
|
10
|
-
|
11
|
-
def initialize: (Rubot::Client, command: Hash[Symbol, String], subcommand: Hash[Symbol, String]?, group: Symbol?, props: Hash[Symbol, String]?) -> void
|
12
|
-
def create: -> void
|
13
|
-
def proprieties: -> void
|
14
|
-
end
|
15
|
-
end
|