discorb 0.19.0 → 0.20.0
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/.github/workflows/build_version.yml +2 -2
- data/.rubocop.yml +12 -75
- data/Changelog.md +10 -0
- data/Rakefile +482 -454
- data/lib/discorb/allowed_mentions.rb +68 -72
- data/lib/discorb/app_command/command.rb +466 -398
- data/lib/discorb/app_command/common.rb +65 -25
- data/lib/discorb/app_command/handler.rb +304 -266
- data/lib/discorb/app_command.rb +5 -5
- data/lib/discorb/application.rb +198 -197
- data/lib/discorb/asset.rb +101 -101
- data/lib/discorb/attachment.rb +134 -119
- data/lib/discorb/audit_logs.rb +412 -385
- data/lib/discorb/automod.rb +279 -269
- data/lib/discorb/channel/base.rb +107 -108
- data/lib/discorb/channel/category.rb +32 -32
- data/lib/discorb/channel/container.rb +44 -44
- data/lib/discorb/channel/dm.rb +26 -28
- data/lib/discorb/channel/guild.rb +311 -246
- data/lib/discorb/channel/stage.rb +156 -140
- data/lib/discorb/channel/text.rb +430 -336
- data/lib/discorb/channel/thread.rb +374 -325
- data/lib/discorb/channel/voice.rb +85 -79
- data/lib/discorb/channel.rb +5 -5
- data/lib/discorb/client.rb +635 -621
- data/lib/discorb/color.rb +178 -182
- data/lib/discorb/common.rb +168 -164
- data/lib/discorb/components/button.rb +107 -106
- data/lib/discorb/components/select_menu.rb +157 -145
- data/lib/discorb/components/text_input.rb +103 -106
- data/lib/discorb/components.rb +68 -66
- data/lib/discorb/dictionary.rb +135 -135
- data/lib/discorb/embed.rb +404 -398
- data/lib/discorb/emoji.rb +309 -302
- data/lib/discorb/emoji_table.rb +16099 -8857
- data/lib/discorb/error.rb +131 -131
- data/lib/discorb/event.rb +360 -314
- data/lib/discorb/event_handler.rb +39 -39
- data/lib/discorb/exe/about.rb +17 -17
- data/lib/discorb/exe/irb.rb +72 -67
- data/lib/discorb/exe/new.rb +323 -315
- data/lib/discorb/exe/run.rb +69 -68
- data/lib/discorb/exe/setup.rb +57 -55
- data/lib/discorb/exe/show.rb +12 -12
- data/lib/discorb/extend.rb +25 -45
- data/lib/discorb/extension.rb +89 -83
- data/lib/discorb/flag.rb +126 -128
- data/lib/discorb/gateway.rb +984 -804
- data/lib/discorb/gateway_events.rb +670 -638
- data/lib/discorb/gateway_requests.rb +45 -48
- data/lib/discorb/guild.rb +2115 -1626
- data/lib/discorb/guild_template.rb +280 -241
- data/lib/discorb/http.rb +247 -232
- data/lib/discorb/image.rb +42 -42
- data/lib/discorb/integration.rb +169 -161
- data/lib/discorb/intents.rb +161 -163
- data/lib/discorb/interaction/autocomplete.rb +76 -62
- data/lib/discorb/interaction/command.rb +279 -224
- data/lib/discorb/interaction/components.rb +114 -104
- data/lib/discorb/interaction/modal.rb +36 -32
- data/lib/discorb/interaction/response.rb +379 -336
- data/lib/discorb/interaction/root.rb +271 -257
- data/lib/discorb/interaction.rb +5 -5
- data/lib/discorb/invite.rb +154 -153
- data/lib/discorb/member.rb +344 -311
- data/lib/discorb/message.rb +615 -544
- data/lib/discorb/message_meta.rb +197 -186
- data/lib/discorb/modules.rb +371 -290
- data/lib/discorb/permission.rb +305 -291
- data/lib/discorb/presence.rb +352 -346
- data/lib/discorb/rate_limit.rb +81 -76
- data/lib/discorb/reaction.rb +55 -54
- data/lib/discorb/role.rb +272 -240
- data/lib/discorb/shard.rb +76 -74
- data/lib/discorb/sticker.rb +193 -171
- data/lib/discorb/user.rb +205 -188
- data/lib/discorb/utils/colored_puts.rb +16 -16
- data/lib/discorb/utils.rb +12 -16
- data/lib/discorb/voice_state.rb +305 -281
- data/lib/discorb/webhook.rb +537 -507
- data/lib/discorb.rb +62 -56
- data/sig/discorb/application.rbs +2 -0
- data/sig/discorb/automod.rbs +10 -1
- data/sig/discorb/guild.rbs +2 -0
- data/sig/discorb/message.rbs +2 -0
- data/sig/discorb/user.rbs +22 -20
- metadata +2 -2
data/lib/discorb/exe/new.rb
CHANGED
@@ -1,315 +1,323 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# description: Make files for the discorb project.
|
4
|
-
|
5
|
-
require "optparse"
|
6
|
-
require "discorb"
|
7
|
-
require "pathname"
|
8
|
-
require_relative "../utils/colored_puts"
|
9
|
-
|
10
|
-
$path = Dir.pwd
|
11
|
-
|
12
|
-
# @private
|
13
|
-
FILES = {
|
14
|
-
"main.rb" => <<~'RUBY',
|
15
|
-
# frozen_string_literal: true
|
16
|
-
|
17
|
-
require "discorb"
|
18
|
-
require "dotenv/load" # Load environment variables from .env file.
|
19
|
-
|
20
|
-
client = Discorb::Client.new # Create client for connecting to Discord
|
21
|
-
|
22
|
-
client.once :standby do
|
23
|
-
puts "Logged in as #{client.user}" # Prints username of logged in user
|
24
|
-
end
|
25
|
-
|
26
|
-
client.run ENV["%<token>s"] # Starts client
|
27
|
-
RUBY
|
28
|
-
"main.rb_nc" => <<~'RUBY',
|
29
|
-
# frozen_string_literal: true
|
30
|
-
|
31
|
-
require "discorb"
|
32
|
-
require "dotenv/load"
|
33
|
-
|
34
|
-
client = Discorb::Client.new
|
35
|
-
|
36
|
-
client.once :standby do
|
37
|
-
puts "Logged in as #{client.user}"
|
38
|
-
end
|
39
|
-
|
40
|
-
client.run ENV["%<token>s"]
|
41
|
-
RUBY
|
42
|
-
".env" => <<~BASH,
|
43
|
-
# Put your token after `%<token>s=`
|
44
|
-
%<token>s=
|
45
|
-
BASH
|
46
|
-
".env_nc" => <<~BASH,
|
47
|
-
%<token>s=
|
48
|
-
BASH
|
49
|
-
".gitignore" => <<~GITIGNORE,
|
50
|
-
*.gem
|
51
|
-
*.rbc
|
52
|
-
/.config
|
53
|
-
/coverage/
|
54
|
-
/InstalledFiles
|
55
|
-
/pkg/
|
56
|
-
/spec/reports/
|
57
|
-
/spec/examples.txt
|
58
|
-
/test/tmp/
|
59
|
-
/test/version_tmp/
|
60
|
-
/tmp/
|
61
|
-
|
62
|
-
# Used by dotenv library to load environment variables.
|
63
|
-
.env
|
64
|
-
|
65
|
-
# Ignore Byebug command history file.
|
66
|
-
.byebug_history
|
67
|
-
|
68
|
-
## Specific to RubyMotion:
|
69
|
-
.dat*
|
70
|
-
.repl_history
|
71
|
-
build/
|
72
|
-
*.bridgesupport
|
73
|
-
build-iPhoneOS/
|
74
|
-
build-iPhoneSimulator/
|
75
|
-
|
76
|
-
## Specific to RubyMotion (use of CocoaPods):
|
77
|
-
#
|
78
|
-
# We recommend against adding the Pods directory to your .gitignore. However
|
79
|
-
# you should judge for yourself, the pros and cons are mentioned at:
|
80
|
-
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
81
|
-
#
|
82
|
-
# vendor/Pods/
|
83
|
-
|
84
|
-
## Documentation cache and generated files:
|
85
|
-
/.yardoc/
|
86
|
-
/_yardoc/
|
87
|
-
/doc/
|
88
|
-
/rdoc/
|
89
|
-
|
90
|
-
## Environment normalization:
|
91
|
-
/.bundle/
|
92
|
-
/vendor/bundle
|
93
|
-
/lib/bundler/man/
|
94
|
-
|
95
|
-
# for a library or gem, you might want to ignore these files since the code is
|
96
|
-
# intended to run in multiple environments; otherwise, check them in:
|
97
|
-
# Gemfile.lock
|
98
|
-
# .ruby-version
|
99
|
-
# .ruby-gemset
|
100
|
-
|
101
|
-
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
102
|
-
.rvmrc
|
103
|
-
|
104
|
-
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
105
|
-
# .rubocop-https?--*
|
106
|
-
|
107
|
-
# This gitignore is from github/gitignore.
|
108
|
-
# https://github.com/github/gitignore/blob/master/Ruby.gitignore
|
109
|
-
GITIGNORE
|
110
|
-
".gitignore_nc" => <<~GITIGNORE,
|
111
|
-
*.gem
|
112
|
-
*.rbc
|
113
|
-
/.config
|
114
|
-
/coverage/
|
115
|
-
/InstalledFiles
|
116
|
-
/pkg/
|
117
|
-
/spec/reports/
|
118
|
-
/spec/examples.txt
|
119
|
-
/test/tmp/
|
120
|
-
/test/version_tmp/
|
121
|
-
/tmp/
|
122
|
-
|
123
|
-
.env
|
124
|
-
|
125
|
-
.byebug_history
|
126
|
-
|
127
|
-
.dat*
|
128
|
-
.repl_history
|
129
|
-
build/
|
130
|
-
*.bridgesupport
|
131
|
-
build-iPhoneOS/
|
132
|
-
build-iPhoneSimulator/
|
133
|
-
|
134
|
-
/.yardoc/
|
135
|
-
/_yardoc/
|
136
|
-
/doc/
|
137
|
-
/rdoc/
|
138
|
-
|
139
|
-
/.bundle/
|
140
|
-
/vendor/bundle
|
141
|
-
/lib/bundler/man/
|
142
|
-
|
143
|
-
.rvmrc
|
144
|
-
GITIGNORE
|
145
|
-
"Gemfile" => <<~RUBY,
|
146
|
-
# frozen_string_literal: true
|
147
|
-
|
148
|
-
source "https://rubygems.org"
|
149
|
-
|
150
|
-
git_source(:github) { |repo_name| "https://github.com/\#{repo_name}" }
|
151
|
-
|
152
|
-
gem "discorb", "~> #{Discorb::VERSION}"
|
153
|
-
gem "dotenv", "~> 2.7"
|
154
|
-
|
155
|
-
ruby "~> #{RUBY_VERSION.split(".")[0]}.#{RUBY_VERSION.split(".")[1]}"
|
156
|
-
RUBY
|
157
|
-
".env.sample" => <<~BASH,
|
158
|
-
%<token>s=
|
159
|
-
BASH
|
160
|
-
"README.md" => <<~MARKDOWN
|
161
|
-
# %<name>s
|
162
|
-
|
163
|
-
Welcome to your bot: %<name>s!
|
164
|
-
|
165
|
-
TODO: Write your bot's description here.
|
166
|
-
|
167
|
-
## Usage
|
168
|
-
|
169
|
-
TODO: Write your bot's usage here.
|
170
|
-
|
171
|
-
## Features
|
172
|
-
|
173
|
-
TODO: Write your bot's features here.
|
174
|
-
|
175
|
-
## How to host
|
176
|
-
|
177
|
-
1. Clone the repository.
|
178
|
-
2. Run `bundle install`.
|
179
|
-
3. Get your bot's token from the Discord developer portal.
|
180
|
-
4. Copy `.env.sample` to `.env` and fill in the token.
|
181
|
-
5. Run `bundle exec discorb run`.
|
182
|
-
|
183
|
-
TODO: Write your own customizations here.
|
184
|
-
|
185
|
-
## License
|
186
|
-
|
187
|
-
TODO: Write your bot's license here.
|
188
|
-
See https://choosealicense.com/ for more information.
|
189
|
-
|
190
|
-
MARKDOWN
|
191
|
-
}.freeze
|
192
|
-
|
193
|
-
# @private
|
194
|
-
def create_file(name)
|
195
|
-
template_name = name
|
196
|
-
template_name += "_nc" if !$values[:comment] && FILES.key?(name
|
197
|
-
content =
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
create_file(".
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
create_file("
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
opt.on(
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# description: Make files for the discorb project.
|
4
|
+
|
5
|
+
require "optparse"
|
6
|
+
require "discorb"
|
7
|
+
require "pathname"
|
8
|
+
require_relative "../utils/colored_puts"
|
9
|
+
|
10
|
+
$path = Dir.pwd
|
11
|
+
|
12
|
+
# @private
|
13
|
+
FILES = {
|
14
|
+
"main.rb" => <<~'RUBY',
|
15
|
+
# frozen_string_literal: true
|
16
|
+
|
17
|
+
require "discorb"
|
18
|
+
require "dotenv/load" # Load environment variables from .env file.
|
19
|
+
|
20
|
+
client = Discorb::Client.new # Create client for connecting to Discord
|
21
|
+
|
22
|
+
client.once :standby do
|
23
|
+
puts "Logged in as #{client.user}" # Prints username of logged in user
|
24
|
+
end
|
25
|
+
|
26
|
+
client.run ENV["%<token>s"] # Starts client
|
27
|
+
RUBY
|
28
|
+
"main.rb_nc" => <<~'RUBY',
|
29
|
+
# frozen_string_literal: true
|
30
|
+
|
31
|
+
require "discorb"
|
32
|
+
require "dotenv/load"
|
33
|
+
|
34
|
+
client = Discorb::Client.new
|
35
|
+
|
36
|
+
client.once :standby do
|
37
|
+
puts "Logged in as #{client.user}"
|
38
|
+
end
|
39
|
+
|
40
|
+
client.run ENV["%<token>s"]
|
41
|
+
RUBY
|
42
|
+
".env" => <<~BASH,
|
43
|
+
# Put your token after `%<token>s=`
|
44
|
+
%<token>s=
|
45
|
+
BASH
|
46
|
+
".env_nc" => <<~BASH,
|
47
|
+
%<token>s=
|
48
|
+
BASH
|
49
|
+
".gitignore" => <<~GITIGNORE,
|
50
|
+
*.gem
|
51
|
+
*.rbc
|
52
|
+
/.config
|
53
|
+
/coverage/
|
54
|
+
/InstalledFiles
|
55
|
+
/pkg/
|
56
|
+
/spec/reports/
|
57
|
+
/spec/examples.txt
|
58
|
+
/test/tmp/
|
59
|
+
/test/version_tmp/
|
60
|
+
/tmp/
|
61
|
+
|
62
|
+
# Used by dotenv library to load environment variables.
|
63
|
+
.env
|
64
|
+
|
65
|
+
# Ignore Byebug command history file.
|
66
|
+
.byebug_history
|
67
|
+
|
68
|
+
## Specific to RubyMotion:
|
69
|
+
.dat*
|
70
|
+
.repl_history
|
71
|
+
build/
|
72
|
+
*.bridgesupport
|
73
|
+
build-iPhoneOS/
|
74
|
+
build-iPhoneSimulator/
|
75
|
+
|
76
|
+
## Specific to RubyMotion (use of CocoaPods):
|
77
|
+
#
|
78
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
79
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
80
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
81
|
+
#
|
82
|
+
# vendor/Pods/
|
83
|
+
|
84
|
+
## Documentation cache and generated files:
|
85
|
+
/.yardoc/
|
86
|
+
/_yardoc/
|
87
|
+
/doc/
|
88
|
+
/rdoc/
|
89
|
+
|
90
|
+
## Environment normalization:
|
91
|
+
/.bundle/
|
92
|
+
/vendor/bundle
|
93
|
+
/lib/bundler/man/
|
94
|
+
|
95
|
+
# for a library or gem, you might want to ignore these files since the code is
|
96
|
+
# intended to run in multiple environments; otherwise, check them in:
|
97
|
+
# Gemfile.lock
|
98
|
+
# .ruby-version
|
99
|
+
# .ruby-gemset
|
100
|
+
|
101
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
102
|
+
.rvmrc
|
103
|
+
|
104
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
105
|
+
# .rubocop-https?--*
|
106
|
+
|
107
|
+
# This gitignore is from github/gitignore.
|
108
|
+
# https://github.com/github/gitignore/blob/master/Ruby.gitignore
|
109
|
+
GITIGNORE
|
110
|
+
".gitignore_nc" => <<~GITIGNORE,
|
111
|
+
*.gem
|
112
|
+
*.rbc
|
113
|
+
/.config
|
114
|
+
/coverage/
|
115
|
+
/InstalledFiles
|
116
|
+
/pkg/
|
117
|
+
/spec/reports/
|
118
|
+
/spec/examples.txt
|
119
|
+
/test/tmp/
|
120
|
+
/test/version_tmp/
|
121
|
+
/tmp/
|
122
|
+
|
123
|
+
.env
|
124
|
+
|
125
|
+
.byebug_history
|
126
|
+
|
127
|
+
.dat*
|
128
|
+
.repl_history
|
129
|
+
build/
|
130
|
+
*.bridgesupport
|
131
|
+
build-iPhoneOS/
|
132
|
+
build-iPhoneSimulator/
|
133
|
+
|
134
|
+
/.yardoc/
|
135
|
+
/_yardoc/
|
136
|
+
/doc/
|
137
|
+
/rdoc/
|
138
|
+
|
139
|
+
/.bundle/
|
140
|
+
/vendor/bundle
|
141
|
+
/lib/bundler/man/
|
142
|
+
|
143
|
+
.rvmrc
|
144
|
+
GITIGNORE
|
145
|
+
"Gemfile" => <<~RUBY,
|
146
|
+
# frozen_string_literal: true
|
147
|
+
|
148
|
+
source "https://rubygems.org"
|
149
|
+
|
150
|
+
git_source(:github) { |repo_name| "https://github.com/\#{repo_name}" }
|
151
|
+
|
152
|
+
gem "discorb", "~> #{Discorb::VERSION}"
|
153
|
+
gem "dotenv", "~> 2.7"
|
154
|
+
|
155
|
+
ruby "~> #{RUBY_VERSION.split(".")[0]}.#{RUBY_VERSION.split(".")[1]}"
|
156
|
+
RUBY
|
157
|
+
".env.sample" => <<~BASH,
|
158
|
+
%<token>s=
|
159
|
+
BASH
|
160
|
+
"README.md" => <<~MARKDOWN
|
161
|
+
# %<name>s
|
162
|
+
|
163
|
+
Welcome to your bot: %<name>s!
|
164
|
+
|
165
|
+
TODO: Write your bot's description here.
|
166
|
+
|
167
|
+
## Usage
|
168
|
+
|
169
|
+
TODO: Write your bot's usage here.
|
170
|
+
|
171
|
+
## Features
|
172
|
+
|
173
|
+
TODO: Write your bot's features here.
|
174
|
+
|
175
|
+
## How to host
|
176
|
+
|
177
|
+
1. Clone the repository.
|
178
|
+
2. Run `bundle install`.
|
179
|
+
3. Get your bot's token from the Discord developer portal.
|
180
|
+
4. Copy `.env.sample` to `.env` and fill in the token.
|
181
|
+
5. Run `bundle exec discorb run`.
|
182
|
+
|
183
|
+
TODO: Write your own customizations here.
|
184
|
+
|
185
|
+
## License
|
186
|
+
|
187
|
+
TODO: Write your bot's license here.
|
188
|
+
See https://choosealicense.com/ for more information.
|
189
|
+
|
190
|
+
MARKDOWN
|
191
|
+
}.freeze
|
192
|
+
|
193
|
+
# @private
|
194
|
+
def create_file(name)
|
195
|
+
template_name = name
|
196
|
+
template_name += "_nc" if !$values[:comment] && FILES.key?("#{name}_nc")
|
197
|
+
content =
|
198
|
+
format(FILES[template_name], token: $values[:token], name: $values[:name])
|
199
|
+
File.write($path + "/#{name}", content, mode: "wb")
|
200
|
+
end
|
201
|
+
|
202
|
+
# @private
|
203
|
+
def make_files
|
204
|
+
iputs "Making files..."
|
205
|
+
create_file("main.rb")
|
206
|
+
create_file(".env")
|
207
|
+
sputs "Made files.\n"
|
208
|
+
end
|
209
|
+
|
210
|
+
# @private
|
211
|
+
def bundle_init
|
212
|
+
iputs "Initializing bundle..."
|
213
|
+
create_file("Gemfile")
|
214
|
+
iputs "Installing gems..."
|
215
|
+
system({ "BUNDLE_GEMFILE" => nil }, "bundle install", chdir: $path)
|
216
|
+
sputs "Installed gems.\n"
|
217
|
+
end
|
218
|
+
|
219
|
+
# @private
|
220
|
+
def git_init
|
221
|
+
create_file(".gitignore")
|
222
|
+
iputs "Initializing git repository..."
|
223
|
+
system "git init", chdir: $path
|
224
|
+
sputs "Initialized repository.\n"
|
225
|
+
end
|
226
|
+
|
227
|
+
# @private
|
228
|
+
def make_descs
|
229
|
+
iputs "Making descriptions..."
|
230
|
+
create_file(".env.sample")
|
231
|
+
create_file("README.md")
|
232
|
+
sputs "Made descriptions.\n"
|
233
|
+
end
|
234
|
+
|
235
|
+
opt = OptionParser.new <<~BANNER
|
236
|
+
A tool to make a new project.
|
237
|
+
|
238
|
+
Usage: discorb new [options] [dir]
|
239
|
+
|
240
|
+
dir The directory to make the files in.
|
241
|
+
BANNER
|
242
|
+
|
243
|
+
$values = {
|
244
|
+
bundle: true,
|
245
|
+
git: false,
|
246
|
+
force: false,
|
247
|
+
token: "TOKEN",
|
248
|
+
descs: false,
|
249
|
+
name: nil,
|
250
|
+
comment: true
|
251
|
+
}
|
252
|
+
|
253
|
+
opt.on("--[no-]bundle", "Whether to use bundle. Default to true.") do |v|
|
254
|
+
$values[:bundle] = v
|
255
|
+
end
|
256
|
+
|
257
|
+
opt.on("--[no-]git", "Whether to initialize git. Default to false.") do |v|
|
258
|
+
$values[:git] = v
|
259
|
+
end
|
260
|
+
|
261
|
+
opt.on(
|
262
|
+
"--[no-]descs",
|
263
|
+
"Whether to put some file for description. Default to false."
|
264
|
+
) { |v| $values[:descs] = v }
|
265
|
+
|
266
|
+
opt.on("--[no-]comment", "Whether to write comment. Default to true.") do |v|
|
267
|
+
$values[:comment] = v
|
268
|
+
end
|
269
|
+
|
270
|
+
opt.on(
|
271
|
+
"-t NAME",
|
272
|
+
"--token NAME",
|
273
|
+
"The name of token environment variable. Default to TOKEN."
|
274
|
+
) { |v| $values[:token] = v }
|
275
|
+
|
276
|
+
opt.on(
|
277
|
+
"-n NAME",
|
278
|
+
"--name NAME",
|
279
|
+
"The name of your project. Default to the directory name."
|
280
|
+
) { |v| $values[:name] = v }
|
281
|
+
|
282
|
+
opt.on(
|
283
|
+
"--force",
|
284
|
+
"-f",
|
285
|
+
"Whether to force use directory. Default to false."
|
286
|
+
) { |v| $values[:force] = v }
|
287
|
+
|
288
|
+
opt.parse!(ARGV)
|
289
|
+
|
290
|
+
if (dir = ARGV[0])
|
291
|
+
$path += "/#{dir}"
|
292
|
+
$path = File.expand_path($path)
|
293
|
+
dir = File.basename($path)
|
294
|
+
if Dir.exist?($path)
|
295
|
+
if Dir.empty?($path)
|
296
|
+
iputs "Found \e[30m#{dir}\e[90m and empty, using this directory."
|
297
|
+
elsif $values[:force]
|
298
|
+
iputs "Found \e[30m#{dir}\e[90m and not empty, but force is on, using this directory."
|
299
|
+
else
|
300
|
+
eputs "Directory \e[31m#{dir}\e[91m already exists and not empty. Use \e[31m-f\e[91m to force."
|
301
|
+
exit
|
302
|
+
end
|
303
|
+
else
|
304
|
+
Dir.mkdir($path)
|
305
|
+
iputs "Couldn't find \e[30m#{dir}\e[90m, created directory."
|
306
|
+
end
|
307
|
+
Dir.chdir($path)
|
308
|
+
else
|
309
|
+
puts opt
|
310
|
+
abort
|
311
|
+
end
|
312
|
+
|
313
|
+
$values[:name] ||= Dir.pwd.split("/").last
|
314
|
+
|
315
|
+
bundle_init if $values[:bundle]
|
316
|
+
|
317
|
+
make_files
|
318
|
+
|
319
|
+
make_descs if $values[:descs]
|
320
|
+
|
321
|
+
git_init if $values[:git]
|
322
|
+
|
323
|
+
sputs "\nSuccessfully made a new project at \e[32m#{Pathname.new($path).cleanpath.split[-1]}\e[92m."
|