discorb 0.9.5 → 0.10.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: 39902a57677adf3ce903678e58060ee04da318617ba81611546772131c9d1696
4
- data.tar.gz: 6f0f17d2230a19b79f6330cda2d567f704f8ffe44ca59e8938cc0ec0f32dfb35
3
+ metadata.gz: 5ea8e05d77b37b7a269b43dff64422e3d49b08d6c09a639d40dc019baaa26a8c
4
+ data.tar.gz: c8ea6f45759aaf22112f6400f7d950fb09f427f98d01302a18094ad3d6a3ae08
5
5
  SHA512:
6
- metadata.gz: 453b9228e5afca3d9b206b54aa3f34f97b3a4c6d6ade46034fe3d0fd8620c1069d0288fa672bc20cdcce2816405f925d92a9fcf6012bc73d5a09fdb4bc7c0335
7
- data.tar.gz: 11920dcfc13754975686abe69504af19f81331fa684fd5d51aa1065ff426300dfa90ef373c626a84f1c3533e511dd0f35641126f020c1838bc7262538d6fa505
6
+ metadata.gz: b3f5e77107192aec6943087251c5b61ab1476eb421ddb0297d61178e5146466a5a59c50f4665a2b81c362d927765259142ed1bc08ed9c07e3018102becab3294
7
+ data.tar.gz: b88f74d4f3e0f0025f7086e95c2b1e2b96ed19a35a258a72dd29f1814986465ac9fdd8443f920fe8b7dcd610d35871b59354ba8cc6b478bcf883797cd17d463d
data/Changelog.md CHANGED
@@ -1,260 +1,309 @@
1
- # Changelog
2
-
3
- ## v0.0.1
4
-
5
- - Initial release
6
-
7
- ## v0.0.2
8
-
9
- - Fix: Fix rubygems description
10
-
11
- ## v0.0.3
12
-
13
- - Fix: Fix no dependencies
14
-
15
- ## v0.0.4
16
-
17
- - Fix: Fix NoMethodError by webhook message
18
- - Add: Add `#author` to webhook message
19
- - Fix: Add `#bot?` to webhook author
20
-
21
- ## v0.0.5
22
-
23
- - Fix: Fix GitHub link
24
- - Change: Internet to HTTP
25
-
26
- ## v0.0.6
27
-
28
- - Fix: Fix error in client without members intent
29
- - Add: Add ThreadChannel::News
30
- - Add: Add official discord link
31
-
32
- ## v0.0.7
33
-
34
- - Fix: Fix `member_xxx` event
35
-
36
- ## 0.0.8
37
-
38
- - Delete: Delete task parameter
39
-
40
- ## 0.1.0
41
-
42
- - Add: Add `User#created_at`
43
- - Add: Add `Member#to_s_user`
44
- - Add: Add `DefaultAvatar`
45
- - Add: Support application commands
46
- - Add: Add `Client#ping`
47
- - Add: Allow `String` for `Embed#initialize`
48
- - Change: Change log format
49
-
50
- ## 0.2.0
51
-
52
- - Fix: Fix unused dependency
53
- - Add: Add `Client#close!`
54
- - Add: Add discord-irb
55
-
56
- ## 0.2.1
57
-
58
- - Fix: Fix NoMethodError in reaction event
59
- - Add: Add Changelog.md to document
60
-
61
- ## 0.2.2 (yanked)
62
-
63
- - Add: Add `Snowflake#to_str`
64
-
65
- ## 0.2.3
66
-
67
- - Fix: Fix critical error
68
-
69
- ## 0.2.4
70
-
71
- - Fix: Fix error in `Embed#image=`, `Embed#thumbnail=`
72
-
73
- ## 0.2.5
74
-
75
- - Add: Add way to add event listener
76
- - Change: Move document to https://discorb-lib.github.io/
77
-
78
- ## 0.3.0
79
-
80
- - Add: Improve CLI tools
81
- - Add: Add `discorb init`
82
- - Change: Change `discord-irb` to `discorb irb`
83
-
84
- ## 0.3.1
85
-
86
- - Add: Add `discorb show`
87
- - Fix: Fix documenting
88
-
89
- ## 0.4.0
90
-
91
- - Add: Add `discorb setup`
92
- - Add: Add `discorb run`
93
- - Add: Add realtime documentation
94
-
95
- ## 0.4.1
96
-
97
- - Add: Add `-s` option to `discorb run`
98
-
99
- ## 0.4.2
100
-
101
- - Fix: Fix error in `discorb run`
102
-
103
- ## 0.5.0
104
-
105
- - Change: Use zlib stream instead
106
- - Add: Add tutorials
107
- - Add: Add ratelimit handler
108
- - Change: Make `--git` option in `discorb init` false
109
-
110
- ## 0.5.1
111
-
112
- - Add: Can use block for defining group commands
113
- - Fix: Fix bug in subcommands
114
- - Fix: Fix bug in receiving commands
115
-
116
- ## 0.5.2
117
-
118
- - Fix: Fix bug of registering commands
119
- - Add: Add way to register commands in Extension
120
-
121
- ## 0.5.3
122
-
123
- - Add: Add way to handle raw events with `event_xxx`
124
- - Add: Add `Client#session_id`
125
- - Add: Add `Connectable`
126
- - Fix: Fix error by sending DM
127
-
128
- ## 0.5.4
129
-
130
- - Fix: Fix issue of receiving component events
131
-
132
- ## 0.5.5
133
-
134
- - Fix: Fix some bugs
135
-
136
- ## 0.5.6
137
-
138
- - Add: Raise error when intents are invalid
139
- - Fix: Fix Emoji#==
140
-
141
- ## 0.6.0
142
-
143
- - Fix: Fix issue with client with no guilds
144
- - Add: Add rbs (experimental)
145
- - Add: Add `-t`, `--token` option to `discorb run`
146
- - Add: Add `-g`, `--guild` option to `discorb setup`
147
- - Change: Use `Async::Task<R>` instead of `R` in return value
148
-
149
- ## 0.6.1
150
-
151
- - Change: Rename `Event#discriminator` to `Event#metadata`
152
- - Add: Add `:override` to `Client#on`
153
-
154
- ## 0.7.0
155
-
156
- - Add: Add `error` event
157
- - Fix: Fix some issues with client without guild intent
158
- - Add: Add alias for `#fired_by`
159
- - Change!: Change block usage of `ApplicationCommand::Handler#group`
160
-
161
- ```ruby
162
- # before
163
- client.slash_group do
164
- slash "help", "Help" do |interaction|
165
- # ...
166
- end
167
- end
168
-
169
- # after
170
- client.slash_group do |group|
171
- group.slash "help", "Help" do |interaction|
172
- # ...
173
- end
174
- end
175
-
176
- ```
177
-
178
- ## 0.7.1
179
-
180
- - Fix: Fix error of responding to interaction
181
-
182
- ## 0.7.2
183
-
184
- - Add: Add `Member#owner?`
185
- - Fix: Fix `Member#permissions`
186
- - Add: Add `Member#guild_permissions` as alias of `Member#permissions`
187
- - Add: Add default role to `Member#roles`
188
- - Fix: Fix error in `Integration#_set_data`
189
- - Change: Reverse `Member#roles`
190
-
191
- ## 0.7.3
192
-
193
- - Add: Improve `discorb init`
194
-
195
- ## 0.7.4 (yanked)
196
-
197
- - Fix: Fix disconnected client
198
-
199
- ## 0.7.5 (yanked)
200
-
201
- - Fix: Fix critical error
202
-
203
- ## 0.7.6
204
-
205
- - Fix: Fix heartbeating error
206
-
207
- ## 0.8.0
208
-
209
- - Add: Add `Guild#fetch_members`
210
- - Add: Add `Guild#fetch_member_list` as alias of `Guild#fetch_members`
211
- - Add: Add `Intents#to_h`
212
- - Add: Add `fetch_member` parameter to `Client#initialize`; Note you should set `false` if your bot doesn't have `GUILD_MEMBERS` intent
213
- - Change: Change `ready` to `standby` event
214
- - Change: `ready` will be fired when client receives `READY` event
215
-
216
- ## 0.8.1
217
-
218
- - Add: Add FAQ
219
- - Fix: Fix sending files
220
- - Add: Add `File.from_string`
221
- - Fix: Fix `Client#update_presence`
222
- - Add: Add information in `discorb run -d`
223
-
224
- ## 0.8.2
225
-
226
- - Fix: Fix `Client#initialize`
227
-
228
- ## 0.9.0
229
-
230
- - Delete: Delete `-d` parameter from `discorb run`; This is caused by segement fault error.
231
- - Change: Rename `-t`, `--token` to `-e`, `--env` parameter
232
- - Add: Add `-t`, `--title` parameter to `discorb run`
233
- - Add: Add `title` parameter to `Client#initialize`
234
-
235
- ## 0.9.1
236
-
237
- - Fix: Fix member fetching
238
-
239
- ## 0.9.2 (yanked)
240
-
241
- - Add: Make `Async::Task#inspect` shorter
242
- - Add: `SourceResponse#post` will return message now
243
- - Fix: Fix member caching
244
-
245
- ## 0.9.3
246
-
247
- - Fix: Fix interaction responding
248
-
249
- ## 0.9.4
250
-
251
- - Change: `Messageable#typing` with block is now synchronous
252
- - Fix: Fix some issues in document
253
- - Add: Add some attributes to `Message`
254
- - Fix: Fix guild parameter in message of message command
255
-
256
- ## 0.9.5
257
-
258
- - Fix: Fix editing message
259
- - Add: Add `required` in slash command argument
260
- - Add: Add `default` in slash command argument
1
+ # @title Changelog
2
+
3
+ # Changelog
4
+
5
+ ## v0.10
6
+
7
+ ### v0.10.2
8
+
9
+ - Change: `discorb init` is now `discorb new`
10
+ - Add: Add `:channel_types` parameter to `ApplicationCommand::Handler#slash` and some
11
+
12
+ ### v0.10.1
13
+
14
+ - Add: Add `Client#extensions`
15
+ - Change: `Client#load_extension` allows instance of `Extension`
16
+ - Add: Add `-b` option to `discorb run`
17
+
18
+ ### v0.10.0
19
+
20
+ - Change: Sort versions
21
+ - Change: Snowflake is now String
22
+ - Change: Extension is now Class
23
+ - Add: Add `SelectMenu#disabled=`
24
+
25
+ ## v0.9
26
+
27
+ ### v0.9.6
28
+
29
+ - Add: Add `Messageable#send_message` as alias of `Messageable#post`
30
+ - Fix: Fix interaction responding with updating message
31
+ - Fix: Fix `MessageComponentInteraction#message`
32
+
33
+ ### v0.9.5
34
+
35
+ - Fix: Fix editing message
36
+ - Add: Add `required` in slash command argument
37
+ - Add: Add `default` in slash command argument
38
+
39
+ ### v0.9.4
40
+
41
+ - Change: `Messageable#typing` with block is now synchronous
42
+ - Fix: Fix some issues in document
43
+ - Add: Add some attributes to `Message`
44
+ - Fix: Fix guild parameter in message of message command
45
+
46
+ ### v0.9.3
47
+
48
+ - Fix: Fix interaction responding
49
+
50
+ ### v0.9.2 (yanked)
51
+
52
+ - Add: Make `Async::Task#inspect` shorter
53
+ - Add: `SourceResponse#post` will return message now
54
+ - Fix: Fix member caching
55
+
56
+ ### v0.9.1
57
+
58
+ - Fix: Fix member fetching
59
+
60
+ ### v0.9.0
61
+
62
+ - Delete: Delete `-d` parameter from `discorb run`; This is caused by segement fault error.
63
+ - Change: Rename `-t`, `--token` to `-e`, `--env` parameter
64
+ - Add: Add `-t`, `--title` parameter to `discorb run`
65
+ - Add: Add `title` parameter to `Client#initialize`
66
+
67
+ ## v0.8
68
+
69
+ ### v0.8.2
70
+
71
+ - Fix: Fix `Client#initialize`
72
+
73
+ ### v0.8.1
74
+
75
+ - Add: Add FAQ
76
+ - Fix: Fix sending files
77
+ - Add: Add `File.from_string`
78
+ - Fix: Fix `Client#update_presence`
79
+ - Add: Add information in `discorb run -d`
80
+
81
+ ### v0.8.0
82
+
83
+ - Add: Add `Guild#fetch_members`
84
+ - Add: Add `Guild#fetch_member_list` as alias of `Guild#fetch_members`
85
+ - Add: Add `Intents#to_h`
86
+ - Add: Add `fetch_member` parameter to `Client#initialize`; Note you should set `false` if your bot doesn't have `GUILD_MEMBERS` intent
87
+ - Change: Change `ready` to `standby` event
88
+ - Change: `ready` will be fired when client receives `READY` event
89
+
90
+ ## v0.7
91
+
92
+ ### v0.7.6
93
+
94
+ - Fix: Fix heartbeating error
95
+
96
+ ### v0.7.5 (yanked)
97
+
98
+ - Fix: Fix critical error
99
+
100
+ ### v0.7.4 (yanked)
101
+
102
+ - Fix: Fix disconnected client
103
+
104
+ ### v0.7.3
105
+
106
+ - Add: Improve `discorb init`
107
+
108
+ ### v0.7.2
109
+
110
+ - Add: Add `Member#owner?`
111
+ - Fix: Fix `Member#permissions`
112
+ - Add: Add `Member#guild_permissions` as alias of `Member#permissions`
113
+ - Add: Add default role to `Member#roles`
114
+ - Fix: Fix error in `Integration#_set_data`
115
+ - Change: Reverse `Member#roles`
116
+
117
+ ### v0.7.1
118
+
119
+ - Fix: Fix error of responding to interaction
120
+
121
+ ### v0.7.0
122
+
123
+ - Add: Add `error` event
124
+ - Fix: Fix some issues with client without guild intent
125
+ - Add: Add alias for `#fired_by`
126
+ - Change!: Change block usage of `ApplicationCommand::Handler#group`
127
+
128
+ ```ruby
129
+ # before
130
+ client.slash_group do
131
+ slash "help", "Help" do |interaction|
132
+ # ...
133
+ end
134
+ end
135
+
136
+ # after
137
+ client.slash_group do |group|
138
+ group.slash "help", "Help" do |interaction|
139
+ # ...
140
+ end
141
+ end
142
+
143
+ ```
144
+
145
+ ## v0.6
146
+
147
+ ### v0.6.1
148
+
149
+ - Change: Rename `Event#discriminator` to `Event#metadata`
150
+ - Add: Add `:override` to `Client#on`
151
+
152
+ ### v0.6.0
153
+
154
+ - Fix: Fix issue with client with no guilds
155
+ - Add: Add rbs (experimental)
156
+ - Add: Add `-t`, `--token` option to `discorb run`
157
+ - Add: Add `-g`, `--guild` option to `discorb setup`
158
+ - Change: Use `Async::Task<R>` instead of `R` in return value
159
+
160
+ ## v0.5
161
+
162
+ ### v0.5.6
163
+
164
+ - Add: Raise error when intents are invalid
165
+ - Fix: Fix Emoji#==
166
+
167
+ ### v0.5.5
168
+
169
+ - Fix: Fix some bugs
170
+
171
+ ### v0.5.4
172
+
173
+ - Fix: Fix issue of receiving component events
174
+
175
+ ### v0.5.3
176
+
177
+ - Add: Add way to handle raw events with `event_xxx`
178
+ - Add: Add `Client#session_id`
179
+ - Add: Add `Connectable`
180
+ - Fix: Fix error by sending DM
181
+
182
+ ### v0.5.2
183
+
184
+ - Fix: Fix bug of registering commands
185
+ - Add: Add way to register commands in Extension
186
+
187
+ ### v0.5.1
188
+
189
+ - Add: Can use block for defining group commands
190
+ - Fix: Fix bug in subcommands
191
+ - Fix: Fix bug in receiving commands
192
+
193
+ ### v0.5.0
194
+
195
+ - Change: Use zlib stream instead
196
+ - Add: Add tutorials
197
+ - Add: Add ratelimit handler
198
+ - Change: Make `--git` option in `discorb init` false
199
+
200
+ ## v0.4
201
+
202
+ ### v0.4.2
203
+
204
+ - Fix: Fix error in `discorb run`
205
+
206
+ ### v0.4.1
207
+
208
+ - Add: Add `-s` option to `discorb run`
209
+
210
+ ### v0.4.0
211
+
212
+ - Add: Add `discorb setup`
213
+ - Add: Add `discorb run`
214
+ - Add: Add realtime documentation
215
+
216
+ ## v0.3
217
+
218
+ ### v0.3.1
219
+
220
+ - Add: Add `discorb show`
221
+ - Fix: Fix documenting
222
+
223
+ ### v0.3.0
224
+
225
+ - Add: Improve CLI tools
226
+ - Add: Add `discorb init`
227
+ - Change: Change `discord-irb` to `discorb irb`
228
+
229
+ ## v0.2
230
+
231
+ ### v0.2.5
232
+
233
+ - Add: Add way to add event listener
234
+ - Change: Move document to https://discorb-lib.github.io/
235
+
236
+ ### v0.2.4
237
+
238
+ - Fix: Fix error in `Embed#image=`, `Embed#thumbnail=`
239
+
240
+ ### v0.2.3
241
+
242
+ - Fix: Fix critical error
243
+
244
+ ### v0.2.2 (yanked)
245
+
246
+ - Add: Add `Snowflake#to_str`
247
+
248
+ ### v0.2.1
249
+
250
+ - Fix: Fix NoMethodError in reaction event
251
+ - Add: Add Changelog.md to document
252
+
253
+ ### v0.2.0
254
+
255
+ - Fix: Fix unused dependency
256
+ - Add: Add `Client#close!`
257
+ - Add: Add discord-irb
258
+
259
+ ## v0.1
260
+
261
+ ### v0.1.0
262
+
263
+ - Add: Add `User#created_at`
264
+ - Add: Add `Member#to_s_user`
265
+ - Add: Add `DefaultAvatar`
266
+ - Add: Support application commands
267
+ - Add: Add `Client#ping`
268
+ - Add: Allow `String` for `Embed#initialize`
269
+ - Change: Change log format
270
+
271
+ ## v0.0
272
+
273
+ ### v0.0.8
274
+
275
+ - Delete: Delete task parameter
276
+
277
+ ### v0.0.7
278
+
279
+ - Fix: Fix `member_xxx` event
280
+
281
+ ### v0.0.6
282
+
283
+ - Fix: Fix error in client without members intent
284
+ - Add: Add ThreadChannel::News
285
+ - Add: Add official discord link
286
+
287
+ ### v0.0.5
288
+
289
+ - Fix: Fix GitHub link
290
+ - Change: Internet to HTTP
291
+
292
+ ### v0.0.4
293
+
294
+ - Fix: Fix NoMethodError by webhook message
295
+ - Add: Add `#author` to webhook message
296
+ - Fix: Add `#bot?` to webhook author
297
+
298
+ ### v0.0.3
299
+
300
+ - Fix: Fix no dependencies
301
+
302
+ ### v0.0.2
303
+
304
+ - Fix: Fix rubygems description
305
+
306
+ ### v0.0.1
307
+
308
+ - Initial release
309
+
@@ -68,6 +68,7 @@ In `options`, hash should be like this:
68
68
  | `:type` | `Object` | Type of the option. |
