discorb 0.9.6 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82c013d06e2f831b3d0bac635ca13eeea99fe5b248a04e4879bb5f0a17374b90
4
- data.tar.gz: bf9d0ea7d1f84696d03e705edbcf8e78ee80b87ab393a06b6d7c5abee6d7fcb5
3
+ metadata.gz: d1b87a672806fd34b5a1a3308bd96db493c13a645a2f4ae7cd6a3b9622cf7a01
4
+ data.tar.gz: fc1b8e0b433489e1390b958b7b4ebeb9c39c1f2d38ff80c05334dda5f19f3bd8
5
5
  SHA512:
6
- metadata.gz: '08088483e41f563e1458cef68132c6f0d98c9ff2d99f319ff80dbd4d242b0248567b0e4114d48bd07fcf942179b76ac480217b2bfb82da7a9d957ace5b1ef83c'
7
- data.tar.gz: 95995caa4ca9ac2d8a6388660afcf10e0928b59347fb4fc5656324fd0917bf80506c6ceb42545b76196ab988e3d3ad62d9449a15cfa57acad85c02e42cbc9294
6
+ metadata.gz: 4c666466d4c10d93e974ecd843d14d9e92b424c18e6fab784dba54ff8c0caf9c5f54feaaa7c03e32f640a237af4ee6795e653691035c3e80e3c7a4af79740143
7
+ data.tar.gz: 344ecd871e7c1e98a1ad2b68f75f988ee2aabfbe78e24ecf4e8a58da069e04b8e3327f5348414c33a619381c520ea7dbb4fb173cbea6fa153cb2dd5b07b9f9e2
data/Changelog.md CHANGED
@@ -1,266 +1,298 @@
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
261
-
262
- ## 0.9.6
263
-
264
- - Add: Add `Messageable#send_message` as alias of `Messageable#post`
265
- - Fix: Fix interaction responding with updating message
266
- - Fix: Fix `MessageComponentInteraction#message`
1
+ # @title Changelog
2
+
3
+ # Changelog
4
+
5
+ ## v0.10
6
+
7
+ ### v0.10.0
8
+
9
+ - Change: Sort versions
10
+ - Change: Snowflake is now String
11
+ - Change: Extension is now Class
12
+ - Add: Add `SelectMenu#disabled=`
13
+
14
+ ## v0.9
15
+
16
+ ### v0.9.6
17
+
18
+ - Add: Add `Messageable#send_message` as alias of `Messageable#post`
19
+ - Fix: Fix interaction responding with updating message
20
+ - Fix: Fix `MessageComponentInteraction#message`
21
+
22
+ ### v0.9.5
23
+
24
+ - Fix: Fix editing message
25
+ - Add: Add `required` in slash command argument
26
+ - Add: Add `default` in slash command argument
27
+
28
+ ### v0.9.4
29
+
30
+ - Change: `Messageable#typing` with block is now synchronous
31
+ - Fix: Fix some issues in document
32
+ - Add: Add some attributes to `Message`
33
+ - Fix: Fix guild parameter in message of message command
34
+
35
+ ### v0.9.3
36
+
37
+ - Fix: Fix interaction responding
38
+
39
+ ### v0.9.2 (yanked)
40
+
41
+ - Add: Make `Async::Task#inspect` shorter
42
+ - Add: `SourceResponse#post` will return message now
43
+ - Fix: Fix member caching
44
+
45
+ ### v0.9.1
46
+
47
+ - Fix: Fix member fetching
48
+
49
+ ### v0.9.0
50
+
51
+ - Delete: Delete `-d` parameter from `discorb run`; This is caused by segement fault error.
52
+ - Change: Rename `-t`, `--token` to `-e`, `--env` parameter
53
+ - Add: Add `-t`, `--title` parameter to `discorb run`
54
+ - Add: Add `title` parameter to `Client#initialize`
55
+
56
+ ## v0.8
57
+
58
+ ### v0.8.2
59
+
60
+ - Fix: Fix `Client#initialize`
61
+
62
+ ### v0.8.1
63
+
64
+ - Add: Add FAQ
65
+ - Fix: Fix sending files
66
+ - Add: Add `File.from_string`
67
+ - Fix: Fix `Client#update_presence`
68
+ - Add: Add information in `discorb run -d`
69
+
70
+ ### v0.8.0
71
+
72
+ - Add: Add `Guild#fetch_members`
73
+ - Add: Add `Guild#fetch_member_list` as alias of `Guild#fetch_members`
74
+ - Add: Add `Intents#to_h`
75
+ - Add: Add `fetch_member` parameter to `Client#initialize`; Note you should set `false` if your bot doesn't have `GUILD_MEMBERS` intent
76
+ - Change: Change `ready` to `standby` event
77
+ - Change: `ready` will be fired when client receives `READY` event
78
+
79
+ ## v0.7
80
+
81
+ ### v0.7.6
82
+
83
+ - Fix: Fix heartbeating error
84
+
85
+ ### v0.7.5 (yanked)
86
+
87
+ - Fix: Fix critical error
88
+
89
+ ### v0.7.4 (yanked)
90
+
91
+ - Fix: Fix disconnected client
92
+
93
+ ### v0.7.3
94
+
95
+ - Add: Improve `discorb init`
96
+
97
+ ### v0.7.2
98
+
99
+ - Add: Add `Member#owner?`
100
+ - Fix: Fix `Member#permissions`
101
+ - Add: Add `Member#guild_permissions` as alias of `Member#permissions`
102
+ - Add: Add default role to `Member#roles`
103
+ - Fix: Fix error in `Integration#_set_data`
104
+ - Change: Reverse `Member#roles`
105
+
106
+ ### v0.7.1
107
+
108
+ - Fix: Fix error of responding to interaction
109
+
110
+ ### v0.7.0
111
+
112
+ - Add: Add `error` event
113
+ - Fix: Fix some issues with client without guild intent
114
+ - Add: Add alias for `#fired_by`
115
+ - Change!: Change block usage of `ApplicationCommand::Handler#group`
116
+
117
+ ```ruby
118
+ # before
119
+ client.slash_group do
120
+ slash "help", "Help" do |interaction|
121
+ # ...
122
+ end
123
+ end
124
+
125
+ # after
126
+ client.slash_group do |group|
127
+ group.slash "help", "Help" do |interaction|
128
+ # ...
129
+ end
130
+ end
131
+
132
+ ```
133
+
134
+ ## v0.6
135
+
136
+ ### v0.6.1
137
+
138
+ - Change: Rename `Event#discriminator` to `Event#metadata`
139
+ - Add: Add `:override` to `Client#on`
140
+
141
+ ### v0.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
+ ## v0.5
150
+
151
+ ### v0.5.6
152
+
153
+ - Add: Raise error when intents are invalid
154
+ - Fix: Fix Emoji#==
155
+
156
+ ### v0.5.5
157
+
158
+ - Fix: Fix some bugs
159
+
160
+ ### v0.5.4
161
+
162
+ - Fix: Fix issue of receiving component events
163
+
164
+ ### v0.5.3
165
+
166
+ - Add: Add way to handle raw events with `event_xxx`
167
+ - Add: Add `Client#session_id`
168
+ - Add: Add `Connectable`
169
+ - Fix: Fix error by sending DM
170
+
171
+ ### v0.5.2
172
+
173
+ - Fix: Fix bug of registering commands
174
+ - Add: Add way to register commands in Extension
175
+
176
+ ### v0.5.1
177
+
178
+ - Add: Can use block for defining group commands
179
+ - Fix: Fix bug in subcommands
180
+ - Fix: Fix bug in receiving commands
181
+
182
+ ### v0.5.0
183
+
184
+ - Change: Use zlib stream instead
185
+ - Add: Add tutorials
186
+ - Add: Add ratelimit handler
187
+ - Change: Make `--git` option in `discorb init` false
188
+
189
+ ## v0.4
190
+
191
+ ### v0.4.2
192
+
193
+ - Fix: Fix error in `discorb run`
194
+
195
+ ### v0.4.1
196
+
197
+ - Add: Add `-s` option to `discorb run`
198
+
199
+ ### v0.4.0
200
+
201
+ - Add: Add `discorb setup`
202
+ - Add: Add `discorb run`
203
+ - Add: Add realtime documentation
204
+
205
+ ## v0.3
206
+
207
+ ### v0.3.1
208
+
209
+ - Add: Add `discorb show`
210
+ - Fix: Fix documenting
211
+
212
+ ### v0.3.0
213
+
214
+ - Add: Improve CLI tools
215
+ - Add: Add `discorb init`
216
+ - Change: Change `discord-irb` to `discorb irb`
217
+
218
+ ## v0.2
219
+
220
+ ### v0.2.5
221
+
222
+ - Add: Add way to add event listener
223
+ - Change: Move document to https://discorb-lib.github.io/
224
+
225
+ ### v0.2.4
226
+
227
+ - Fix: Fix error in `Embed#image=`, `Embed#thumbnail=`
228
+
229
+ ### v0.2.3
230
+
231
+ - Fix: Fix critical error
232
+
233
+ ### v0.2.2 (yanked)
234
+
235
+ - Add: Add `Snowflake#to_str`
236
+
237
+ ### v0.2.1
238
+
239
+ - Fix: Fix NoMethodError in reaction event
240
+ - Add: Add Changelog.md to document
241
+
242
+ ### v0.2.0
243
+
244
+ - Fix: Fix unused dependency
245
+ - Add: Add `Client#close!`
246
+ - Add: Add discord-irb
247
+
248
+ ## v0.1
249
+
250
+ ### v0.1.0
251
+
252
+ - Add: Add `User#created_at`
253
+ - Add: Add `Member#to_s_user`
254
+ - Add: Add `DefaultAvatar`
255
+ - Add: Support application commands
256
+ - Add: Add `Client#ping`
257
+ - Add: Allow `String` for `Embed#initialize`
258
+ - Change: Change log format
259
+
260
+ ## v0.0
261
+
262
+ ### v0.0.8
263
+
264
+ - Delete: Delete task parameter
265
+
266
+ ### v0.0.7
267
+
268
+ - Fix: Fix `member_xxx` event
269
+
270
+ ### v0.0.6
271
+
272
+ - Fix: Fix error in client without members intent
273
+ - Add: Add ThreadChannel::News
274
+ - Add: Add official discord link
275
+
276
+ ### v0.0.5
277
+
278
+ - Fix: Fix GitHub link
279
+ - Change: Internet to HTTP
280
+
281
+ ### v0.0.4
282
+
283
+ - Fix: Fix NoMethodError by webhook message
284
+ - Add: Add `#author` to webhook message
285
+ - Fix: Add `#bot?` to webhook author
286
+
287
+ ### v0.0.3
288
+
289
+ - Fix: Fix no dependencies
290
+
291
+ ### v0.0.2
292
+
293
+ - Fix: Fix rubygems description
294
+
295
+ ### v0.0.1
296
+
297
+ - Initial release
298
+
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
+ ----
@@ -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}",
@@ -369,31 +369,30 @@ module Discorb
369
369
  #
