ezdrb 0.1.1 → 0.1.2
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/Gemfile +2 -2
- data/Gemfile.lock +1 -1
- data/README.md +66 -17
- data/Rakefile +1 -1
- data/bin/console +3 -3
- data/bin/ezdrb +2 -2
- data/ezdrb.gemspec +13 -14
- data/lib/ezdrb.rb +1 -1
- data/lib/ezdrb/cli.rb +138 -38
- data/lib/ezdrb/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 740fc8581a121fa1fde61ac5868509c8a162732465a839280b9f10e778d9e91c
|
4
|
+
data.tar.gz: d7a751fd9c4e9838211d955d1660e00c563c53045aa9d93868138fca66461df1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9f4df5fc5b258dfee5dd86c81e46b0f2036c120db6b38654a94413bc3d71639a64d177103480905c48f34669e7f740f921f81e646177fd695c9ca034db755a6
|
7
|
+
data.tar.gz: 99318ac82b6db5c90894494ea35fd1209d57a8e8e90ef25ea4716193a3d3115b6f95cea5014e2121dbdadf4a461c5357883ef079be1f17131b3b4c1a59ea3f96
|
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
3
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in ezdrb.gemspec
|
6
6
|
gemspec
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,38 +1,87 @@
|
|
1
1
|
# Ezdrb
|
2
2
|
|
3
|
-
|
3
|
+
Write Discord bots faster (Discordrb-only).
|
4
4
|
|
5
|
-
|
5
|
+
## Install
|
6
6
|
|
7
|
-
|
7
|
+
`$ gem install ezdrb`
|
8
8
|
|
9
|
-
|
9
|
+
## Usage
|
10
|
+
`$ ezdrb <command>`
|
11
|
+
|
12
|
+
## Commands available
|
13
|
+
|
14
|
+
* `help [command]`: Lists all commands available.
|
15
|
+
* `init`: Creates a new bot in the current directory (recommended: run this in an empty directory)
|
16
|
+
* `command <command>`: Creates a new bot command. You can find all bot commands in the *commands/* directory.
|
17
|
+
|
18
|
+
## Example
|
19
|
+
|
20
|
+
**1\. Create the bot:**
|
10
21
|
|
11
|
-
```ruby
|
12
|
-
gem 'ezdrb'
|
13
22
|
```
|
23
|
+
$ mkdir my-awesome-bot && cd "$_"
|
24
|
+
$ ezdrb init
|
25
|
+
Creating new EZDRB project...
|
14
26
|
|
15
|
-
|
27
|
+
Set prefix: ++
|
28
|
+
Set token: 123456789
|
29
|
+
```
|
16
30
|
|
17
|
-
|
31
|
+
By running `ls` you should get this structure:
|
18
32
|
|
19
|
-
|
33
|
+
```
|
34
|
+
$ ls
|
35
|
+
Attributes.rb bot.rb commands/ Commands.rb config/
|
36
|
+
```
|
20
37
|
|
21
|
-
|
38
|
+
**2\. Add commands to the bot:**
|
22
39
|
|
23
|
-
|
40
|
+
```
|
41
|
+
$ ezdrb command ping
|
42
|
+
```
|
43
|
+
|
44
|
+
All available commands are in `config/commands.yml`:
|
45
|
+
|
46
|
+
```
|
47
|
+
$ cat config/commands.yml
|
48
|
+
commands:
|
49
|
+
- ping
|
50
|
+
```
|
51
|
+
|
52
|
+
**3\. Edit commands:**
|
53
|
+
|
54
|
+
`$ vim commands/Ping.rb`. You should get something like this:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
class Ping
|
58
|
+
|
59
|
+
def activate(bot)
|
60
|
+
bot.command :ping do |event|
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
Ping.new
|
68
|
+
```
|
69
|
+
|
70
|
+
Write your command script inside the `bot.command` block.
|
24
71
|
|
25
|
-
|
72
|
+
**4\. Run the bot:**
|
26
73
|
|
27
|
-
|
74
|
+
Run `bot.rb`:
|
28
75
|
|
29
|
-
|
76
|
+
`$ ruby bot.rb`
|
30
77
|
|
31
|
-
|
78
|
+
## To do
|
32
79
|
|
33
|
-
|
80
|
+
- delete a bot command
|
81
|
+
- add events
|
82
|
+
- remove events
|
83
|
+
- run the bot from ezdrb
|
34
84
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ezdrb.
|
36
85
|
|
37
86
|
## License
|
38
87
|
|
data/Rakefile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
2
|
task :default => :spec
|
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'ezdrb'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "ezdrb"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start(__FILE__)
|
data/bin/ezdrb
CHANGED
data/ezdrb.gemspec
CHANGED
@@ -1,26 +1,25 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'ezdrb/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
6
|
+
spec.name = 'ezdrb'
|
8
7
|
spec.version = Ezdrb::VERSION
|
9
8
|
spec.platform = Gem::Platform::RUBY
|
10
|
-
spec.authors = [
|
11
|
-
spec.email = [
|
12
|
-
spec.homepage =
|
13
|
-
spec.summary =
|
14
|
-
spec.description =
|
15
|
-
spec.license =
|
9
|
+
spec.authors = ['monocrystal']
|
10
|
+
spec.email = ['askeeydev@gmail.com']
|
11
|
+
spec.homepage = ''
|
12
|
+
spec.summary = 'A tool that helps you write Discord bots faster (Discordrb-only)'
|
13
|
+
spec.description = 'A tool that helps you write Discord bots faster (Discordrb-only)'
|
14
|
+
spec.license = 'MIT'
|
16
15
|
|
17
|
-
spec.add_development_dependency
|
18
|
-
spec.add_development_dependency
|
16
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
17
|
+
spec.add_development_dependency 'rake'
|
19
18
|
|
20
|
-
spec.add_runtime_dependency
|
19
|
+
spec.add_runtime_dependency 'thor'
|
21
20
|
|
22
21
|
spec.files = `git ls-files`.split($/)
|
23
22
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
24
23
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
25
|
-
spec.require_paths = [
|
26
|
-
end
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
end
|
data/lib/ezdrb.rb
CHANGED
data/lib/ezdrb/cli.rb
CHANGED
@@ -1,14 +1,19 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
# ENV['DISCORDRB_NONACL'] = 'nope'
|
4
|
+
|
5
|
+
# module Discordrb
|
6
|
+
# end
|
7
|
+
|
8
|
+
require 'thor'
|
9
|
+
require 'yaml'
|
10
|
+
require 'ezdrb'
|
6
11
|
|
7
12
|
module Ezdrb
|
8
13
|
|
9
14
|
module Helpers
|
10
15
|
|
11
|
-
def self.validate(var, error_msg =
|
16
|
+
def self.validate(var, error_msg = '')
|
12
17
|
var = Thor::Shell::Basic.new.ask error_msg while var.empty? || var.nil?
|
13
18
|
var
|
14
19
|
end
|
@@ -17,24 +22,25 @@ module Ezdrb
|
|
17
22
|
|
18
23
|
class CLI < Thor
|
19
24
|
|
20
|
-
desc
|
25
|
+
desc 'init', 'Initializes a Discord bot template.'
|
21
26
|
def init
|
22
|
-
if File.file?(
|
23
|
-
say(
|
27
|
+
if File.file?('config/bot.yml') then
|
28
|
+
say('You already have a Discord bot in here.')
|
24
29
|
else
|
25
30
|
say("Creating new EZDRB project...\n\n")
|
26
31
|
|
27
|
-
prefix = ask(
|
28
|
-
prefix = Helpers::validate(prefix,
|
32
|
+
prefix = ask('Set prefix:')
|
33
|
+
prefix = Helpers::validate(prefix, 'Error: you must set a prefix:')
|
29
34
|
|
30
|
-
token = ask(
|
31
|
-
token = Helpers::validate(token,
|
35
|
+
token = ask('Set token:')
|
36
|
+
token = Helpers::validate(token, 'Error: you must set a token:')
|
32
37
|
|
33
38
|
begin
|
34
|
-
Dir.mkdir(
|
35
|
-
Dir.mkdir(
|
39
|
+
Dir.mkdir('config')
|
40
|
+
Dir.mkdir('commands')
|
41
|
+
Dir.mkdir('events')
|
36
42
|
|
37
|
-
File.open(
|
43
|
+
File.open('config/bot.yml', 'w') do |file|
|
38
44
|
file.write(
|
39
45
|
<<~HEREDOC
|
40
46
|
prefix: '#{prefix.strip}'
|
@@ -43,7 +49,7 @@ module Ezdrb
|
|
43
49
|
)
|
44
50
|
end
|
45
51
|
|
46
|
-
File.open(
|
52
|
+
File.open('config/commands.yml', 'w') do |file|
|
47
53
|
file.write(
|
48
54
|
<<~HEREDOC
|
49
55
|
commands:
|
@@ -51,29 +57,37 @@ module Ezdrb
|
|
51
57
|
)
|
52
58
|
end
|
53
59
|
|
54
|
-
File.open(
|
60
|
+
File.open('config/events.yml', 'w') do |file|
|
61
|
+
file.write(
|
62
|
+
<<~HEREDOC
|
63
|
+
events:
|
64
|
+
HEREDOC
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
68
|
+
File.open('Attributes.rb', 'w') do |file|
|
55
69
|
file.write(
|
56
70
|
<<~HEREDOC
|
57
|
-
require
|
71
|
+
require 'yaml'
|
58
72
|
|
59
73
|
class Attributes
|
60
74
|
|
61
75
|
def self.parse
|
62
76
|
begin
|
63
|
-
config = YAML.load_file(
|
77
|
+
config = YAML.load_file('config/bot.yml')
|
64
78
|
rescue => e
|
65
79
|
puts "ERROR: Couldn't read bot.yml"
|
66
80
|
exit!
|
67
81
|
end
|
68
82
|
|
69
|
-
@prefix = config[
|
70
|
-
@token = config[
|
83
|
+
@prefix = config['prefix']
|
84
|
+
@token = config['token']
|
71
85
|
|
72
86
|
if @prefix.nil? then
|
73
|
-
puts
|
87
|
+
puts 'ERROR: You must set a prefix'
|
74
88
|
exit!
|
75
89
|
elsif @token.nil? then
|
76
|
-
puts
|
90
|
+
puts 'ERROR: You must set a token'
|
77
91
|
exit!
|
78
92
|
end
|
79
93
|
|
@@ -87,25 +101,25 @@ module Ezdrb
|
|
87
101
|
)
|
88
102
|
end
|
89
103
|
|
90
|
-
File.open(
|
104
|
+
File.open('Commands.rb', 'w') do |file|
|
91
105
|
file.write(
|
92
106
|
<<~HEREDOC
|
93
|
-
require
|
107
|
+
require 'yaml'
|
94
108
|
|
95
109
|
class Commands
|
96
110
|
@commands = {}
|
97
111
|
|
98
112
|
def self.parse(bot)
|
99
113
|
begin
|
100
|
-
commands = YAML.load_file(
|
114
|
+
commands = YAML.load_file('config/commands.yml')
|
101
115
|
commands = commands.values.flatten.map(&:to_sym)
|
102
116
|
rescue => e
|
103
117
|
puts "ERROR: Couldn't read commands.yml"
|
104
118
|
exit!
|
105
119
|
end
|
106
120
|
|
107
|
-
commands.each {|command| @commands[command] = instance_eval(File.read("commands/\#{command}.rb"))}
|
108
|
-
@commands.each {|command| command[1].activate(bot)}
|
121
|
+
commands.each { |command| @commands[command] = instance_eval(File.read("commands/\#{command.downcase.capitalize}.rb")) }
|
122
|
+
@commands.each { |command| command[1].activate(bot) }
|
109
123
|
end
|
110
124
|
|
111
125
|
class << self
|
@@ -116,37 +130,68 @@ module Ezdrb
|
|
116
130
|
)
|
117
131
|
end
|
118
132
|
|
119
|
-
File.open(
|
133
|
+
File.open('Events.rb', 'w') do |file|
|
134
|
+
file.write(
|
135
|
+
<<~HEREDOC
|
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
|
+
)
|
160
|
+
end
|
161
|
+
|
162
|
+
File.open('bot.rb', 'w') do |file|
|
120
163
|
file.write(
|
121
164
|
<<~HEREDOC
|
122
|
-
require
|
165
|
+
require 'discordrb'
|
123
166
|
|
124
|
-
require_relative
|
125
|
-
require_relative
|
167
|
+
require_relative 'Attributes.rb'
|
168
|
+
require_relative 'Commands.rb'
|
169
|
+
require_relative 'Events.rb'
|
126
170
|
|
127
171
|
$LOAD_PATH << Dir.pwd
|
128
172
|
|
129
173
|
Attributes.parse
|
130
174
|
bot = Discordrb::Commands::CommandBot.new(token: Attributes.token, prefix: Attributes.prefix)
|
131
175
|
Commands.parse(bot)
|
176
|
+
Events.parse(bot)
|
132
177
|
|
133
178
|
bot.run
|
134
179
|
HEREDOC
|
135
180
|
)
|
136
181
|
end
|
137
182
|
rescue => e
|
138
|
-
say(
|
183
|
+
say('Something went wrong while creating the project.')
|
139
184
|
say(" => #{e.message}")
|
140
185
|
end
|
141
186
|
end
|
142
187
|
end
|
143
188
|
|
144
|
-
desc
|
189
|
+
desc 'command <command_name>', 'Creates a new bot command'
|
145
190
|
def command(command_name)
|
146
191
|
command_name = command_name.strip.downcase
|
147
192
|
|
148
193
|
begin
|
149
|
-
commands = YAML.load_file(
|
194
|
+
commands = YAML.load_file('config/commands.yml')
|
150
195
|
commands = commands.values.flatten
|
151
196
|
rescue => e
|
152
197
|
say("ERROR: Couldn't read commands.yml")
|
@@ -159,15 +204,15 @@ module Ezdrb
|
|
159
204
|
end
|
160
205
|
|
161
206
|
begin
|
162
|
-
File.open(
|
207
|
+
File.open('config/commands.yml', 'a') do |file|
|
163
208
|
file.write(
|
164
209
|
<<~HEREDOC
|
165
|
-
|
210
|
+
- #{command_name}
|
166
211
|
HEREDOC
|
167
212
|
)
|
168
213
|
end
|
169
214
|
|
170
|
-
File.open("commands/#{command_name.capitalize}.rb",
|
215
|
+
File.open("commands/#{command_name.capitalize}.rb", 'w') do |file|
|
171
216
|
file.write(
|
172
217
|
<<~HEREDOC
|
173
218
|
class #{command_name.capitalize}
|
@@ -185,10 +230,65 @@ module Ezdrb
|
|
185
230
|
)
|
186
231
|
end
|
187
232
|
rescue => e
|
188
|
-
say(
|
233
|
+
say('Something went wrong while creating the command.')
|
189
234
|
say(" => #{e.message}")
|
190
235
|
end
|
191
236
|
end
|
192
237
|
|
238
|
+
desc 'event <event>', 'Creates a new event handler'
|
239
|
+
def event(event)
|
240
|
+
event = event.strip.downcase
|
241
|
+
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
|
+
|
243
|
+
if official_events.include?(event.to_sym) then
|
244
|
+
begin
|
245
|
+
events = YAML.load_file('config/events.yml')
|
246
|
+
events = events.values.flatten
|
247
|
+
rescue => e
|
248
|
+
say("ERROR: Couldn't read events.yml")
|
249
|
+
exit!
|
250
|
+
end
|
251
|
+
|
252
|
+
if events.include?(event) then
|
253
|
+
say("ERROR: #{event} already exists")
|
254
|
+
exit!
|
255
|
+
end
|
256
|
+
|
257
|
+
begin
|
258
|
+
File.open('config/events.yml', 'a') do |file|
|
259
|
+
file.write(
|
260
|
+
<<~HEREDOC
|
261
|
+
- #{event.downcase.capitalize}
|
262
|
+
HEREDOC
|
263
|
+
)
|
264
|
+
end
|
265
|
+
|
266
|
+
File.open("events/#{event.downcase.capitalize}.rb", 'w') do |file|
|
267
|
+
file.write(
|
268
|
+
<<~HEREDOC
|
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
|
+
)
|
282
|
+
end
|
283
|
+
rescue => e
|
284
|
+
say('Something went wrong while creating the command.')
|
285
|
+
say(" => #{e.message}")
|
286
|
+
end
|
287
|
+
|
288
|
+
else
|
289
|
+
say('This event does not exist.')
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
193
293
|
end
|
194
294
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- monocrystal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
description: A tool that helps you write Discord bots faster (Discordrb-only)
|
56
56
|
email:
|
57
|
-
- askeeydev@
|
57
|
+
- askeeydev@gmail.com
|
58
58
|
executables:
|
59
59
|
- console
|
60
60
|
- ezdrb
|