69
69
  | `:choice` | `Hash{String => String, Integer, Float}` | Type of the option. |
70
70
  | `:default` | `Object` | Default value of the option. |
71
+ | `:channel_types` | `Array<Class<Discorb::Channel>>` | Type of the channel option. |
71
72
 
72
73
  `choices` should be unspecified if you don't want to use it.
73
74
  `choices` is hash like this:
data/docs/cli/init.md CHANGED
@@ -1,13 +1,13 @@
1
- # @title CLI: discorb init
1
+ # @title CLI: discorb new
2
2
 
3
- # discorb init
3
+ # discorb new
4
4
 
5
5
  This command will create a new project in the directory.
6
6
 
7
7
  ## Usage
8
8
 
9
9
  ```bash
10
- discorb init [options] [dir]
10
+ discorb new [options] [dir]
11
11
  ```
12
12
 
13
13
  ## Options
data/docs/cli/run.md CHANGED
@@ -53,4 +53,8 @@ Whether to setup application commands.
53
53
 
54
54
  #### `-e`, `--env`
55
55
 
56
- The name of the environment variable to use for token, or just `-t` or `--token` for intractive prompt.
56
+ The name of the environment variable to use for token, or just `-t` or `--token` for intractive prompt.
57
+
58
+ #### `-b`, `--bundler`
59
+
60
+ Whether to use bundler to load the script.
data/docs/extension.md CHANGED
@@ -2,16 +2,16 @@
2
2
 
