ezdrb 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +43 -4
- data/ezdrb.gemspec +2 -1
- data/lib/ezdrb/cli.rb +28 -147
- data/lib/ezdrb/templates/Attributes.erb +29 -0
- data/lib/ezdrb/templates/BotRun.erb +14 -0
- data/lib/ezdrb/templates/BotYml.erb +2 -0
- data/lib/ezdrb/templates/Commands.erb +22 -0
- data/lib/ezdrb/templates/Events.erb +22 -0
- data/lib/ezdrb/templates/SingleCommand.erb +11 -0
- data/lib/ezdrb/templates/SingleEvent.erb +11 -0
- data/lib/ezdrb/version.rb +1 -1
- metadata +27 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc9e729492ac8433318f7503f60fd273b265c0044279f8c32870bd82b977d77b
|
4
|
+
data.tar.gz: 795892edc5b970210d1bf4f6dd79d743d9b5280cdd83dfdf42d5d33e86947da1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 197163660adf42d236816548e732d30f768ae667e74ce56b0f8f043579a2573d2f13346306b24fa087aa495e86723f91a72046c56fdeecc2b6aac3aec9f6f5ca
|
7
|
+
data.tar.gz: 13df088e3c8ed94cafd43dc63e9a366bbf4d0e1f13441532d9ed2c82e0016b49aaafd19a5cb4b30cc1547cb714b9c8cb64b48a38de53b5d9d6f4de14cc7e5ea9
|
data/README.md
CHANGED
@@ -12,6 +12,7 @@ Write Discord bots faster (Discordrb-only).
|
|
12
12
|
## Commands available
|
13
13
|
|
14
14
|
* `help [command]`: Lists all commands available.
|
15
|
+
* `event <event>`: Creates new event handler (see all available events: https://www.rubydoc.info/github/meew0/discordrb/Discordrb/EventContainer)
|
15
16
|
* `init`: Creates a new bot in the current directory (recommended: run this in an empty directory)
|
16
17
|
* `command <command>`: Creates a new bot command. You can find all bot commands in the *commands/* directory.
|
17
18
|
|
@@ -51,14 +52,14 @@ commands:
|
|
51
52
|
|
52
53
|
**3\. Edit commands:**
|
53
54
|
|
54
|
-
|
55
|
+
Open `commands/Ping.rb` with your favorite text editor. You should get something like this:
|
55
56
|
|
56
57
|
```ruby
|
57
58
|
class Ping
|
58
59
|
|
59
60
|
def activate(bot)
|
60
61
|
bot.command :ping do |event|
|
61
|
-
|
62
|
+
puts "pong!"
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
@@ -69,7 +70,43 @@ Ping.new
|
|
69
70
|
|
70
71
|
Write your command script inside the `bot.command` block.
|
71
72
|
|
72
|
-
**4\.
|
73
|
+
**4\. Add event handlers to the bot:**
|
74
|
+
|
75
|
+
```
|
76
|
+
$ ezdrb event channel_create
|
77
|
+
```
|
78
|
+
|
79
|
+
All bot handlers are stored in `config/events.yml`:
|
80
|
+
|
81
|
+
```
|
82
|
+
$ cat config/events.yml
|
83
|
+
events:
|
84
|
+
- Channel_create
|
85
|
+
```
|
86
|
+
|
87
|
+
See all available events [here](https://www.rubydoc.info/github/meew0/discordrb/Discordrb/EventContainer).
|
88
|
+
|
89
|
+
**5\. Edit handlers**
|
90
|
+
|
91
|
+
Open `commands/Channel_create.rb` with your favorite text editor. You should get something like this:
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
class Channel_create
|
95
|
+
|
96
|
+
def activate(bot)
|
97
|
+
bot.channel_create do |event|
|
98
|
+
puts "channel has been added"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
Channel_create.new
|
105
|
+
```
|
106
|
+
|
107
|
+
Write what your bot should do when the event is triggered inside the `bot.channel_create` block.
|
108
|
+
|
109
|
+
**6\. Run the bot:**
|
73
110
|
|
74
111
|
Run `bot.rb`:
|
75
112
|
|
@@ -78,9 +115,11 @@ Run `bot.rb`:
|
|
78
115
|
## To do
|
79
116
|
|
80
117
|
- delete a bot command
|
81
|
-
- add events
|
118
|
+
- ~~add events~~
|
82
119
|
- remove events
|
83
120
|
- run the bot from ezdrb
|
121
|
+
- ~~use erb for code generation~~
|
122
|
+
- rewrite commands structure
|
84
123
|
|
85
124
|
|
86
125
|
## License
|
data/ezdrb.gemspec
CHANGED
@@ -16,7 +16,8 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
17
17
|
spec.add_development_dependency 'rake'
|
18
18
|
|
19
|
-
spec.add_runtime_dependency 'thor'
|
19
|
+
spec.add_runtime_dependency 'thor', '~> 0.20.0'
|
20
|
+
spec.add_runtime_dependency 'discordrb', '~> 3.2.1'
|
20
21
|
|
21
22
|
spec.files = `git ls-files`.split($/)
|
22
23
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
data/lib/ezdrb/cli.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
# module Discordrb
|
6
|
-
# end
|
7
|
-
|
8
|
-
require 'thor'
|
3
|
+
require 'bundler/cli'
|
9
4
|
require 'yaml'
|
5
|
+
require 'erb'
|
6
|
+
require 'thor'
|
7
|
+
|
10
8
|
require 'ezdrb'
|
11
9
|
|
12
10
|
module Ezdrb
|
@@ -18,7 +16,14 @@ module Ezdrb
|
|
18
16
|
var
|
19
17
|
end
|
20
18
|
|
19
|
+
def self.load_template(template)
|
20
|
+
ERB.new(File.read("#{Bundler.rubygems.find_name('ezdrb').first.full_gem_path}/lib/ezdrb/templates/#{template}.erb"), 0, '%<>')
|
21
|
+
end
|
22
|
+
|
21
23
|
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module Ezdrb
|
22
27
|
|
23
28
|
class CLI < Thor
|
24
29
|
|
@@ -41,12 +46,8 @@ module Ezdrb
|
|
41
46
|
Dir.mkdir('events')
|
42
47
|
|
43
48
|
File.open('config/bot.yml', 'w') do |file|
|
44
|
-
|
45
|
-
|
46
|
-
prefix: '#{prefix.strip}'
|
47
|
-
token: '#{token.strip}'
|
48
|
-
HEREDOC
|
49
|
-
)
|
49
|
+
template = Helpers::load_template('BotYml').result(binding)
|
50
|
+
file.write(template)
|
50
51
|
end
|
51
52
|
|
52
53
|
File.open('config/commands.yml', 'w') do |file|
|
@@ -66,118 +67,23 @@ module Ezdrb
|
|
66
67
|
end
|
67
68
|
|
68
69
|
File.open('Attributes.rb', 'w') do |file|
|
69
|
-
|
70
|
-
|
71
|
-
require 'yaml'
|
72
|
-
|
73
|
-
class Attributes
|
74
|
-
|
75
|
-
def self.parse
|
76
|
-
begin
|
77
|
-
config = YAML.load_file('config/bot.yml')
|
78
|
-
rescue => e
|
79
|
-
puts "ERROR: Couldn't read bot.yml"
|
80
|
-
exit!
|
81
|
-
end
|
82
|
-
|
83
|
-
@prefix = config['prefix']
|
84
|
-
@token = config['token']
|
85
|
-
|
86
|
-
if @prefix.nil? then
|
87
|
-
puts 'ERROR: You must set a prefix'
|
88
|
-
exit!
|
89
|
-
elsif @token.nil? then
|
90
|
-
puts 'ERROR: You must set a token'
|
91
|
-
exit!
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
class << self
|
97
|
-
attr_reader :prefix, :token
|
98
|
-
end
|
99
|
-
end
|
100
|
-
HEREDOC
|
101
|
-
)
|
70
|
+
template = Helpers::load_template('Attributes').result(binding)
|
71
|
+
file.write(template)
|
102
72
|
end
|
103
73
|
|
104
74
|
File.open('Commands.rb', 'w') do |file|
|
105
|
-
|
106
|
-
|
107
|
-
require 'yaml'
|
108
|
-
|
109
|
-
class Commands
|
110
|
-
@commands = {}
|
111
|
-
|
112
|
-
def self.parse(bot)
|
113
|
-
begin
|
114
|
-
commands = YAML.load_file('config/commands.yml')
|
115
|
-
commands = commands.values.flatten.map(&:to_sym)
|
116
|
-
rescue => e
|
117
|
-
puts "ERROR: Couldn't read commands.yml"
|
118
|
-
exit!
|
119
|
-
end
|
120
|
-
|
121
|
-
commands.each { |command| @commands[command] = instance_eval(File.read("commands/\#{command.downcase.capitalize}.rb")) }
|
122
|
-
@commands.each { |command| command[1].activate(bot) }
|
123
|
-
end
|
124
|
-
|
125
|
-
class << self
|
126
|
-
attr_reader :commands
|
127
|
-
end
|
128
|
-
end
|
129
|
-
HEREDOC
|
130
|
-
)
|
75
|
+
template = Helpers::load_template('Commands').result(binding)
|
76
|
+
file.write(template)
|
131
77
|
end
|
132
78
|
|
133
79
|
File.open('Events.rb', 'w') do |file|
|
134
|
-
|
135
|
-
|
136
|
-
require 'yaml'
|
137
|
-
|
138
|
-
class Events
|
139
|
-
@events = {}
|
140
|
-
|
141
|
-
def self.parse(bot)
|
142
|
-
begin
|
143
|
-
events = YAML.load_file('config/events.yml')
|
144
|
-
events = events.values.flatten.map(&:to_sym)
|
145
|
-
rescue => e
|
146
|
-
puts "ERROR: Couldn't read events.yml"
|
147
|
-
exit!
|
148
|
-
end
|
149
|
-
|
150
|
-
events.each { |event| @events[event] = instance_eval(File.read("events/\#{event.downcase.capitalize}.rb")) }
|
151
|
-
@events.each { |event| event[1].activate(bot) }
|
152
|
-
end
|
153
|
-
|
154
|
-
class << self
|
155
|
-
attr_reader :events
|
156
|
-
end
|
157
|
-
end
|
158
|
-
HEREDOC
|
159
|
-
)
|
80
|
+
template = Helpers::load_template('Events').result(binding)
|
81
|
+
file.write(template)
|
160
82
|
end
|
161
83
|
|
162
84
|
File.open('bot.rb', 'w') do |file|
|
163
|
-
|
164
|
-
|
165
|
-
require 'discordrb'
|
166
|
-
|
167
|
-
require_relative 'Attributes.rb'
|
168
|
-
require_relative 'Commands.rb'
|
169
|
-
require_relative 'Events.rb'
|
170
|
-
|
171
|
-
$LOAD_PATH << Dir.pwd
|
172
|
-
|
173
|
-
Attributes.parse
|
174
|
-
bot = Discordrb::Commands::CommandBot.new(token: Attributes.token, prefix: Attributes.prefix)
|
175
|
-
Commands.parse(bot)
|
176
|
-
Events.parse(bot)
|
177
|
-
|
178
|
-
bot.run
|
179
|
-
HEREDOC
|
180
|
-
)
|
85
|
+
template = Helpers::load_template('BotRun').result(binding)
|
86
|
+
file.write(template)
|
181
87
|
end
|
182
88
|
rescue => e
|
183
89
|
say('Something went wrong while creating the project.')
|
@@ -213,21 +119,8 @@ module Ezdrb
|
|
213
119
|
end
|
214
120
|
|
215
121
|
File.open("commands/#{command_name.capitalize}.rb", 'w') do |file|
|
216
|
-
|
217
|
-
|
218
|
-
class #{command_name.capitalize}
|
219
|
-
|
220
|
-
def activate(bot)
|
221
|
-
bot.command :#{command_name} do |event|
|
222
|
-
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
end
|
227
|
-
|
228
|
-
#{command_name.capitalize}.new
|
229
|
-
HEREDOC
|
230
|
-
)
|
122
|
+
template = Helpers::load_template('SingleCommand').result(binding)
|
123
|
+
file.write(template)
|
231
124
|
end
|
232
125
|
rescue => e
|
233
126
|
say('Something went wrong while creating the command.')
|
@@ -239,7 +132,8 @@ module Ezdrb
|
|
239
132
|
def event(event)
|
240
133
|
event = event.strip.downcase
|
241
134
|
official_events = [:ready, :disconnected, :heartbeat, :typing, :message_edit, :message_delete, :reaction_add, :reaction_remove, :reaction_remove_all, :presence, :playing, :channel_create, :channel_update, :channel_delete, :channel_recipient_add, :channel_recipient_remove, :voice_state_update, :member_join, :member_update, :member_leave, :user_ban, :user_unban, :server_create, :mention, :server_update, :server_delete, :server_emoji, :server_emoji_create, :server_emoji_delete, :private_message, :direct_message, :server_emoji_update, :raw, :unknown, :pm, :dm, :message]
|
242
|
-
|
135
|
+
official_events.freeze
|
136
|
+
|
243
137
|
if official_events.include?(event.to_sym) then
|
244
138
|
begin
|
245
139
|
events = YAML.load_file('config/events.yml')
|
@@ -263,22 +157,9 @@ module Ezdrb
|
|
263
157
|
)
|
264
158
|
end
|
265
159
|
|
266
|
-
File.open("events/#{event.
|
267
|
-
|
268
|
-
|
269
|
-
class #{event.downcase.capitalize}
|
270
|
-
|
271
|
-
def activate(bot)
|
272
|
-
bot.#{event} do |event|
|
273
|
-
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
|
-
end
|
278
|
-
|
279
|
-
#{event.downcase.capitalize}.new
|
280
|
-
HEREDOC
|
281
|
-
)
|
160
|
+
File.open("events/#{event.capitalize}.rb", 'w') do |file|
|
161
|
+
template = Helpers::load_template('SingleEvent').result(binding)
|
162
|
+
file.write(template)
|
282
163
|
end
|
283
164
|
rescue => e
|
284
165
|
say('Something went wrong while creating the command.')
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
class Attributes
|
4
|
+
|
5
|
+
def self.parse
|
6
|
+
begin
|
7
|
+
config = YAML.load_file('config/bot.yml')
|
8
|
+
rescue => e
|
9
|
+
puts "ERROR: Couldn't read bot.yml"
|
10
|
+
exit!
|
11
|
+
end
|
12
|
+
|
13
|
+
@prefix = config['prefix']
|
14
|
+
@token = config['token']
|
15
|
+
|
16
|
+
if @prefix.nil? then
|
17
|
+
puts 'ERROR: You must set a prefix'
|
18
|
+
exit!
|
19
|
+
elsif @token.nil? then
|
20
|
+
puts 'ERROR: You must set a token'
|
21
|
+
exit!
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
class << self
|
27
|
+
attr_reader :prefix, :token
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'discordrb'
|
2
|
+
|
3
|
+
require_relative 'Attributes.rb'
|
4
|
+
require_relative 'Commands.rb'
|
5
|
+
require_relative 'Events.rb'
|
6
|
+
|
7
|
+
$LOAD_PATH << Dir.pwd
|
8
|
+
|
9
|
+
Attributes.parse
|
10
|
+
bot = Discordrb::Commands::CommandBot.new(token: Attributes.token, prefix: Attributes.prefix)
|
11
|
+
Commands.parse(bot)
|
12
|
+
Events.parse(bot)
|
13
|
+
|
14
|
+
bot.run
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
class Commands
|
4
|
+
@commands = {}
|
5
|
+
|
6
|
+
def self.parse(bot)
|
7
|
+
begin
|
8
|
+
commands = YAML.load_file('config/commands.yml')
|
9
|
+
commands = commands.values.flatten.map(&:to_sym)
|
10
|
+
rescue => e
|
11
|
+
puts "ERROR: Couldn't read commands.yml"
|
12
|
+
exit!
|
13
|
+
end
|
14
|
+
|
15
|
+
commands.each { |command| @commands[command] = instance_eval(File.read("commands/\#{command.downcase.capitalize}.rb")) }
|
16
|
+
@commands.each { |command| command[1].activate(bot) }
|
17
|
+
end
|
18
|
+
|
19
|
+
class << self
|
20
|
+
attr_reader :commands
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
class Events
|
4
|
+
@events = {}
|
5
|
+
|
6
|
+
def self.parse(bot)
|
7
|
+
begin
|
8
|
+
events = YAML.load_file('config/events.yml')
|
9
|
+
events = events.values.flatten.map(&:to_sym)
|
10
|
+
rescue => e
|
11
|
+
puts "ERROR: Couldn't read events.yml"
|
12
|
+
exit!
|
13
|
+
end
|
14
|
+
|
15
|
+
events.each { |event| @events[event] = instance_eval(File.read("events/\#{event.downcase.capitalize}.rb")) }
|
16
|
+
@events.each { |event| event[1].activate(bot) }
|
17
|
+
end
|
18
|
+
|
19
|
+
class << self
|
20
|
+
attr_reader :events
|
21
|
+
end
|
22
|
+
end
|
data/lib/ezdrb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ezdrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- monocrystal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -42,16 +42,30 @@ dependencies:
|
|
42
42
|
name: thor
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 0.20.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 0.20.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: discordrb
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.2.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.2.1
|
55
69
|
description: A tool that helps you write Discord bots faster (Discordrb-only)
|
56
70
|
email:
|
57
71
|
- askeeydev@gmail.com
|
@@ -74,6 +88,13 @@ files:
|
|
74
88
|
- ezdrb.gemspec
|
75
89
|
- lib/ezdrb.rb
|
76
90
|
- lib/ezdrb/cli.rb
|
91
|
+
- lib/ezdrb/templates/Attributes.erb
|
92
|
+
- lib/ezdrb/templates/BotRun.erb
|
93
|
+
- lib/ezdrb/templates/BotYml.erb
|
94
|
+
- lib/ezdrb/templates/Commands.erb
|
95
|
+
- lib/ezdrb/templates/Events.erb
|
96
|
+
- lib/ezdrb/templates/SingleCommand.erb
|
97
|
+
- lib/ezdrb/templates/SingleEvent.erb
|
77
98
|
- lib/ezdrb/version.rb
|
78
99
|
homepage: ''
|
79
100
|
licenses:
|