discorb 0.8.1 → 0.9.3
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/Changelog.md +25 -0
- data/docs/faq.md +1 -1
- data/lib/discorb/client.rb +9 -12
- data/lib/discorb/common.rb +1 -1
- data/lib/discorb/exe/run.rb +5 -3
- data/lib/discorb/gateway.rb +2 -4
- data/lib/discorb/interaction.rb +74 -7
- data/lib/discorb/message.rb +49 -0
- data/lib/discorb/utils.rb +20 -0
- metadata +2 -4
- data/.github/workflows/changelog.rb +0 -12
- data/.github/workflows/release_from_changelog.yml +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbb61003015daf1f1731f80809e9c739cad169f60b7b5f7cc6c1ac7580d61bd1
|
4
|
+
data.tar.gz: e2d7bcad6c493bea84b7f2608a1d1366f76e95675c50052b034742be322d0569
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b2cee7155fe0273181fc7cf1fdd048ebd0b9d1adba4ca7c4444a31a92b5cd86a65c77511e581858c379e1abb53d1d092ab6115394b0a9fbc076b6692b04312b
|
7
|
+
data.tar.gz: 245db18f6b68599ccf199e5c1571a3f38181d4a4a6dc5371cf55e29bc9dd1d95766ff67047091558aaf392f41ea3fb0d28b726972c120ad7dd80a216a1e3699c
|
data/Changelog.md
CHANGED
@@ -220,3 +220,28 @@ end
|
|
220
220
|
- Add: Add `File.from_string`
|
221
221
|
- Fix: Fix `Client#update_presence`
|
222
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
|
data/docs/faq.md
CHANGED
data/lib/discorb/client.rb
CHANGED
@@ -65,13 +65,14 @@ module Discorb
|
|
65
65
|
# @param [Boolean] colorize_log Whether to colorize the log.
|
66
66
|
# @param [:debug, :info, :warn, :error, :critical] log_level The log level.
|
67
67
|
# @param [Boolean] wait_until_ready Whether to delay event dispatch until ready.
|
68
|
-
# @param [Boolean] fetch_member Whether to fetch member on ready. This may slow down the client.
|
69
|
-
#
|
68
|
+
# @param [Boolean] fetch_member Whether to fetch member on ready. This may slow down the client. Default to `false`.
|
69
|
+
# @param [String] title The title of the process. `false` to default, `nil` to `discorb: User#0000`. Default to `nil`.
|
70
70
|
#
|
71
71
|
def initialize(
|
72
72
|
allowed_mentions: nil, intents: nil, message_caches: 1000,
|
73
73
|
log: nil, colorize_log: false, log_level: :info,
|
74
|
-
wait_until_ready: true, fetch_member:
|
74
|
+
wait_until_ready: true, fetch_member: false,
|
75
|
+
title: nil
|
75
76
|
)
|
76
77
|
@allowed_mentions = allowed_mentions || AllowedMentions.new(everyone: true, roles: true, users: true)
|
77
78
|
@intents = (intents or Intents.default)
|
@@ -94,7 +95,8 @@ module Discorb
|
|
94
95
|
@commands = []
|
95
96
|
@bottom_commands = []
|
96
97
|
@status = :initialized
|
97
|
-
@fetch_member = fetch_member
|
98
|
+
@fetch_member = fetch_member
|
99
|
+
@title = title
|
98
100
|
set_default_events
|
99
101
|
end
|
100
102
|
|
@@ -496,15 +498,10 @@ module Discorb
|
|
496
498
|
end
|
497
499
|
|
498
500
|
once :standby do
|
499
|
-
if @
|
500
|
-
title = "discorb: #{@user}"
|
501
|
-
Process.setproctitle title
|
502
|
-
sputs "Your discorb client is now in standby mode."
|
503
|
-
iputs "Process ID: #{Process.pid}"
|
504
|
-
iputs "Title: #{title}"
|
501
|
+
next if @title == false
|
505
502
|
|
506
|
-
|
507
|
-
|
503
|
+
title = @title || ENV["DISCORB_CLI_TITLE"] || "discorb: #{@user}"
|
504
|
+
Process.setproctitle title
|
508
505
|
end
|
509
506
|
end
|
510
507
|
end
|
data/lib/discorb/common.rb
CHANGED
@@ -4,7 +4,7 @@ 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.
|
7
|
+
VERSION = "0.9.3"
|
8
8
|
# @return [String] The user agent for the bot.
|
9
9
|
USER_AGENT = "DiscordBot (https://github.com/discorb-lib/discorb #{VERSION}) Ruby/#{RUBY_VERSION}"
|
10
10
|
|
data/lib/discorb/exe/run.rb
CHANGED
@@ -16,14 +16,13 @@ opt = OptionParser.new <<~BANNER
|
|
16
16
|
script The script to run. Defaults to 'main.rb'.
|
17
17
|
BANNER
|
18
18
|
options = {
|
19
|
-
|
19
|
+
title: nil,
|
20
20
|
log_level: nil,
|
21
21
|
log_file: nil,
|
22
22
|
log_color: nil,
|
23
23
|
setup: nil,
|
24
24
|
token: false,
|
25
25
|
}
|
26
|
-
opt.on("-d", "--deamon", "Run as a daemon.") { |v| options[:daemon] = v }
|
27
26
|
opt.on("-l", "--log-level LEVEL", "Log level.") do |v|
|
28
27
|
unless LOG_LEVELS.include? v.downcase
|
29
28
|
eputs "Invalid log level: \e[31m#{v}\e[91m"
|
@@ -35,7 +34,8 @@ end
|
|
35
34
|
opt.on("-f", "--log-file FILE", "File to write log to.") { |v| options[:log_file] = v }
|
36
35
|
opt.on("-c", "--[no-]log-color", "Whether to colorize log output.") { |v| options[:log_color] = v }
|
37
36
|
opt.on("-s", "--setup", "Whether to setup application commands.") { |v| options[:setup] = v }
|
38
|
-
opt.on("-
|
37
|
+
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
|
+
opt.on("-t", "--title TITLE", "The title of process.") { |v| options[:title] = v }
|
39
39
|
opt.parse!(ARGV)
|
40
40
|
|
41
41
|
script = ARGV[0]
|
@@ -54,6 +54,8 @@ elsif options[:token].nil? || options[:token] == "-"
|
|
54
54
|
puts ""
|
55
55
|
end
|
56
56
|
|
57
|
+
ENV["DISCORB_CLI_TITLE"] = options[:title]
|
58
|
+
|
57
59
|
begin
|
58
60
|
load script
|
59
61
|
rescue LoadError
|
data/lib/discorb/gateway.rb
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
require "async/http"
|
4
4
|
require "async/websocket"
|
5
5
|
require "async/barrier"
|
6
|
-
require "async/semaphore"
|
7
6
|
require "json"
|
8
7
|
require "zlib"
|
9
8
|
|
@@ -1035,14 +1034,13 @@ module Discorb
|
|
1035
1034
|
if @fetch_member
|
1036
1035
|
@log.debug "Fetching members"
|
1037
1036
|
barrier = Async::Barrier.new
|
1038
|
-
semaphore = Async::Semaphore.new(@guilds.length)
|
1039
1037
|
|
1040
1038
|
@guilds.each do |guild|
|
1041
|
-
|
1039
|
+
barrier.async(parent: barrier) do
|
1042
1040
|
guild.fetch_members
|
1043
1041
|
end
|
1044
1042
|
end
|
1045
|
-
|
1043
|
+
barrier.wait
|
1046
1044
|
end
|
1047
1045
|
@ready = true
|
1048
1046
|
dispatch(:standby)
|
data/lib/discorb/interaction.rb
CHANGED
@@ -131,6 +131,8 @@ module Discorb
|
|
131
131
|
# @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
|
132
132
|
# @param [Boolean] ephemeral Whether to make the response ephemeral.
|
133
133
|
#
|
134
|
+
# @return [Discorb::Interaction::SourceResponse::CallbackMessage, Discorb::Webhook::Message] The callback message.
|
135
|
+
#
|
134
136
|
def post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, components: nil, ephemeral: false)
|
135
137
|
Async do
|
136
138
|
payload = {}
|
@@ -165,14 +167,79 @@ module Discorb
|
|
165
167
|
end
|
166
168
|
payload[:flags] = (ephemeral ? 1 << 6 : 0)
|
167
169
|
|
168
|
-
if @responded
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
170
|
+
ret = if @responded
|
171
|
+
_resp, data = @client.http.post("/webhooks/#{@application_id}/#{@token}", payload).wait
|
172
|
+
webhook = Webhook::URLWebhook.new("/webhooks/#{@application_id}/#{@token}")
|
173
|
+
Webhook::Message.new(webhook, data, @client)
|
174
|
+
elsif @defered
|
175
|
+
@client.http.patch("/webhooks/#{@application_id}/#{@token}/messages/@original", payload).wait
|
176
|
+
CallbackMessage.new(@client, payload, @application_id, @token)
|
177
|
+
else
|
178
|
+
@client.http.post("/interactions/#{@id}/#{@token}/callback", { type: 4, data: payload }).wait
|
179
|
+
CallbackMessage.new(@client, payload, @application_id, @token)
|
180
|
+
end
|
175
181
|
@responded = true
|
182
|
+
ret
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
class CallbackMessage
|
187
|
+
# @!visibility private
|
188
|
+
def initialize(client, data, application_id, token)
|
189
|
+
@client = client
|
190
|
+
@data = data
|
191
|
+
@application_id = application_id
|
192
|
+
@token = token
|
193
|
+
end
|
194
|
+
|
195
|
+
#
|
196
|
+
# Edits the callback message.
|
197
|
+
# @macro async
|
198
|
+
# @macro http
|
199
|
+
# @macro edit
|
200
|
+
#
|
201
|
+
# @param [Discorb::Webhook::Message] message The message to edit.
|
202
|
+
# @param [String] content The new content of the message.
|
203
|
+
# @param [Discorb::Embed] embed The new embed of the message.
|
204
|
+
# @param [Array<Discorb::Embed>] embeds The new embeds of the message.
|
205
|
+
# @param [Array<Discorb::Attachment>] attachments The attachments to remain.
|
206
|
+
# @param [Discorb::File] file The file to send.
|
207
|
+
# @param [Array<Discorb::File>] files The files to send.
|
208
|
+
#
|
209
|
+
def edit(
|
210
|
+
content = :unset,
|
211
|
+
embed: :unset, embeds: :unset,
|
212
|
+
file: :unset, files: :unset,
|
213
|
+
attachments: :unset
|
214
|
+
)
|
215
|
+
Async do
|
216
|
+
payload = {}
|
217
|
+
payload[:content] = content if content != :unset
|
218
|
+
payload[:embeds] = embed ? [embed.to_hash] : [] if embed != :unset
|
219
|
+
payload[:embeds] = embeds.map(&:to_hash) if embeds != :unset
|
220
|
+
payload[:attachments] = attachments.map(&:to_hash) if attachments != :unset
|
221
|
+
files = [file] if file != :unset
|
222
|
+
if files == :unset
|
223
|
+
headers = {
|
224
|
+
"Content-Type" => "application/json",
|
225
|
+
}
|
226
|
+
else
|
227
|
+
headers, payload = HTTP.multipart(payload, files)
|
228
|
+
end
|
229
|
+
@client.http.patch("/webhooks/#{@application_id}/#{@token}/messages/@original", payload, headers: headers).wait
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
alias modify edit
|
234
|
+
|
235
|
+
#
|
236
|
+
# Deletes the callback message.
|
237
|
+
# @note This will fail if the message is ephemeral.
|
238
|
+
#
|
239
|
+
def delete!
|
240
|
+
Async do
|
241
|
+
@client.http.delete("/webhooks/#{@application_id}/#{@token}/messages/@original").wait
|
242
|
+
end
|
176
243
|
end
|
177
244
|
end
|
178
245
|
end
|
data/lib/discorb/message.rb
CHANGED
@@ -213,6 +213,55 @@ module Discorb
|
|
213
213
|
!@updated_at.nil?
|
214
214
|
end
|
215
215
|
|
216
|
+
#
|
217
|
+
# Removes the mentions from the message.
|
218
|
+
#
|
219
|
+
# @param [Boolean] user Whether to clean user mentions.
|
220
|
+
# @param [Boolean] channel Whether to clean channel mentions.
|
221
|
+
# @param [Boolean] role Whether to clean role mentions.
|
222
|
+
# @param [Boolean] emoji Whether to clean emoji.
|
223
|
+
# @param [Boolean] everyone Whether to clean `@everyone` and `@here`.
|
224
|
+
# @param [Boolean] codeblock Whether to clean codeblocks.
|
225
|
+
#
|
226
|
+
# @return [String] The cleaned content of the message.
|
227
|
+
#
|
228
|
+
def clean_content(user: true, channel: true, role: true, emoji: true, everyone: true, codeblock: false)
|
229
|
+
ret = @content.dup
|
230
|
+
ret.gsub!(/<@!?(\d+)>/) do |match|
|
231
|
+
member = guild&.members&.[]($1)
|
232
|
+
member ||= @client.users[$1]
|
233
|
+
member ? "@#{member.name}" : "@Unknown User"
|
234
|
+
end if user
|
235
|
+
ret.gsub!(/<#(\d+)>/) do |match|
|
236
|
+
channel = @client.channels[$1]
|
237
|
+
channel ? "<##{channel.id}>" : "#Unknown Channel"
|
238
|
+
end
|
239
|
+
ret.gsub!(/<@&(\d+)>/) do |match|
|
240
|
+
role = guild&.roles&.[]($1)
|
241
|
+
role ? "@#{role.name}" : "@Unknown Role"
|
242
|
+
end if role
|
243
|
+
ret.gsub!(/<a?:([a-zA-Z0-9_]+):\d+>/) do |match|
|
244
|
+
$1
|
245
|
+
end if emoji
|
246
|
+
ret.gsub!(/@(everyone|here)/, "@\u200b\\1") if everyone
|
247
|
+
unless codeblock
|
248
|
+
codeblocks = ret.split("```", -1)
|
249
|
+
original_codeblocks = @content.scan(/```(.+?)```/m)
|
250
|
+
res = []
|
251
|
+
max = codeblocks.length
|
252
|
+
codeblocks.each_with_index do |codeblock, i|
|
253
|
+
if max % 2 == 0 && i == max - 1 or i.even?
|
254
|
+
res << codeblock
|
255
|
+
else
|
256
|
+
res << original_codeblocks[i / 2]
|
257
|
+
end
|
258
|
+
end
|
259
|
+
res.join("```")
|
260
|
+
else
|
261
|
+
ret
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
216
265
|
#
|
217
266
|
# Edit the message.
|
218
267
|
#
|
data/lib/discorb/utils.rb
CHANGED
@@ -14,3 +14,23 @@ module Discorb
|
|
14
14
|
module_function :try
|
15
15
|
end
|
16
16
|
end
|
17
|
+
|
18
|
+
class Async::Node
|
19
|
+
def description
|
20
|
+
@object_name ||= "#{self.class}:0x#{object_id.to_s(16)}#{@transient ? ' transient' : nil}"
|
21
|
+
|
22
|
+
if @annotation
|
23
|
+
"#{@object_name} #{@annotation}"
|
24
|
+
elsif line = self.backtrace(0, 1)&.first
|
25
|
+
"#{@object_name} #{line}"
|
26
|
+
else
|
27
|
+
@object_name
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s
|
32
|
+
"\#<#{self.description}>"
|
33
|
+
end
|
34
|
+
|
35
|
+
alias inspect to_s
|
36
|
+
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.
|
4
|
+
version: 0.9.3
|
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-
|
11
|
+
date: 2021-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|
@@ -79,8 +79,6 @@ files:
|
|
79
79
|
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
80
80
|
- ".github/workflows/build_main.yml"
|
81
81
|
- ".github/workflows/build_version.yml"
|
82
|
-
- ".github/workflows/changelog.rb"
|
83
|
-
- ".github/workflows/release_from_changelog.yml"
|
84
82
|
- ".gitignore"
|
85
83
|
- ".yardopts"
|
86
84
|
- Changelog.md
|
@@ -1,12 +0,0 @@
|
|
1
|
-
changelog = File.read("./Changelog.md")
|
2
|
-
releases = changelog.split("## ")
|
3
|
-
releases_hash = releases.map do |release|
|
4
|
-
release_name = "v" + release.split("\n")[0]
|
5
|
-
release_body = release.split("\n")[1..-1].join("\n").strip
|
6
|
-
[release_name, release_body]
|
7
|
-
end.to_h
|
8
|
-
|
9
|
-
release_version = ENV["GITHUB_REF"].split("/")[-1]
|
10
|
-
|
11
|
-
release_body = releases_hash[release_version] || "No release notes for this version"
|
12
|
-
puts "::set-output name=release_body::#{release_body.gsub("\n", "\\n")}"
|
@@ -1,39 +0,0 @@
|
|
1
|
-
name: Release from changelog
|
2
|
-
|
3
|
-
on:
|
4
|
-
workflow_dispatch:
|
5
|
-
push:
|
6
|
-
tags:
|
7
|
-
- "v*"
|
8
|
-
jobs:
|
9
|
-
main:
|
10
|
-
|
11
|
-
runs-on: ubuntu-latest
|
12
|
-
|
13
|
-
steps:
|
14
|
-
- uses: actions/checkout@v2
|
15
|
-
with:
|
16
|
-
fetch-depth: 0
|
17
|
-
- name: Set up Ruby
|
18
|
-
uses: ruby/setup-ruby@v1
|
19
|
-
with:
|
20
|
-
ruby-version: 3.0.2
|
21
|
-
bundler-cache: true
|
22
|
-
- name: Install dependencies
|
23
|
-
run: |
|
24
|
-
bundle install
|
25
|
-
- name: Get changelog
|
26
|
-
run: |
|
27
|
-
bundle exec ruby .github/workflows/changelog.rb
|
28
|
-
id: get-changelog
|
29
|
-
- name: Build gem
|
30
|
-
run: |
|
31
|
-
bundle exec rake build
|
32
|
-
- name: Release
|
33
|
-
uses: softprops/action-gh-release@v1
|
34
|
-
with:
|
35
|
-
files: |
|
36
|
-
$(ls -1 pkg/*.gem)
|
37
|
-
body: ${{ steps.get-changelog.outputs.release_body }}
|
38
|
-
env:
|
39
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|