370
370
  # Load the extension.
371
371
  #
372
- # @param [Module] mod The extension to load.
373
- #
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
372
+ # @param [Class] ext The extension to load.
373
+ # @param [Object] ... The arguments to pass to the `ext#initialize`.
374
+ #
375
+ def load_extension(ext, ...)
376
+ raise ArgumentError, "#{ext} is not a extension" unless ext.is_a?(Class) && ext < Discorb::Extension
377
+ ins = ext.new(self, ...)
378
+ @events.each_value do |event|
379
+ event.delete_if { |c| c.metadata[:extension] == ins.class.name }
380
+ end
381
+ ins.events.each do |name, events|
382
+ @events[name] ||= []
383
+ events.each do |event|
384
+ @events[name] << event
392
385
  end
393
- @bottom_commands += mod.bottom_commands
394
- mod.client = self
395
386
  end
396
- super(mod)
387
+ @commands.delete_if do |cmd|
388
+ cmd.respond_to? :extension and cmd.extension == ins.name
389
+ end
390
+ ins.class.commands.each do |cmd|
391
+ cmd.define_singleton_method(:extension) { ins.name }
392
+ @commands << cmd
393
+ end
394
+ @bottom_commands += ins.class.bottom_commands
395
+ ins
397
396
  end
398
397
 
