discorb 0.2.4 → 0.2.5
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/.gitignore +2 -1
- data/.yardopts +1 -0
- data/Changelog.md +10 -1
- data/Gemfile +17 -17
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/Rakefile +159 -46
- data/crowdin.yml +3 -0
- data/discorb.gemspec +1 -0
- data/docs/application_command.md +6 -6
- data/docs/discord_irb.md +1 -1
- data/docs/events.md +21 -7
- data/docs/extension.md +15 -3
- data/examples/commands/inspect.rb +1 -1
- data/lib/discorb/client.rb +15 -3
- data/lib/discorb/color.rb +1 -0
- data/lib/discorb/common.rb +1 -1
- data/lib/discorb/image.rb +1 -4
- data/lib/discorb/interaction.rb +6 -1
- data/lib/discorb/message.rb +4 -2
- data/lib/discorb/permission.rb +3 -0
- data/po/yard.pot +12452 -0
- data/template-replace/files/css/common.css +519 -0
- data/template-replace/resources/version_list.html +61 -0
- data/template-replace/scripts/index.rb +13 -0
- data/template-replace/scripts/sidebar.rb +11 -0
- data/template-replace/scripts/version.rb +12 -0
- data/template-replace/scripts/yard_replace.rb +27 -0
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e27fc8b1d9e527f2ce007c686025f4edc9ca7ee8dda06df91ff48a02034a1dbf
|
4
|
+
data.tar.gz: 7708d124bd2921941164e178c35714b3cf7d68f19b202a823bc9913688c35495
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b4d553c7fe030956205058581ed1685a73fcdc1034c250e1c09ca29ef52637d8b85b10bb19edc93d334f0782e7b9a4d4fe4e88976d1f1174286e5f72ca866bb
|
7
|
+
data.tar.gz: bc6ec15cb5c3592df82e5af2682f690a5ee6649e8a1cf957786bf0886f3b0c3ad76ab6241b606d52380d47b3ccd17f4c7cda71b62b98198ce3470180ec07c753
|
data/.gitignore
CHANGED
data/.yardopts
CHANGED
data/Changelog.md
CHANGED
@@ -64,4 +64,13 @@
|
|
64
64
|
|
65
65
|
## 0.2.3
|
66
66
|
|
67
|
-
- Fix: Fix critical error
|
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/
|
data/Gemfile
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
# Specify your gem's dependencies in discorb.gemspec
|
6
|
-
gemspec
|
7
|
-
|
8
|
-
gem "rake", "~> 13.0"
|
9
|
-
|
10
|
-
group :debug, optional: true do
|
11
|
-
gem "rufo", "~> 0.13.0"
|
12
|
-
end
|
13
|
-
|
14
|
-
group :docs, optional: true do
|
15
|
-
gem "redcarpet"
|
16
|
-
gem "yard", "~> 0.9.26"
|
17
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in discorb.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "rake", "~> 13.0"
|
9
|
+
|
10
|
+
group :debug, optional: true do
|
11
|
+
gem "rufo", "~> 0.13.0"
|
12
|
+
end
|
13
|
+
|
14
|
+
group :docs, optional: true do
|
15
|
+
gem "redcarpet"
|
16
|
+
gem "yard", "~> 0.9.26"
|
17
|
+
end
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# discorb
|
2
|
-
[](https://discorb-lib.github.io/)
|
3
3
|
[](https://rubygems.org/gems/discorb)
|
4
4
|
[](https://rubygems.org/gems/discorb)
|
5
5
|
[](https://discord.gg/hCP6zq8Vpj)
|
data/Rakefile
CHANGED
@@ -1,46 +1,159 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "bundler/gem_tasks"
|
4
|
-
task default: %i[]
|
5
|
-
|
6
|
-
|
7
|
-
require_relative "lib/discorb"
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
46
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
task default: %i[]
|
5
|
+
|
6
|
+
def get_version
|
7
|
+
require_relative "lib/discorb/common"
|
8
|
+
latest_commit = `git log --oneline`.force_encoding("utf-8").split("\n")[0]
|
9
|
+
version = Discorb::VERSION
|
10
|
+
unless latest_commit.downcase.include?("update version")
|
11
|
+
version += "-dev"
|
12
|
+
end
|
13
|
+
version
|
14
|
+
end
|
15
|
+
|
16
|
+
def gputs(text)
|
17
|
+
puts "\e[90m#{text}\e[m"
|
18
|
+
end
|
19
|
+
|
20
|
+
def sputs(text)
|
21
|
+
puts "\e[92m#{text}\e[m"
|
22
|
+
end
|
23
|
+
|
24
|
+
task :emoji_table do
|
25
|
+
require_relative "lib/discorb"
|
26
|
+
|
27
|
+
gputs "Building emoji_table.rb"
|
28
|
+
res = {}
|
29
|
+
Discorb::EmojiTable::DISCORD_TO_UNICODE.each do |discord, unicode|
|
30
|
+
res[unicode] ||= []
|
31
|
+
res[unicode] << discord
|
32
|
+
end
|
33
|
+
|
34
|
+
res_text = +""
|
35
|
+
res.each do |unicode, discord|
|
36
|
+
res_text << %(#{unicode.unpack("C*").pack("C*").inspect} => %w[#{discord.join(" ")}],\n)
|
37
|
+
end
|
38
|
+
|
39
|
+
table_script = File.read("lib/discorb/emoji_table.rb")
|
40
|
+
|
41
|
+
table_script.gsub!(/(?<=UNICODE_TO_DISCORD = {\n)[\s\S]+(?=}\.freeze)/, res_text)
|
42
|
+
|
43
|
+
File.open("lib/discorb/emoji_table.rb", "w") do |f|
|
44
|
+
f.print(table_script)
|
45
|
+
end
|
46
|
+
`rufo lib/discorb/emoji_table.rb`
|
47
|
+
sputs "Successfully made emoji_table.rb"
|
48
|
+
end
|
49
|
+
|
50
|
+
task :format do
|
51
|
+
Dir.glob("**/*.rb").each do |file|
|
52
|
+
next if file.start_with?("vendor")
|
53
|
+
|
54
|
+
gputs "Formatting #{file}"
|
55
|
+
`rufo ./#{file}`
|
56
|
+
content = ""
|
57
|
+
File.open(file, "rb") do |f|
|
58
|
+
content = f.read
|
59
|
+
end
|
60
|
+
content.gsub!("\r\n", "\n")
|
61
|
+
File.open(file, "wb") do |f|
|
62
|
+
f.print(content)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
namespace :document do
|
67
|
+
version = get_version
|
68
|
+
task :yard do
|
69
|
+
sh "yardoc -o doc/#{version}"
|
70
|
+
end
|
71
|
+
namespace :replace do
|
72
|
+
require "fileutils"
|
73
|
+
task :css do
|
74
|
+
gputs "Replacing css"
|
75
|
+
Dir.glob("template-replace/files/**/*.*")
|
76
|
+
.map { |f| f.delete_prefix("template-replace/files") }.each do |file|
|
77
|
+
FileUtils.cp("template-replace/files" + file, "doc/#{version}/#{file}")
|
78
|
+
end
|
79
|
+
sputs "Successfully replaced css"
|
80
|
+
end
|
81
|
+
task :html do
|
82
|
+
require_relative "template-replace/scripts/sidebar.rb"
|
83
|
+
require_relative "template-replace/scripts/version.rb"
|
84
|
+
require_relative "template-replace/scripts/index.rb"
|
85
|
+
require_relative "template-replace/scripts/yard_replace.rb"
|
86
|
+
gputs "Resetting changes"
|
87
|
+
Dir.glob("doc/#{version}/**/*.html") do |f|
|
88
|
+
next if (m = f.match(/[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+)?/)) && m[0] != version
|
89
|
+
|
90
|
+
content = File.read(f)
|
91
|
+
content.gsub!(/<!--od-->[\s\S]*<!--eod-->/, "")
|
92
|
+
File.write(f, content)
|
93
|
+
end
|
94
|
+
gputs "Adding version tab"
|
95
|
+
%w[file_list class_list method_list].each do |f|
|
96
|
+
replace_sidebar("doc/#{version}/#{f}.html")
|
97
|
+
end
|
98
|
+
|
99
|
+
gputs "Building version tab"
|
100
|
+
build_version_sidebar("doc/#{version}")
|
101
|
+
gputs "Replacing _index.html"
|
102
|
+
replace_index("doc/#{version}", version)
|
103
|
+
gputs "Replacing YARD credits"
|
104
|
+
yard_replace("doc/#{version}", version)
|
105
|
+
gputs "Successfully replaced htmls"
|
106
|
+
end
|
107
|
+
task :eol do
|
108
|
+
gputs "Replacing CRLF with LF"
|
109
|
+
Dir.glob("doc/**/*.*") do |file|
|
110
|
+
next unless File.file?(file)
|
111
|
+
|
112
|
+
content = ""
|
113
|
+
File.open(file, "rb") do |f|
|
114
|
+
content = f.read
|
115
|
+
end
|
116
|
+
content.gsub!("\r\n", "\n")
|
117
|
+
File.open(file, "wb") do |f|
|
118
|
+
f.print(content)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
sputs "Successfully replaced CRLF with LF"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
task :replace => %i[replace:css replace:html replace:eol]
|
125
|
+
task :build_all do
|
126
|
+
require "fileutils"
|
127
|
+
gputs "Building all versions"
|
128
|
+
FileUtils.cp_r("./template-replace/.", "./tmp-template-replace")
|
129
|
+
tags = `git tag`.force_encoding("utf-8").split("\n")
|
130
|
+
tags.each do |tag|
|
131
|
+
sh "git checkout #{tag} -f"
|
132
|
+
gputs "Building #{tag}"
|
133
|
+
FileUtils.cp_r("./tmp-template-replace/.", "./template-replace")
|
134
|
+
version = tag.delete_prefix("v")
|
135
|
+
Rake::Task["document:yard"].execute
|
136
|
+
Rake::Task["document:replace:html"].execute
|
137
|
+
Rake::Task["document:replace:css"].execute
|
138
|
+
Rake::Task["document:replace:eol"].execute
|
139
|
+
end
|
140
|
+
version = "."
|
141
|
+
Rake::Task["document:yard"].execute
|
142
|
+
Rake::Task["document:replace:html"].execute
|
143
|
+
Rake::Task["document:replace:css"].execute
|
144
|
+
Rake::Task["document:replace:eol"].execute
|
145
|
+
sh "git switch main -f"
|
146
|
+
sputs "Successfully built all versions"
|
147
|
+
end
|
148
|
+
task :push do
|
149
|
+
gputs "Pushing documents"
|
150
|
+
Dir.chdir("doc") do
|
151
|
+
sh "git add ."
|
152
|
+
sh "git commit -m \"Update: Update document\""
|
153
|
+
sh "git push -f"
|
154
|
+
end
|
155
|
+
sputs "Successfully pushed documents"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
task :document => %i[document:yard document:replace]
|
data/crowdin.yml
ADDED
data/discorb.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.metadata["homepage_uri"] = spec.homepage
|
19
19
|
spec.metadata["source_code_uri"] = "https://github.com/discorb-lib/discorb"
|
20
20
|
spec.metadata["changelog_uri"] = "https://github.com/discorb-lib/discorb/blob/main/Changelog.md"
|
21
|
+
spec.metadata["documentation_uri"] = "https://discorb-lib.github.io"
|
21
22
|
|
22
23
|
# Specify which files should be added to the gem when it is released.
|
23
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
data/docs/application_command.md
CHANGED
@@ -10,7 +10,7 @@ From: [Discord API docs](https://discord.com/developers/docs/interactions/applic
|
|
10
10
|
|
11
11
|
## How do I register an application command?
|
12
12
|
|
13
|
-
Use {Discorb::Command::Handler
|
13
|
+
Use {Discorb::Command::Handler.slash}, {Discorb::Command::Handler.slash_group} for slash commands, {Discorb::Command::Handler.user_command} for user menu commands, and {Discorb::Command::Handler.message_command} for message menu commands.
|
14
14
|
|
15
15
|
### Note
|
16
16
|
|
@@ -69,7 +69,7 @@ In `options`, hash should be like this:
|
|
69
69
|
{
|
70
70
|
"vocaloid" => {
|
71
71
|
required: true,
|
72
|
-
description: "The vocaloid which you like."
|
72
|
+
description: "The vocaloid which you like.",
|
73
73
|
type: :string,
|
74
74
|
choices: {
|
75
75
|
"Hatsune Miku" => "miku",
|
@@ -125,7 +125,7 @@ group.slash("bump_alert", "Whether bot should notify DISBOARD bump.", {
|
|
125
125
|
end
|
126
126
|
```
|
127
127
|
|
128
|
-
You can make subcommand group by using {Discorb::Command::GroupCommand#group}.
|
128
|
+
You can make subcommand group by using {Discorb::Command::Command::GroupCommand#group}.
|
129
129
|
|
130
130
|
```ruby
|
131
131
|
group = client.slash_group("permission", "Set/Get command permissions.")
|
@@ -211,7 +211,7 @@ client.user_command("hello") do |interaction, user|
|
|
211
211
|
interaction.post("Hello, #{user.name}!")
|
212
212
|
end
|
213
213
|
```
|
214
|
-
{Discorb::Command::Handler
|
214
|
+
{Discorb::Command::Handler.user_command} takes 3 arguments:
|
215
215
|
|
216
216
|
| Parameter | Description |
|
217
217
|
| --- | --- |
|
@@ -235,7 +235,7 @@ client.message_command("Bookmark") do |interaction, message|
|
|
235
235
|
end
|
236
236
|
```
|
237
237
|
|
238
|
-
{Discorb::Command::Handler
|
238
|
+
{Discorb::Command::Handler.message_command} takes 3 arguments:
|
239
239
|
|
240
240
|
| Parameter | Description |
|
241
241
|
| --- | --- |
|
@@ -248,4 +248,4 @@ end
|
|
248
248
|
| Parameter | Description |
|
249
249
|
| --- | --- |
|
250
250
|
| `interaction` | The interaction object. |
|
251
|
-
| `message` | The message object. |
|
251
|
+
| `message` | The message object. |
|
data/docs/discord_irb.md
CHANGED
@@ -18,7 +18,7 @@ To start.
|
|
18
18
|
discord-irb will load a token from...
|
19
19
|
1. the `DISCORD_BOT_TOKEN` environment variable
|
20
20
|
2. the `DISCORD_TOKEN` environment variable
|
21
|
-
3. `token` file in the current directory(customizable with `-
|
21
|
+
3. `token` file in the current directory(customizable with `-t` option)
|
22
22
|
4. your input
|
23
23
|
|
24
24
|
### Arguments
|
data/docs/events.md
CHANGED
@@ -5,8 +5,8 @@
|
|
5
5
|
## How to use events
|
6
6
|
|
7
7
|
discorb uses event driven programming.
|
8
|
-
You can register event handlers with {Client#on}.
|
9
|
-
Alternatively, you can use {Client#once} to register a one-time event handler.
|
8
|
+
You can register event handlers with {Discorb::Client#on}.
|
9
|
+
Alternatively, you can use {Discorb::Client#once} to register a one-time event handler.
|
10
10
|
|
11
11
|
```ruby
|
12
12
|
client.on :message do |event|
|
@@ -16,6 +16,20 @@ end
|
|
16
16
|
|
17
17
|
This example will print the content of every message received.
|
18
18
|
|
19
|
+
Since v0.2.5, you can also register event handlers by adding a method to the client, with the prefix `on_` and the event name as the method name.
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
client = Discorb::Client.new
|
23
|
+
|
24
|
+
class << client
|
25
|
+
def on_ready
|
26
|
+
puts "Ready!"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
If you want to seperate event handlers from the client, consider using {Discorb::Extension}. {file:docs/extension.md Learn more about extensions}.
|
32
|
+
|
19
33
|
## Event reference
|
20
34
|
|
21
35
|
### Client events
|
@@ -139,7 +153,7 @@ Fires when a webhook is updated.
|
|
139
153
|
|
140
154
|
| Parameter | Type | Description |
|
141
155
|
| ---------- | ----- | ----------- |
|
142
|
-
|`event` | {Discorb::WebhooksUpdateEvent} | The webhook update event. |
|
156
|
+
|`event` | {Discorb::Gateway::WebhooksUpdateEvent} | The webhook update event. |
|
143
157
|
|
144
158
|
#### `thread_new(thread)`
|
145
159
|
|
@@ -182,8 +196,8 @@ Fires when a thread's members are updated.
|
|
182
196
|
| Parameter | Type | Description |
|
183
197
|
| ---------- | ----- | ----------- |
|
184
198
|
|`thread` | {Discorb::ThreadChannel} | The thread that the members were updated for. |
|
185
|
-
|`added` | Array<{ThreadChannel::Member}> | An array of {Discorb::ThreadChannel::Member} objects that were added to the thread. |
|
186
|
-
|`removed` | Array<{ThreadChannel::Member}> | An array of {Discorb::ThreadChannel::Member} objects that were removed from the thread. |
|
199
|
+
|`added` | Array<{Discorb::ThreadChannel::Member}> | An array of {Discorb::ThreadChannel::Member} objects that were added to the thread. |
|
200
|
+
|`removed` | Array<{Discorb::ThreadChannel::Member}> | An array of {Discorb::ThreadChannel::Member} objects that were removed from the thread. |
|
187
201
|
|
188
202
|
#### `thread_member_update(before, after)`
|
189
203
|
|
@@ -258,7 +272,7 @@ This will fire when cached messages are deleted.
|
|
258
272
|
#### `message_delete_id(message_id, channel, guild)`
|
259
273
|
|
260
274
|
Fires when a message is deleted.
|
261
|
-
Not like {
|
275
|
+
Not like {file:#message_delete} this will fire even message is not cached.
|
262
276
|
|
263
277
|
| Parameter | Type | Description |
|
264
278
|
| ---------- | ----- | ----------- |
|
@@ -280,7 +294,7 @@ Fires when a message is pinned or unpinned.
|
|
280
294
|
|
281
295
|
| Parameter | Type | Description |
|
282
296
|
| ---------- | ----- | ----------- |
|
283
|
-
|`event` | {Discorb::Gateway::
|
297
|
+
|`event` | {Discorb::Gateway::MessagePinEvent}| The event object. |
|
284
298
|
|
285
299
|
#### `typing_start(event)`
|
286
300
|
|