discorb 0.18.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.
Files changed (149) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build_version.yml +2 -2
  3. data/.rubocop.yml +12 -75
  4. data/Changelog.md +25 -0
  5. data/Gemfile +4 -4
  6. data/README.md +2 -1
  7. data/Rakefile +482 -459
  8. data/Steepfile +8 -6
  9. data/docs/application_command.md +1 -0
  10. data/docs/events.md +2 -2
  11. data/docs/voice_events.md +6 -6
  12. data/lib/discorb/allowed_mentions.rb +68 -72
  13. data/lib/discorb/app_command/command.rb +466 -394
  14. data/lib/discorb/app_command/common.rb +65 -25
  15. data/lib/discorb/app_command/handler.rb +304 -265
  16. data/lib/discorb/app_command.rb +5 -5
  17. data/lib/discorb/application.rb +198 -197
  18. data/lib/discorb/asset.rb +101 -101
  19. data/lib/discorb/attachment.rb +134 -119
  20. data/lib/discorb/audit_logs.rb +412 -385
  21. data/lib/discorb/automod.rb +279 -269
  22. data/lib/discorb/channel/base.rb +107 -108
  23. data/lib/discorb/channel/category.rb +32 -32
  24. data/lib/discorb/channel/container.rb +44 -44
  25. data/lib/discorb/channel/dm.rb +26 -28
  26. data/lib/discorb/channel/guild.rb +311 -246
  27. data/lib/discorb/channel/stage.rb +156 -140
  28. data/lib/discorb/channel/text.rb +430 -336
  29. data/lib/discorb/channel/thread.rb +374 -325
  30. data/lib/discorb/channel/voice.rb +85 -79
  31. data/lib/discorb/channel.rb +5 -5
  32. data/lib/discorb/client.rb +635 -623
  33. data/lib/discorb/color.rb +178 -182
  34. data/lib/discorb/common.rb +168 -164
  35. data/lib/discorb/components/button.rb +107 -106
  36. data/lib/discorb/components/select_menu.rb +157 -145
  37. data/lib/discorb/components/text_input.rb +103 -106
  38. data/lib/discorb/components.rb +68 -66
  39. data/lib/discorb/dictionary.rb +135 -135
  40. data/lib/discorb/embed.rb +404 -398
  41. data/lib/discorb/emoji.rb +309 -302
  42. data/lib/discorb/emoji_table.rb +16099 -8857
  43. data/lib/discorb/error.rb +131 -131
  44. data/lib/discorb/event.rb +360 -314
  45. data/lib/discorb/event_handler.rb +39 -39
  46. data/lib/discorb/exe/about.rb +17 -17
  47. data/lib/discorb/exe/irb.rb +72 -67
  48. data/lib/discorb/exe/new.rb +323 -315
  49. data/lib/discorb/exe/run.rb +69 -68
  50. data/lib/discorb/exe/setup.rb +57 -55
  51. data/lib/discorb/exe/show.rb +12 -12
  52. data/lib/discorb/extend.rb +25 -45
  53. data/lib/discorb/extension.rb +89 -83
  54. data/lib/discorb/flag.rb +126 -128
  55. data/lib/discorb/gateway.rb +984 -794
  56. data/lib/discorb/gateway_events.rb +670 -638
  57. data/lib/discorb/gateway_requests.rb +45 -48
  58. data/lib/discorb/guild.rb +2115 -1626
  59. data/lib/discorb/guild_template.rb +280 -241
  60. data/lib/discorb/http.rb +247 -232
  61. data/lib/discorb/image.rb +42 -42
  62. data/lib/discorb/integration.rb +169 -161
  63. data/lib/discorb/intents.rb +161 -163
  64. data/lib/discorb/interaction/autocomplete.rb +76 -62
  65. data/lib/discorb/interaction/command.rb +279 -224
  66. data/lib/discorb/interaction/components.rb +114 -104
  67. data/lib/discorb/interaction/modal.rb +36 -32
  68. data/lib/discorb/interaction/response.rb +379 -330
  69. data/lib/discorb/interaction/root.rb +271 -118
  70. data/lib/discorb/interaction.rb +5 -5
  71. data/lib/discorb/invite.rb +154 -153
  72. data/lib/discorb/member.rb +344 -311
  73. data/lib/discorb/message.rb +615 -544
  74. data/lib/discorb/message_meta.rb +197 -186
  75. data/lib/discorb/modules.rb +371 -290
  76. data/lib/discorb/permission.rb +305 -289
  77. data/lib/discorb/presence.rb +352 -346
  78. data/lib/discorb/rate_limit.rb +81 -76
  79. data/lib/discorb/reaction.rb +55 -54
  80. data/lib/discorb/role.rb +272 -240
  81. data/lib/discorb/shard.rb +76 -74
  82. data/lib/discorb/sticker.rb +193 -171
  83. data/lib/discorb/user.rb +205 -188
  84. data/lib/discorb/utils/colored_puts.rb +16 -16
  85. data/lib/discorb/utils.rb +12 -16
  86. data/lib/discorb/voice_state.rb +305 -281
  87. data/lib/discorb/webhook.rb +537 -507
  88. data/lib/discorb.rb +62 -56
  89. data/sig/discorb/activity.rbs +1 -0
  90. data/sig/discorb/allowed_mentions.rbs +1 -0
  91. data/sig/discorb/app_command/base.rbs +7 -1
  92. data/sig/discorb/application.rbs +6 -0
  93. data/sig/discorb/asset.rbs +2 -0
  94. data/sig/discorb/attachment.rbs +8 -0
  95. data/sig/discorb/audit_log.rbs +7 -0
  96. data/sig/discorb/automod.rbs +32 -6
  97. data/sig/discorb/avatar.rbs +1 -0
  98. data/sig/discorb/channel/base.rbs +8 -1
  99. data/sig/discorb/channel/category.rbs +1 -0
  100. data/sig/discorb/channel/container.rbs +4 -0
  101. data/sig/discorb/channel/stage.rbs +4 -0
  102. data/sig/discorb/channel/text.rbs +2 -2
  103. data/sig/discorb/channel/thread.rbs +11 -0
  104. data/sig/discorb/channel/voice.rbs +2 -0
  105. data/sig/discorb/client.rbs +21 -20
  106. data/sig/discorb/color.rbs +6 -0
  107. data/sig/discorb/component/base.rbs +1 -0
  108. data/sig/discorb/component/button.rbs +2 -0
  109. data/sig/discorb/component/select_menu.rbs +4 -0
  110. data/sig/discorb/component/text_input.rbs +1 -0
  111. data/sig/discorb/custom_emoji.rbs +5 -1
  112. data/sig/discorb/dictionary.rbs +2 -0
  113. data/sig/discorb/discord_model.rbs +2 -0
  114. data/sig/discorb/embed.rbs +7 -0
  115. data/sig/discorb/emoji.rbs +1 -0
  116. data/sig/discorb/event_handler.rbs +2 -1
  117. data/sig/discorb/extension.rbs +13 -12
  118. data/sig/discorb/flag.rbs +2 -0
  119. data/sig/discorb/gateway.rbs +5 -0
  120. data/sig/discorb/guild.rbs +8 -4
  121. data/sig/discorb/guild_template.rbs +1 -1
  122. data/sig/discorb/http.rbs +4 -1
  123. data/sig/discorb/image.rbs +2 -0
  124. data/sig/discorb/integration.rbs +1 -1
  125. data/sig/discorb/intents.rbs +4 -3
  126. data/sig/discorb/interaction/base.rbs +36 -0
  127. data/sig/discorb/interaction/message_component.rbs +1 -2
  128. data/sig/discorb/interaction/modal.rbs +1 -2
  129. data/sig/discorb/interaction/responder.rbs +49 -49
  130. data/sig/discorb/invite.rbs +1 -1
  131. data/sig/discorb/member.rbs +2 -0
  132. data/sig/discorb/message.rbs +8 -1
  133. data/sig/discorb/messageable.rbs +1 -4
  134. data/sig/discorb/partial_emoji.rbs +3 -0
  135. data/sig/discorb/permissions.rbs +7 -0
  136. data/sig/discorb/presence.rbs +2 -0
  137. data/sig/discorb/reaction.rbs +5 -1
  138. data/sig/discorb/role.rbs +7 -1
  139. data/sig/discorb/scheduled_event.rbs +2 -1
  140. data/sig/discorb/shard.rbs +2 -1
  141. data/sig/discorb/snowflake.rbs +2 -0
  142. data/sig/discorb/stage_instance.rbs +9 -3
  143. data/sig/discorb/sticker.rbs +1 -1
  144. data/sig/discorb/unicode_emoji.rbs +4 -0
  145. data/sig/discorb/user.rbs +24 -20
  146. data/sig/discorb/webhook.rbs +17 -6
  147. data/sig/discorb/welcome_screen.rbs +1 -0
  148. data/sig/override.rbs +2 -0
  149. metadata +3 -3