399
398
  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.6"
7
+ VERSION = "0.10.0"
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
  #
@@ -180,7 +180,7 @@ module Discorb
180
180
  # @return [Integer] The maximum number of values.
181
181
  attr_accessor :max_values
182
182
  # @return [Boolean] Whether the select menu is disabled.
183
- attr_reader :disabled
183
+ attr_accessor :disabled
184
184
  alias disabled? disabled
185
185
 
186
186
  #
@@ -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
@@ -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,36 @@ 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`.force_encoding("utf-8").split("\n").reverse.each.with_index do |tag|
8
8
  i += 1
9
9
  sha = `git rev-parse #{tag}`.force_encoding("utf-8").strip
10
- version = tag.delete_prefix("v")
10
+ tag_version = tag.delete_prefix("v")
11
11
  cls = i % 2 == 0 ? "even" : "odd"
12
- if version == "."
12
+ if tag_version == version
13
13
  cls += " current"
14
14
  end
15
- res += template.gsub("!version!", version).gsub("!path!", "../" + version).gsub("!class!", cls).gsub("!sha!", sha)
15
+ res += template
16
+ .gsub("!version!", tag_version)
17
+ .gsub("!path!", "/" + tag_version)
18
+ .gsub("!class!", cls)
19
+ .gsub("!sha!", sha)
16
20
  end
17
21
  i += 1
18
22
  cls = i % 2 == 0 ? "even" : "odd"
19
23
  if version == "main"
20
24
  cls += " current"
21
25
  end
22
- res += template.gsub("!version!", "main").gsub("!path!", "../main").gsub("!class!", cls).gsub("!sha!", "(Latest on GitHub)")
26
+ res.insert 0, template
27
+ .gsub("!version!", "main")
28
+ .gsub("!path!", "/main")
29
+ .gsub("!class!", cls)
30
+ .gsub("!sha!", "Latest on GitHub")
31
+ i += 1
32
+ cls = i % 2 == 0 ? "even" : "odd"
33
+ res.insert 0, template
34
+ .gsub("!version!", "Latest")
35
+ .gsub("!path!", "/")
36
+ .gsub("!class!", cls)
37
+ .gsub("!sha!", "Latest on RubyGems")
23
38
  File.write(dir + "/version_list.html", raw.gsub("<!--replace-->", res))
24
39
  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.6
4
+ version: 0.10.0
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-29 00:00:00.000000000 Z
11
+ date: 2021-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async