ezdrb 0.1.0 → 0.1.1
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.lock +22 -0
- data/bin/ezdrb +4 -0
- data/ezdrb.gemspec +2 -3
- data/lib/ezdrb/cli.rb +194 -0
- data/lib/ezdrb/version.rb +1 -1
- data/lib/ezdrb.rb +0 -1
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19b259e7f4a104fff4088f9e7a5b8fea58c5b83007f61b557ae66536339a4b9a
|
4
|
+
data.tar.gz: 1247cd9412097a315e88c91a7aadf9a15b0136163c9c3050f9203a62a956643f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea49fb05b9cd35ec7d320c7e437116eb831b5132e54b8c76c81a6b697505e8ab3d6d5e6d2ef678fc499f717efc56a4ea5e9f88dc4cd67152d32743afd7399da0
|
7
|
+
data.tar.gz: 9f11176b5bbad2d12c1041aaef3ccd5b0f4e959b56a82d0d14a05f911799f7a49f2d01a2afeddb660a152d0b4dcacea8baff54591fcacbe58268e2e8b1a61916
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ezdrb (0.1.0)
|
5
|
+
thor
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
rake (12.3.1)
|
11
|
+
thor (0.20.0)
|
12
|
+
|
13
|
+
PLATFORMS
|
14
|
+
ruby
|
15
|
+
|
16
|
+
DEPENDENCIES
|
17
|
+
bundler (~> 1.3)
|
18
|
+
ezdrb!
|
19
|
+
rake
|
20
|
+
|
21
|
+
BUNDLED WITH
|
22
|
+
1.16.2
|
data/bin/ezdrb
ADDED
data/ezdrb.gemspec
CHANGED
@@ -17,11 +17,10 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.add_development_dependency "bundler", "~> 1.3"
|
18
18
|
spec.add_development_dependency "rake"
|
19
19
|
|
20
|
+
spec.add_runtime_dependency "thor"
|
21
|
+
|
20
22
|
spec.files = `git ls-files`.split($/)
|
21
23
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
24
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
25
|
spec.require_paths = ["lib"]
|
24
|
-
|
25
|
-
#spec.add_development_dependency "yaml"
|
26
|
-
spec.add_runtime_dependency "thor"
|
27
26
|
end
|
data/lib/ezdrb/cli.rb
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "thor"
|
4
|
+
require "yaml"
|
5
|
+
require "ezdrb"
|
6
|
+
|
7
|
+
module Ezdrb
|
8
|
+
|
9
|
+
module Helpers
|
10
|
+
|
11
|
+
def self.validate(var, error_msg = "")
|
12
|
+
var = Thor::Shell::Basic.new.ask error_msg while var.empty? || var.nil?
|
13
|
+
var
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
class CLI < Thor
|
19
|
+
|
20
|
+
desc "init", "Initializes a Discord bot template."
|
21
|
+
def init
|
22
|
+
if File.file?("config/bot.yml") then
|
23
|
+
say("You already have a Discord bot in here.")
|
24
|
+
else
|
25
|
+
say("Creating new EZDRB project...\n\n")
|
26
|
+
|
27
|
+
prefix = ask("Set prefix:")
|
28
|
+
prefix = Helpers::validate(prefix, "Error: you must set a prefix:")
|
29
|
+
|
30
|
+
token = ask("Set token:")
|
31
|
+
token = Helpers::validate(token, "Error: you must set a token:")
|
32
|
+
|
33
|
+
begin
|
34
|
+
Dir.mkdir("config")
|
35
|
+
Dir.mkdir("commands")
|
36
|
+
|
37
|
+
File.open("config/bot.yml", "w") do |file|
|
38
|
+
file.write(
|
39
|
+
<<~HEREDOC
|
40
|
+
prefix: '#{prefix.strip}'
|
41
|
+
token: '#{token.strip}'
|
42
|
+
HEREDOC
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
File.open("config/commands.yml", "w") do |file|
|
47
|
+
file.write(
|
48
|
+
<<~HEREDOC
|
49
|
+
commands:
|
50
|
+
HEREDOC
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
File.open("Attributes.rb", "w") do |file|
|
55
|
+
file.write(
|
56
|
+
<<~HEREDOC
|
57
|
+
require "yaml"
|
58
|
+
|
59
|
+
class Attributes
|
60
|
+
|
61
|
+
def self.parse
|
62
|
+
begin
|
63
|
+
config = YAML.load_file("config/bot.yml")
|
64
|
+
rescue => e
|
65
|
+
puts "ERROR: Couldn't read bot.yml"
|
66
|
+
exit!
|
67
|
+
end
|
68
|
+
|
69
|
+
@prefix = config["prefix"]
|
70
|
+
@token = config["token"]
|
71
|
+
|
72
|
+
if @prefix.nil? then
|
73
|
+
puts "ERROR: You must set a prefix"
|
74
|
+
exit!
|
75
|
+
elsif @token.nil? then
|
76
|
+
puts "ERROR: You must set a token"
|
77
|
+
exit!
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
class << self
|
83
|
+
attr_reader :prefix, :token
|
84
|
+
end
|
85
|
+
end
|
86
|
+
HEREDOC
|
87
|
+
)
|
88
|
+
end
|
89
|
+
|
90
|
+
File.open("Commands.rb", "w") do |file|
|
91
|
+
file.write(
|
92
|
+
<<~HEREDOC
|
93
|
+
require "yaml"
|
94
|
+
|
95
|
+
class Commands
|
96
|
+
@commands = {}
|
97
|
+
|
98
|
+
def self.parse(bot)
|
99
|
+
begin
|
100
|
+
commands = YAML.load_file("config/commands.yml")
|
101
|
+
commands = commands.values.flatten.map(&:to_sym)
|
102
|
+
rescue => e
|
103
|
+
puts "ERROR: Couldn't read commands.yml"
|
104
|
+
exit!
|
105
|
+
end
|
106
|
+
|
107
|
+
commands.each {|command| @commands[command] = instance_eval(File.read("commands/\#{command}.rb"))}
|
108
|
+
@commands.each {|command| command[1].activate(bot)}
|
109
|
+
end
|
110
|
+
|
111
|
+
class << self
|
112
|
+
attr_reader :commands
|
113
|
+
end
|
114
|
+
end
|
115
|
+
HEREDOC
|
116
|
+
)
|
117
|
+
end
|
118
|
+
|
119
|
+
File.open("bot.rb", "w") do |file|
|
120
|
+
file.write(
|
121
|
+
<<~HEREDOC
|
122
|
+
require "discordrb"
|
123
|
+
|
124
|
+
require_relative "Attributes.rb"
|
125
|
+
require_relative "Commands.rb"
|
126
|
+
|
127
|
+
$LOAD_PATH << Dir.pwd
|
128
|
+
|
129
|
+
Attributes.parse
|
130
|
+
bot = Discordrb::Commands::CommandBot.new(token: Attributes.token, prefix: Attributes.prefix)
|
131
|
+
Commands.parse(bot)
|
132
|
+
|
133
|
+
bot.run
|
134
|
+
HEREDOC
|
135
|
+
)
|
136
|
+
end
|
137
|
+
rescue => e
|
138
|
+
say("Something went wrong while creating the project.")
|
139
|
+
say(" => #{e.message}")
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
desc "command <command_name>", "Creates a new bot command"
|
145
|
+
def command(command_name)
|
146
|
+
command_name = command_name.strip.downcase
|
147
|
+
|
148
|
+
begin
|
149
|
+
commands = YAML.load_file("config/commands.yml")
|
150
|
+
commands = commands.values.flatten
|
151
|
+
rescue => e
|
152
|
+
say("ERROR: Couldn't read commands.yml")
|
153
|
+
exit!
|
154
|
+
end
|
155
|
+
|
156
|
+
if commands.include?(command_name) then
|
157
|
+
say("ERROR: #{command_name} already exists")
|
158
|
+
exit!
|
159
|
+
end
|
160
|
+
|
161
|
+
begin
|
162
|
+
File.open("config/commands.yml", "a") do |file|
|
163
|
+
file.write(
|
164
|
+
<<~HEREDOC
|
165
|
+
- #{command_name}
|
166
|
+
HEREDOC
|
167
|
+
)
|
168
|
+
end
|
169
|
+
|
170
|
+
File.open("commands/#{command_name.capitalize}.rb", "w") do |file|
|
171
|
+
file.write(
|
172
|
+
<<~HEREDOC
|
173
|
+
class #{command_name.capitalize}
|
174
|
+
|
175
|
+
def activate(bot)
|
176
|
+
bot.command :#{command_name} do |event|
|
177
|
+
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
#{command_name.capitalize}.new
|
184
|
+
HEREDOC
|
185
|
+
)
|
186
|
+
end
|
187
|
+
rescue => e
|
188
|
+
say("Something went wrong while creating the command.")
|
189
|
+
say(" => #{e.message}")
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
194
|
+
end
|
data/lib/ezdrb/version.rb
CHANGED
data/lib/ezdrb.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- monocrystal
|
@@ -57,19 +57,23 @@ email:
|
|
57
57
|
- askeeydev@email.com
|
58
58
|
executables:
|
59
59
|
- console
|
60
|
+
- ezdrb
|
60
61
|
- setup
|
61
62
|
extensions: []
|
62
63
|
extra_rdoc_files: []
|
63
64
|
files:
|
64
65
|
- ".gitignore"
|
65
66
|
- Gemfile
|
67
|
+
- Gemfile.lock
|
66
68
|
- LICENSE.txt
|
67
69
|
- README.md
|
68
70
|
- Rakefile
|
69
71
|
- bin/console
|
72
|
+
- bin/ezdrb
|
70
73
|
- bin/setup
|
71
74
|
- ezdrb.gemspec
|
72
75
|
- lib/ezdrb.rb
|
76
|
+
- lib/ezdrb/cli.rb
|
73
77
|
- lib/ezdrb/version.rb
|
74
78
|
homepage: ''
|
75
79
|
licenses:
|