3
3
  # Extension
4
4
 
5
- Extension allows you to split your code into multiple files.
5
+ Extension allows you to seperate your code from the main application.
6
+
7
+ # @since
6
8
 
7
9
  ## Make a new extension
8
10
 
9
- Make a new module, and extend {Discorb::Extension}.
11
+ Make a new class that extends Extension.
10
12
 
11
13
  ```ruby
12
- module MyExtension
13
- extend Discorb::Extension
14
-
14
+ class MyExtension < Discorb::Extension
15
15
  # ...
16
16
  end
17
17
  ```
@@ -21,27 +21,25 @@ end
21
21
  Use {Discorb::Extension.event} to register event, or {Discorb::Extension.once_event} to register event only once.
22
22
 
23
23
  ```ruby
24
- module MyExtension
25
- extend Discorb::Extension
26
-
24
+ class MyExtension < Discorb::Extension
27
25
  event :message do |message|
28
26
  # ...
29
27
  end
30
28
 
31
- once_event :ready do |message|
29
+ once_event :standby do |message|
32
30
  # ...
33
31
  end
34
32
  end
35
33
  ```
36
34
 
35
+ Note block will be binded to the extension instance.
36
+
37
37
  ## Register Command
38
38
 
39
- Since v0.5.2, {Discorb::Extension} includes {Discorb::ApplicationCommand::Handler} module, so you can register command with {Discorb::ApplicationCommand::Handler#slash} and {Discorb::ApplicationCommand::Handler#slash_group}.
39
+ Use `Discorb::Extension.command` to register command, see {Discorb::ApplicationCommand::Handler} for more information.
40
40
 
41
41
  ```ruby
42
- module MyExtension
43
- extend Discorb::Extension
44
-
42
+ class MyExtension < Discorb::Extension
45
43
  slash("command", "Command") do |interaction|
46
44
  # ...
47
45
  end
@@ -63,18 +61,16 @@ end
63
61
 
64
62
  ## Load extension
65
63
 
66
- Use {Discorb::Client#extend} to load extension.
64
+ Use {Discorb::Client#load_extension} to load extension.
67
65
 
68
66
  ```ruby
69
- module MyExtension
70
- extend Discorb::Extension
71
-
67
+ class MyExtension < Discorb::Extension
72
68
  event :message do |message|
73
69
  # ...
74
70
  end
75
71
  end
76
72
 
77
- client.extend MyExtension
73
+ client.load_extension(MyExtension)
78
74
  ```
79
75
 
80
76
  ## Access Client from extension
@@ -82,10 +78,8 @@ client.extend MyExtension
82
78
  You can access {Discorb::Client} from extension with `@client`.
83
79
 
84
80
  ```ruby
85
- module MyExtension
86
- extend Discorb::Extension
87
-
88
- event :ready do |message|
81
+ class MyExtension < Discorb::Extension
82
+ event :standby do |message|
89
83
  puts "Logged in as #{@client.user}"
90
84
  end
91
85
  end
data/docs/license.md CHANGED
@@ -4,4 +4,8 @@
4
4
 
5
5
  discorb is licensed under the [MIT license](https://opensource.org/licenses/MIT).
6
6
 
7
+ ----
8
+
7
9
  {include:file:LICENSE.txt}
10
+
11
+ ----
data/docs/tutorial.md CHANGED
@@ -74,7 +74,7 @@ Create a new directory and go to it.
74
74
  Open terminal and type:
75
75
 
76
76
  ```
77
- discorb init
77
+ discorb new
78
78
  ```
79
79
 
80
80
  Specify `--git` if you want to use git.
@@ -7,6 +7,6 @@ client.once :standby do
7
7
  puts "Logged in as #{client.user}"
8
8
  end
9
9
 
10
- client.extend(MessageExpander)
10
+ client.load_extension(MessageExpander)
11
11
 
12
12
  client.run(ENV["DISCORD_BOT_TOKEN"])
@@ -1,9 +1,7 @@
1
1
  require "discorb"
2
2
 
3
- module MessageExpander
4
- extend Discorb::Extension
5
-
6
- @message_regex = Regexp.new(
3
+ class MessageExpander < Discorb::Extension
4
+ @@message_regex = Regexp.new(
7
5
  '(?!<)https://(?:ptb\.|canary\.)?discord(?:app)?\.com/channels/' \
8
6
  "(?<guild>[0-9]{18})/(?<channel>[0-9]{18})/(?<message>[0-9]{18})(?!>)"
9
7
  )
@@ -11,7 +9,7 @@ module MessageExpander
11
9
  event :message do |message|
12
10
  next if message.author.bot?
13
11
 
14
- message.content.to_enum(:scan, @message_regex).map { Regexp.last_match }.each do |match|
12
+ message.content.to_enum(:scan, @@message_regex).map { Regexp.last_match }.each do |match|
15
13
  ch = @client.channels[match[:channel]]
16
14
  next if ch.nil?
17
15
 
@@ -27,7 +25,7 @@ module MessageExpander
27
25
  author: Discorb::Embed::Author.new(
28
26
  url_message.author.name,
29
27
  url: url_message.jump_url,
30
- icon: url_message.author.display_avatar.url,
28
+ icon: url_message.author.avatar.url,
31
29
  ),
32
30
  footer: Discorb::Embed::Footer.new(
33
31
  "#{url_message.guild.name} / #{ch.name}",
@@ -25,6 +25,7 @@ module Discorb
25
25
  # | `:type` | `Object` | Type of the option. |
26
26
  # | `:choice` | `Hash{String => String, Integer, Float}` | Type of the option. |
27
27
  # | `:default` | `Object` | Default value of the option. |
28
+ # | `:channel_types` | `Array<Class<Discorb::Channel>>` | Type of the channel option. |
28
29
  #
29
30
  # @param [Array<#to_s>, false, nil] guild_ids Guild IDs to set the command to. `false` to global command, `nil` to use default.
30
31
  # @param [Proc] block Command block.
@@ -238,6 +239,9 @@ module Discorb
238
239
  if value[:choices]
239
240
  ret[:choices] = value[:choices].map { |t| { name: t[0], value: t[1] } }
240
241
  end
242
+ if value[:channel_types]
243
+ ret[:channel_types] = value[:channel_types].map(&:channel_type)
244
+ end
241
245
  ret
242
246
  end
243
247
  {
@@ -52,6 +52,8 @@ module Discorb
52
52
  attr_reader :status
53
53
  # @return [Integer] The session ID of connection.
54
54
  attr_reader :session_id
55
+ # @return [Hash{String => Discorb::Extension}] The loaded extensions.
56
+ attr_reader :extensions
55
57
  # @private
56
58
  attr_reader :bottom_commands
57
59
 
@@ -97,6 +99,7 @@ module Discorb
97
99
  @status = :initialized
98
100
  @fetch_member = fetch_member
99
101
  @title = title
102
+ @extensions = {}
100
103
  set_default_events
101
104
  end
102
105
 
@@ -369,31 +372,38 @@ module Discorb
369
372
  #
370
373
  # Load the extension.
371
374
  #
372
- # @param [Module] mod The extension to load.
375
+ # @param [Class, Discorb::Extension] ext The extension to load.
376
+ # @param [Object] ... The arguments to pass to the `ext#initialize`.
373
377
  #
374
- def extend(mod)
375
- if mod.respond_to?(:events)
376
- @events.each_value do |event|
377
- event.delete_if { |c| c.metadata[:extension] == mod.name }
378
- end
379
- mod.events.each do |name, events|
380
- @events[name] ||= []
381
- @events[name].delete_if { |c| c.metadata[:override] }
382
- events.each do |event|
383
- @events[name] << event
384
- end
385
- end
386
- @commands.delete_if do |cmd|
387
- cmd.respond_to? :extension and cmd.extension == mod.name
388
- end
389
- mod.commands.each do |cmd|
390
- cmd.define_singleton_method(:extension) { mod.name }
391
- @commands << cmd
378
+ def load_extension(ext, ...)
379
+ if ext.is_a?(Class)
380
+ raise ArgumentError, "#{ext} is not a extension" unless ext < Discorb::Extension
381
+ ins = ext.new(self, ...)
382
+ elsif ext.is_a?(Discorb::Extension)
383
+ ins = ext
384
+ else
385
+ raise ArgumentError, "#{ext} is not a extension"
386
+ end
387
+
388
+ @events.each_value do |event|
389
+ event.delete_if { |c| c.metadata[:extension] == ins.class.name }
390
+ end
391
+ ins.events.each do |name, events|
392
+ @events[name] ||= []
393
+ events.each do |event|
394
+ @events[name] << event
392
395
  end
393
- @bottom_commands += mod.bottom_commands
394
- mod.client = self
395
396
  end
396
- super(mod)
397
+ @commands.delete_if do |cmd|
398
+ cmd.respond_to? :extension and cmd.extension == ins.name
399
+ end
400
+ ins.class.commands.each do |cmd|
401
+ cmd.define_singleton_method(:extension) { ins.name }
402
+ @commands << cmd
403
+ end
404
+ @bottom_commands += ins.class.bottom_commands
405
+ @extensions[ins.class.name] = ins
406
+ ins
397
407
  end
398
408
 
399
409
  include Discorb::Gateway::Handler
@@ -4,9 +4,9 @@ module Discorb
4
4
  # @return [String] The API base URL.
5
5
  API_BASE_URL = "https://discord.com/api/v9"
6
6
  # @return [String] The version of discorb.
7
- VERSION = "0.9.5"
7
+ VERSION = "0.10.2"
8
8
  # @return [String] The user agent for the bot.
9
- USER_AGENT = "DiscordBot (https://github.com/discorb-lib/discorb #{VERSION}) Ruby/#{RUBY_VERSION}"
9
+ USER_AGENT = "DiscordBot (https://discorb-lib.github.io #{VERSION}) Ruby/#{RUBY_VERSION}"
10
10
 
11
11
  #
12
12
  # @abstract
@@ -39,10 +39,11 @@ module Discorb
39
39
  # Represents Snowflake of Discord.
40
40
  #
41
41
  # @see https://discord.com/developers/docs/reference#snowflakes Official Discord API docs
42
- class Snowflake < DiscordModel
42
+ class Snowflake < String
43
43
  # @private
44
44
  def initialize(value)
45
45
  @value = value.to_i
46
+ super(@value.to_s)
46
47
  end
47
48
 
48
49
  # @!attribute [r] timestamp
@@ -64,26 +65,6 @@ module Discorb
64
65
  #
65
66
  # @return [Integer] Increment of snowflake.
66
67
 
67
- #
68
- # Stringify snowflake.
69
- #
70
- # @return [String] Stringified snowflake.
71
- #
72
- def to_s
73
- @value.to_s
74
- end
75
-
76
- alias to_str to_s
77
-
78
- #
79
- # Integerize snowflake.
80
- #
81
- # @return [Integer] Integerized snowflake.
82
- #
83
- def to_i
84
- @value.to_i
85
- end
86
-
87
68
  #
88
69
  # Compares snowflake with other object.
89
70
  #
@@ -36,6 +36,34 @@ module Discorb
36
36
  )
37
37
  end
38
38
  end
39
+
40
+ #
41
+ # Convert components to a hash.
42
+ #
43
+ # @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components Components.
44
+ #
45
+ # @return [Array<Hash>] Hash data.
46
+ #
47
+ def to_payload(components)
48
+ tmp_components = []
49
+ tmp_row = []
50
+ components.each do |c|
51
+ case c
52
+ when Array
53
+ tmp_components << tmp_row
54
+ tmp_row = []
55
+ tmp_components << c
56
+ when SelectMenu
57
+ tmp_components << tmp_row
58
+ tmp_row = []
59
+ tmp_components << [c]
60
+ else
61
+ tmp_row << c
62
+ end
63
+ end
64
+ tmp_components << tmp_row
65
+ return tmp_components.filter { |c| c.length.positive? }.map { |c| { type: 1, components: c.map(&:to_hash) } }
66
+ end
39
67
  end
40
68
  end
41
69
 
@@ -152,7 +180,7 @@ module Discorb
152
180
  # @return [Integer] The maximum number of values.
153
181
  attr_accessor :max_values
154
182
  # @return [Boolean] Whether the select menu is disabled.
155
- attr_reader :disabled
183
+ attr_accessor :disabled
156
184
  alias disabled? disabled
157
185
 
158
186
  #
@@ -178,7 +178,7 @@ end
178
178
  opt = OptionParser.new <<~BANNER
179
179
  A tool to make a new project.
180
180
 
181
- Usage: discorb init [options] [dir]
181
+ Usage: discorb new [options] [dir]
182
182
 
183
183
  dir The directory to make the files in.
184
184
  BANNER
@@ -22,6 +22,7 @@ options = {
22
22
  log_color: nil,
23
23
  setup: nil,
24
24
  token: false,
25
+ bundler: :default,
25
26
  }
26
27
  opt.on("-l", "--log-level LEVEL", "Log level.") do |v|
27
28
  unless LOG_LEVELS.include? v.downcase
@@ -36,6 +37,7 @@ opt.on("-c", "--[no-]log-color", "Whether to colorize log output.") { |v| option
36
37
  opt.on("-s", "--setup", "Whether to setup application commands.") { |v| options[:setup] = v }
37
38
  opt.on("-e", "--env [ENV]", "The name of the environment variable to use for token, or just `-e` or `--env` for intractive prompt.") { |v| options[:token] = v }
38
39
  opt.on("-t", "--title TITLE", "The title of process.") { |v| options[:title] = v }
40
+ opt.on("-b", "--[no-]bundler", "Whether to use bundler. Default to true if Gemfile exists, otherwise false.") { |v| options[:bundler] = v }
39
41
  opt.parse!(ARGV)
40
42
 
41
43
  script = ARGV[0]
@@ -54,10 +56,25 @@ elsif options[:token].nil? || options[:token] == "-"
54
56
  puts ""
55
57
  end
56
58
 
59
+ if options[:bundler] == :default
60
+ dir = Dir.pwd.split("/")
61
+ options[:bundler] = false
62
+ dir.length.times.reverse_each do |i|
63
+ if File.exist? "#{dir[0..i].join("/")}/Gemfile"
64
+ options[:bundler] = true
65
+ break
66
+ end
67
+ end
68
+ end
69
+
57
70
  ENV["DISCORB_CLI_TITLE"] = options[:title]
58
71
 
59
- begin
60
- load script
61
- rescue LoadError
72
+ if File.exist? script
73
+ if options[:bundler]
74
+ system "bundle exec ruby #{script}"
75
+ else
76
+ system "ruby #{script}"
77
+ end
78
+ else
62
79
  eputs "Could not load script: \e[31m#{script}\e[91m"
63
80
  end
@@ -2,65 +2,78 @@
2
2
 
3
3
  module Discorb
4
4
  #
5
- # Module to make extension.
6
- # extend this module to make your own extension.
5
+ # Abstract class to make extension.
6
+ # Inherit from this class to make your own extension.
7
7
  # @see file:docs/extension.md
8
8
  # @abstract
9
9
  #
10
- module Extension
11
- include Discorb::ApplicationCommand::Handler
12
- undef setup_commands
10
+ class Extension
11
+ extend Discorb::ApplicationCommand::Handler
13
12
 
14
13
  @events = {}
15
- @client = nil
16
14
 
17
- #
18
- # Define a new event.
19
- #
20
- # @param [Symbol] event_name The name of the event.
21
- # @param [Symbol] id The id of the event. Used to delete the event.
22
- # @param [Hash] metadata Other metadata.
23
- # @param [Proc] block The block to execute when the event is triggered.
24
- #
25
- # @return [Discorb::Event] The event.
26
- #
27
- def event(event_name, id: nil, **metadata, &block)
28
- raise ArgumentError, "Event name must be a symbol" unless event_name.is_a?(Symbol)
29
- raise ArgumentError, "block must be a Proc" unless block.is_a?(Proc)
30
-
31
- @events[event_name] ||= []
32
- metadata[:extension] = self.name
33
- @events[event_name] << Discorb::Event.new(block, id, metadata)
15
+ def initialize(client)
16
+ @client = client
34
17
  end
35
18
 
36
- #
37
- # Define a new once event.
38
- #
39
- # @param [Symbol] event_name The name of the event.
40
- # @param [Symbol] id The id of the event. Used to delete the event.
41
- # @param [Hash] metadata Other metadata.
42
- # @param [Proc] block The block to execute when the event is triggered.
43
- #
44
- # @return [Discorb::Event] The event.
45
- #
46
- def once_event(event_name, id: nil, **metadata, &block)
47
- event(event_name, id: id, once: true, **metadata, &block)
19
+ def events
20
+ return @events if @events
21
+ ret = {}
22
+ self.class.events.each do |event, handlers|
23
+ ret[event] = handlers.map do |handler|
24
+ Discorb::Event.new(Proc.new { |*args, **kwargs| instance_exec(*args, **kwargs, &handler[2]) }, handler[0], handler[1])
25
+ end
26
+ end
27
+ @events = ret
48
28
  end
49
29
 
50
- # @return [Hash{Symbol => Array<Discorb::Event>}] The events of the extension.
51
- attr_reader :events
52
- # @return [Array<Discorb::ApplicationCommand::Command>] The commands of the extension.
53
- attr_reader :commands
54
- # @private
55
- attr_reader :bottom_commands
30
+ class << self
31
+ undef setup_commands
32
+
33
+ #
34
+ # Define a new event.
35
+ #
36
+ # @param [Symbol] event_name The name of the event.
37
+ # @param [Symbol] id The id of the event. Used to delete the event.
38
+ # @param [Hash] metadata Other metadata.
39
+ #
40
+ # @return [Discorb::Event] The event.
41
+ #
42
+ def event(event_name, id: nil, **metadata, &block)
43
+ raise ArgumentError, "Event name must be a symbol" unless event_name.is_a?(Symbol)
44
+ raise ArgumentError, "block must be given" unless block_given?
45
+
46
+ @events[event_name] ||= []
47
+ metadata[:extension] = self.name
48
+ @events[event_name] << [id, metadata, block]
49
+ end
50
+
51
+ #
52
+ # Define a new once event.
53
+ #
54
+ # @param [Symbol] event_name The name of the event.
55
+ # @param [Symbol] id The id of the event. Used to delete the event.
56
+ # @param [Hash] metadata Other metadata.
57
+ # @param [Proc] block The block to execute when the event is triggered.
58
+ #
59
+ # @return [Discorb::Event] The event.
60
+ #
61
+ def once_event(event_name, id: nil, **metadata, &block)
62
+ event(event_name, id: id, once: true, **metadata, &block)
63
+ end
56
64
 
57
- # @private
58
- attr_accessor :client
65
+ # @return [Hash{Symbol => Array<Discorb::Event>}] The events of the extension.
66
+ attr_reader :events
67
+ # @return [Array<Discorb::ApplicationCommand::Command>] The commands of the extension.
68
+ attr_reader :commands
69
+ # @private
70
+ attr_reader :bottom_commands
59
71
 
60
- def self.extended(obj)
61
- obj.instance_variable_set(:@events, {})
62
- obj.instance_variable_set(:@commands, [])
63
- obj.instance_variable_set(:@bottom_commands, [])
72
+ def inherited(klass)
73
+ klass.instance_variable_set(:@commands, [])
74
+ klass.instance_variable_set(:@bottom_commands, [])
75
+ klass.instance_variable_set(:@events, {})
76
+ end
64
77
  end
65
78
  end
66
79
  end
@@ -255,7 +255,7 @@ module Discorb
255
255
  def defer_update(ephemeral: false)
256
256
  Async do
257
257
  @client.http.post("/interactions/#{@id}/#{@token}/callback", {
258
- type: 7,
258
+ type: 6,
259
259
  data: {
260
260
  flags: (ephemeral ? 1 << 6 : 0),
261
261
  },
@@ -310,7 +310,7 @@ module Discorb
310
310
  payload[:components] = tmp_components.filter { |c| c.length.positive? }.map { |c| { type: 1, components: c.map(&:to_hash) } }
311
311
  end
312
312
  payload[:flags] = (ephemeral ? 1 << 6 : 0)
313
- @client.http.post("/interactions/#{@id}/#{@token}/callback", { type: 6, data: payload }).wait
313
+ @client.http.post("/interactions/#{@id}/#{@token}/callback", { type: 7, data: payload }).wait
314
314
  end
315
315
  end
316
316
  end
@@ -460,6 +460,8 @@ module Discorb
460
460
  include Interaction::UpdateResponse
461
461
  # @return [String] The content of the response.
462
462
  attr_reader :custom_id
463
+ # @return [Discorb::Message] The target message.
464
+ attr_reader :message
463
465
 
464
466
  @interaction_type = 3
465
467
  @interaction_name = :message_component
@@ -37,26 +37,7 @@ module Discorb
37
37
  payload[:allowed_mentions] =
38
38
  allowed_mentions ? allowed_mentions.to_hash(@client.allowed_mentions) : @client.allowed_mentions.to_hash
39
39
  payload[:message_reference] = reference.to_reference if reference
40
- if components
41
- tmp_components = []
42
- tmp_row = []
43
- components.each do |c|
44
- case c
45
- when Array
46
- tmp_components << tmp_row
47
- tmp_row = []
48
- tmp_components << c
49
- when SelectMenu
50
- tmp_components << tmp_row
51
- tmp_row = []
52
- tmp_components << [c]
53
- else
54
- tmp_row << c
55
- end
56
- end
57
- tmp_components << tmp_row
58
- payload[:components] = tmp_components.filter { |c| c.length.positive? }.map { |c| { type: 1, components: c.map(&:to_hash) } }
59
- end
40
+ payload[:components] = Component.to_payload(components) if components
60
41
  files = [file] if file
61
42
  if files
62
43
  seperator, payload = HTTP.multipart(payload, files)
@@ -69,6 +50,8 @@ module Discorb
69
50
  end
70
51
  end
71
52
 
53
+ alias send_message post
54
+
72
55
  #
73
56
  # Edit a message.
74
57
  # @macro async
@@ -95,27 +78,8 @@ module Discorb
95
78
  payload[:embeds] = tmp_embed.map(&:to_hash) if tmp_embed
96
79
  payload[:allowed_mentions] =
97
80
  allowed_mentions ? allowed_mentions.to_hash(@client.allowed_mentions) : @client.allowed_mentions.to_hash
98
- if components
99
- tmp_components = []
100
- tmp_row = []
101
- components.each do |c|
102
- case c
103
- when Array
104
- tmp_components << tmp_row
105
- tmp_row = []
106
- tmp_components << c
107
- when SelectMenu
108
- tmp_components << tmp_row
109
- tmp_row = []
110
- tmp_components << [c]
111
- else
112
- tmp_row << c
113
- end
114
- end
115
- tmp_components << tmp_row
116
- payload[:flags] = (supress ? 1 << 2 : 0) unless supress.nil?
117
- payload[:components] = tmp_components.filter { |c| c.length.positive? }.map { |c| { type: 1, components: c.map(&:to_hash) } }
118
- end
81
+ payload[:components] = Component.to_payload(components) if components
82
+ payload[:flags] = (supress ? 1 << 2 : 0) unless supress.nil?
119
83
  @client.http.patch("/channels/#{channel_id.wait}/messages/#{message_id}", payload).wait
120
84
  end
121
85
  end
@@ -527,6 +527,7 @@ dd pre.code {
527
527
  padding: 9px 14px;
528
528
  border-radius: 4px;
529
529
  border: 1px solid var(--background-tertiary);
530
+ overflow-x: scroll;
530
531
  }
531
532
 
532
533
  #main {
@@ -4,21 +4,41 @@ def build_version_sidebar(dir, version)
4
4
  raw.gsub!(template, "")
5
5
  res = +""
6
6
  i = 0
7
- `git tag`.force_encoding("utf-8").split("\n").each.with_index do |tag|
7
+ `git tag`
8
+ .force_encoding("utf-8")
9
+ .split("\n")
10
+ .sort_by { |v| Gem::Version.new(v[1..]) }
11
+ .reverse
12
+ .each.with_index do |tag|
8
13
  i += 1
9
14
  sha = `git rev-parse #{tag}`.force_encoding("utf-8").strip
10
- version = tag.delete_prefix("v")
15
+ tag_version = tag.delete_prefix("v")
11
16
  cls = i % 2 == 0 ? "even" : "odd"
12
- if version == "."
17
+ if tag_version == version
13
18
  cls += " current"
14
19
  end
15
- res += template.gsub("!version!", version).gsub("!path!", "../" + version).gsub("!class!", cls).gsub("!sha!", sha)
20
+ res += template
21
+ .gsub("!version!", tag_version)
22
+ .gsub("!path!", "/" + tag_version)
23
+ .gsub("!class!", cls)
24
+ .gsub("!sha!", sha)
16
25
  end
17
26
  i += 1
18
27
  cls = i % 2 == 0 ? "even" : "odd"
19
28
  if version == "main"
20
29
  cls += " current"
21
30
  end
22
- res += template.gsub("!version!", "main").gsub("!path!", "../main").gsub("!class!", cls).gsub("!sha!", "(Latest on GitHub)")
31
+ res.insert 0, template
32
+ .gsub("!version!", "main")
33
+ .gsub("!path!", "/main")
34
+ .gsub("!class!", cls)
35
+ .gsub("!sha!", "Latest on GitHub")
36
+ i += 1
37
+ cls = i % 2 == 0 ? "even" : "odd"
38
+ res.insert 0, template
39
+ .gsub("!version!", "Latest")
40
+ .gsub("!path!", "")
41
+ .gsub("!class!", cls)
42
+ .gsub("!sha!", "Latest on RubyGems")
23
43
  File.write(dir + "/version_list.html", raw.gsub("<!--replace-->", res))
24
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discorb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - sevenc-nanashi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-28 00:00:00.000000000 Z
11
+ date: 2021-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -142,8 +142,8 @@ files:
142
142
  - lib/discorb/error.rb
143
143
  - lib/discorb/event.rb
144
144
  - lib/discorb/exe/about.rb
145
- - lib/discorb/exe/init.rb
146
145
  - lib/discorb/exe/irb.rb
146
+ - lib/discorb/exe/new.rb
147
147
  - lib/discorb/exe/run.rb
148
148
  - lib/discorb/exe/setup.rb
149
149
  - lib/discorb/exe/show.rb