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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19b259e7f4a104fff4088f9e7a5b8fea58c5b83007f61b557ae66536339a4b9a
4
- data.tar.gz: 1247cd9412097a315e88c91a7aadf9a15b0136163c9c3050f9203a62a956643f
3
+ metadata.gz: 740fc8581a121fa1fde61ac5868509c8a162732465a839280b9f10e778d9e91c
4
+ data.tar.gz: d7a751fd9c4e9838211d955d1660e00c563c53045aa9d93868138fca66461df1
5
5
  SHA512:
6
- metadata.gz: ea49fb05b9cd35ec7d320c7e437116eb831b5132e54b8c76c81a6b697505e8ab3d6d5e6d2ef678fc499f717efc56a4ea5e9f88dc4cd67152d32743afd7399da0
7
- data.tar.gz: 9f11176b5bbad2d12c1041aaef3ccd5b0f4e959b56a82d0d14a05f911799f7a49f2d01a2afeddb660a152d0b4dcacea8baff54591fcacbe58268e2e8b1a61916
6
+ metadata.gz: b9f4df5fc5b258dfee5dd86c81e46b0f2036c120db6b38654a94413bc3d71639a64d177103480905c48f34669e7f740f921f81e646177fd695c9ca034db755a6
7
+ data.tar.gz: 99318ac82b6db5c90894494ea35fd1209d57a8e8e90ef25ea4716193a3d3115b6f95cea5014e2121dbdadf4a461c5357883ef079be1f17131b3b4c1a59ea3f96
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source "https://rubygems.org"
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ezdrb (0.1.0)
4
+ ezdrb (0.1.1)
5
5
  thor
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,38 +1,87 @@
1
1
  # Ezdrb
2
2
 
3
- 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/ezdrb`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Write Discord bots faster (Discordrb-only).
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ ## Install
6
6
 
7
- ## Installation
7
+ `$ gem install ezdrb`
8
8
 
9
- Add this line to your application's Gemfile:
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
- And then execute:
27
+ Set prefix: ++
28
+ Set token: 123456789
29
+ ```
16
30
 
17
- $ bundle
31
+ By running `ls` you should get this structure:
18
32
 
19
- Or install it yourself as:
33
+ ```
34
+ $ ls
35
+ Attributes.rb bot.rb commands/ Commands.rb config/
36
+ ```
20
37
 
21
- $ gem install ezdrb
38
+ **2\. Add commands to the bot:**
22
39
 
23
- ## Usage
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
- TODO: Write usage instructions here
72
+ **4\. Run the bot:**
26
73
 
27
- ## Development
74
+ Run `bot.rb`:
28
75
 
29
- 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.
76
+ `$ ruby bot.rb`
30
77
 
31
- 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
78
+ ## To do
32
79
 
33
- ## Contributing
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 "bundler/gem_tasks"
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 "bundler/setup"
4
- require "ezdrb"
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 "irb"
13
+ require 'irb'
14
14
  IRB.start(__FILE__)
data/bin/ezdrb CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "ezdrb/cli"
4
- Ezdrb::CLI.start
3
+ require 'ezdrb/cli'
4
+ Ezdrb::CLI.start
data/ezdrb.gemspec CHANGED
@@ -1,26 +1,25 @@
1
- # coding: utf-8
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 = "ezdrb"
6
+ spec.name = 'ezdrb'
8
7
  spec.version = Ezdrb::VERSION
9
8
  spec.platform = Gem::Platform::RUBY
10
- spec.authors = ["monocrystal"]
11
- spec.email = ["askeeydev@email.com"]
12
- spec.homepage = ""
13
- spec.summary = %q{A tool that helps you write Discord bots faster (Discordrb-only)}
14
- spec.description = %q{A tool that helps you write Discord bots faster (Discordrb-only)}
15
- spec.license = "MIT"
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 "bundler", "~> 1.3"
18
- spec.add_development_dependency "rake"
16
+ spec.add_development_dependency 'bundler', '~> 1.3'
17
+ spec.add_development_dependency 'rake'
19
18
 
20
- spec.add_runtime_dependency "thor"
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 = ["lib"]
26
- end
24
+ spec.require_paths = ['lib']
25
+ end
data/lib/ezdrb.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "ezdrb/version"
1
+ require 'ezdrb/version'
2
2
 
3
3
  module Ezdrb
4
4
  # Your code goes here...
data/lib/ezdrb/cli.rb CHANGED
@@ -1,14 +1,19 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "thor"
4
- require "yaml"
5
- require "ezdrb"
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 "init", "Initializes a Discord bot template."
25
+ desc 'init', 'Initializes a Discord bot template.'
21
26
  def init
22
- if File.file?("config/bot.yml") then
23
- say("You already have a Discord bot in here.")
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("Set prefix:")
28
- prefix = Helpers::validate(prefix, "Error: you must set a prefix:")
32
+ prefix = ask('Set prefix:')
33
+ prefix = Helpers::validate(prefix, 'Error: you must set a prefix:')
29
34
 
30
- token = ask("Set token:")
31
- token = Helpers::validate(token, "Error: you must set a 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("config")
35
- Dir.mkdir("commands")
39
+ Dir.mkdir('config')
40
+ Dir.mkdir('commands')
41
+ Dir.mkdir('events')
36
42
 
37
- File.open("config/bot.yml", "w") do |file|
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("config/commands.yml", "w") do |file|
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("Attributes.rb", "w") do |file|
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 "yaml"
71
+ require 'yaml'
58
72
 
59
73
  class Attributes
60
74
 
61
75
  def self.parse
62
76
  begin
63
- config = YAML.load_file("config/bot.yml")
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["prefix"]
70
- @token = config["token"]
83
+ @prefix = config['prefix']
84
+ @token = config['token']
71
85
 
72
86
  if @prefix.nil? then
73
- puts "ERROR: You must set a prefix"
87
+ puts 'ERROR: You must set a prefix'
74
88
  exit!
75
89
  elsif @token.nil? then
76
- puts "ERROR: You must set a token"
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("Commands.rb", "w") do |file|
104
+ File.open('Commands.rb', 'w') do |file|
91
105
  file.write(
92
106
  <<~HEREDOC
93
- require "yaml"
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("config/commands.yml")
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("bot.rb", "w") do |file|
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 "discordrb"
165
+ require 'discordrb'
123
166
 
124
- require_relative "Attributes.rb"
125
- require_relative "Commands.rb"
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("Something went wrong while creating the project.")
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 "command <command_name>", "Creates a new bot command"
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("config/commands.yml")
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("config/commands.yml", "a") do |file|
207
+ File.open('config/commands.yml', 'a') do |file|
163
208
  file.write(
164
209
  <<~HEREDOC
165
- - #{command_name}
210
+ - #{command_name}
166
211
  HEREDOC
167
212
  )
168
213
  end
169
214
 
170
- File.open("commands/#{command_name.capitalize}.rb", "w") do |file|
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("Something went wrong while creating the command.")
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
@@ -1,3 +1,3 @@
1
1
  module Ezdrb
2
- VERSION = "0.1.1"
2
+ VERSION = '0.1.2'.freeze
3
3
  end
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.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-28 00:00:00.000000000 Z
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@email.com
57
+ - askeeydev@gmail.com
58
58
  executables:
59
59
  - console
60
60
  - ezdrb