@@ -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 + "_nc")
197
- content = format(FILES[template_name], token: $values[:token], name: $values[:name])
198
- File.write($path + "/#{name}", content, mode: "wb")
199
- end
200
-
201
- # @private
202
- def make_files
203
- iputs "Making files..."
204
- create_file("main.rb")
205
- create_file(".env")
206
- sputs "Made files.\n"
207
- end
208
-
209
- # @private
210
- def bundle_init
211
- iputs "Initializing bundle..."
212
- create_file("Gemfile")
213
- iputs "Installing gems..."
214
- system({ "BUNDLE_GEMFILE" => nil }, "bundle install", chdir: $path)
215
- sputs "Installed gems.\n"
216
- end
217
-
218
- # @private
219
- def git_init
220
- create_file(".gitignore")
221
- iputs "Initializing git repository..."
222
- system "git init", chdir: $path
223
- sputs "Initialized repository.\n"
224
- end
225
-
226
- # @private
227
- def make_descs
228
- iputs "Making descriptions..."
229
- create_file(".env.sample")
230
- create_file("README.md")
231
- sputs "Made descriptions.\n"
232
- end
233
-
234
- opt = OptionParser.new <<~BANNER
235
- A tool to make a new project.
236
-
237
- Usage: discorb new [options] [dir]
238
-
239
- dir The directory to make the files in.
240
- BANNER
241
-
242
- $values = {
243
- bundle: true,
244
- git: false,
245
- force: false,
246
- token: "TOKEN",
247
- descs: false,
248
- name: nil,
249
- comment: true,
250
- }
251
-
252
- opt.on("--[no-]bundle", "Whether to use bundle. Default to true.") do |v|
253
- $values[:bundle] = v
254
- end
255
-
256
- opt.on("--[no-]git", "Whether to initialize git. Default to false.") do |v|
257
- $values[:git] = v
258
- end
259
-
260
- opt.on("--[no-]descs", "Whether to put some file for description. Default to false.") do |v|
261
- $values[:descs] = v
262
- end
263
-
264
- opt.on("--[no-]comment", "Whether to write comment. Default to true.") do |v|
265
- $values[:comment] = v
266
- end
267
-
268
- opt.on("-t NAME", "--token NAME", "The name of token environment variable. Default to TOKEN.") do |v|
269
- $values[:token] = v
270
- end
271
-
272
- opt.on("-n NAME", "--name NAME", "The name of your project. Default to the directory name.") do |v|
273
- $values[:name] = v
274
- end
275
-
276
- opt.on("--force", "-f", "Whether to force use directory. Default to false.") do |v|
277
- $values[:force] = v
278
- end
279
-
280
- opt.parse!(ARGV)
281
-
282
- if (dir = ARGV[0])
283
- $path += "/#{dir}"
284
- $path = File.expand_path($path)
285
- dir = File.basename($path)
286
- if Dir.exist?($path)
287
- if Dir.empty?($path)
288
- iputs "Found \e[30m#{dir}\e[90m and empty, using this directory."
289
- elsif $values[:force]
290
- iputs "Found \e[30m#{dir}\e[90m and not empty, but force is on, using this directory."
291
- else
292
- eputs "Directory \e[31m#{dir}\e[91m already exists and not empty. Use \e[31m-f\e[91m to force."
293
- exit
294
- end
295
- else
296
- Dir.mkdir($path)
297
- iputs "Couldn't find \e[30m#{dir}\e[90m, created directory."
298
- end
299
- Dir.chdir($path)
300
- else
301
- puts opt
302
- abort
303
- end
304
-
305
- $values[:name] ||= Dir.pwd.split("/").last
306
-
307
- bundle_init if $values[:bundle]
308
-
309
- make_files
310
-
311
- make_descs if $values[:descs]
312
-
313
- git_init if $values[:git]
314
-
315
- sputs "\nSuccessfully made a new project at \e[32m#{Pathname.new($path).cleanpath.split[-1]}\e[92m."
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."