discorb 0.0.1 → 0.0.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/Changelog.md +14 -2
- data/Gemfile.lock +5 -5
- data/README.md +1 -1
- data/discorb.gemspec +7 -5
- data/lib/discorb/channel.rb +32 -32
- data/lib/discorb/client.rb +8 -8
- data/lib/discorb/common.rb +4 -1
- data/lib/discorb/emoji.rb +2 -2
- data/lib/discorb/gateway.rb +4 -2
- data/lib/discorb/guild.rb +37 -37
- data/lib/discorb/guild_template.rb +3 -3
- data/lib/discorb/{internet.rb → http.rb} +2 -2
- data/lib/discorb/integration.rb +1 -1
- data/lib/discorb/interaction.rb +6 -6
- data/lib/discorb/invite.rb +1 -1
- data/lib/discorb/member.rb +3 -3
- data/lib/discorb/message.rb +7 -7
- data/lib/discorb/modules.rb +6 -6
- data/lib/discorb/role.rb +3 -3
- data/lib/discorb/sticker.rb +2 -2
- data/lib/discorb/user.rb +2 -2
- data/lib/discorb/voice_state.rb +2 -2
- data/lib/discorb/webhook.rb +10 -11
- data/lib/discorb.rb +1 -1
- metadata +65 -18
data/lib/discorb/message.rb
CHANGED
@@ -264,7 +264,7 @@ module Discorb
|
|
264
264
|
#
|
265
265
|
def add_reaction(emoji)
|
266
266
|
Async do |_task|
|
267
|
-
@client.
|
267
|
+
@client.http.put("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/@me", nil).wait
|
268
268
|
end
|
269
269
|
end
|
270
270
|
|
@@ -279,7 +279,7 @@ module Discorb
|
|
279
279
|
#
|
280
280
|
def remove_reaction(emoji)
|
281
281
|
Async do |_task|
|
282
|
-
@client.
|
282
|
+
@client.http.delete("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/@me").wait
|
283
283
|
end
|
284
284
|
end
|
285
285
|
|
@@ -295,7 +295,7 @@ module Discorb
|
|
295
295
|
#
|
296
296
|
def remove_reaction_of(emoji, member)
|
297
297
|
Async do |_task|
|
298
|
-
@client.
|
298
|
+
@client.http.delete("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/#{member.is_a?(Member) ? member.id : member}").wait
|
299
299
|
end
|
300
300
|
end
|
301
301
|
|
@@ -318,7 +318,7 @@ module Discorb
|
|
318
318
|
after = 0
|
319
319
|
users = []
|
320
320
|
loop do
|
321
|
-
_resp, data = @client.
|
321
|
+
_resp, data = @client.http.get("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}?limit=100&after=#{after}").wait
|
322
322
|
break if data.empty?
|
323
323
|
|
324
324
|
users += data.map { |r| guild&.members&.[](r[:id]) || @client.users[r[:id]] || User.new(@client, r) }
|
@@ -329,7 +329,7 @@ module Discorb
|
|
329
329
|
end
|
330
330
|
next users
|
331
331
|
else
|
332
|
-
_resp, data = @client.
|
332
|
+
_resp, data = @client.http.get("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}?limit=#{limit}&after=#{after}").wait
|
333
333
|
next data.map { |r| guild&.members&.[](r[:id]) || @client.users[r[:id]] || User.new(@client, r) }
|
334
334
|
end
|
335
335
|
end
|
@@ -490,9 +490,9 @@ module Discorb
|
|
490
490
|
@guild_id = nil
|
491
491
|
end
|
492
492
|
|
493
|
-
if data[:
|
493
|
+
if data[:member].nil? && data[:webhook_id]
|
494
494
|
@webhook_id = Snowflake.new(data[:webhook_id])
|
495
|
-
|
495
|
+
@author = Webhook::Message::Author.new(data[:author])
|
496
496
|
elsif data[:guild_id].nil? || data[:guild_id].empty?
|
497
497
|
@author = @client.users[data[:author][:id]] || User.new(@client, data[:author])
|
498
498
|
else
|
data/lib/discorb/modules.rb
CHANGED
@@ -57,11 +57,11 @@ module Discorb
|
|
57
57
|
end
|
58
58
|
files = [file] if file
|
59
59
|
if files
|
60
|
-
headers, payload =
|
60
|
+
headers, payload = HTTP.multipart(payload, files)
|
61
61
|
else
|
62
62
|
headers = {}
|
63
63
|
end
|
64
|
-
_resp, data = @client.
|
64
|
+
_resp, data = @client.http.post("#{base_url.wait}/messages", payload, headers: headers).wait
|
65
65
|
Message.new(@client, data.merge({ guild_id: @guild_id.to_s }))
|
66
66
|
end
|
67
67
|
end
|
@@ -76,7 +76,7 @@ module Discorb
|
|
76
76
|
#
|
77
77
|
def fetch_message(id)
|
78
78
|
Async do
|
79
|
-
_resp, data = @client.
|
79
|
+
_resp, data = @client.http.get("#{base_url.wait}/messages/#{id}").wait
|
80
80
|
Message.new(@client, data.merge({ guild_id: @guild_id.to_s }))
|
81
81
|
end
|
82
82
|
end
|
@@ -99,7 +99,7 @@ module Discorb
|
|
99
99
|
after: Discorb::Utils.try(around, :id),
|
100
100
|
around: Discorb::Utils.try(before, :id),
|
101
101
|
}.filter { |_k, v| !v.nil? }.to_h
|
102
|
-
_resp, messages = @client.
|
102
|
+
_resp, messages = @client.http.get("#{base_url.wait}/messages?#{URI.encode_www_form(params)}").wait
|
103
103
|
messages.map { |m| Message.new(@client, m.merge({ guild_id: @guild_id.to_s })) }
|
104
104
|
end
|
105
105
|
end
|
@@ -122,7 +122,7 @@ module Discorb
|
|
122
122
|
if block_given?
|
123
123
|
begin
|
124
124
|
post_task = task.async do
|
125
|
-
@client.
|
125
|
+
@client.http.post("/channels/#{@id}/typing", {})
|
126
126
|
sleep(5)
|
127
127
|
end
|
128
128
|
yield
|
@@ -130,7 +130,7 @@ module Discorb
|
|
130
130
|
post_task.stop
|
131
131
|
end
|
132
132
|
else
|
133
|
-
@client.
|
133
|
+
@client.http.post("/channels/#{@id}/typing", {})
|
134
134
|
end
|
135
135
|
end
|
136
136
|
end
|
data/lib/discorb/role.rb
CHANGED
@@ -88,7 +88,7 @@ module Discorb
|
|
88
88
|
#
|
89
89
|
def move(position, reason: nil)
|
90
90
|
Async do
|
91
|
-
@client.
|
91
|
+
@client.http.patch("/guilds/#{@guild_id}/roles", { id: @id, position: position }, reason: reason).wait
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
@@ -113,7 +113,7 @@ module Discorb
|
|
113
113
|
payload[:color] = color.to_i if color != :unset
|
114
114
|
payload[:hoist] = hoist if hoist != :unset
|
115
115
|
payload[:mentionable] = mentionable if mentionable != :unset
|
116
|
-
@client.
|
116
|
+
@client.http.patch("/guilds/#{@guild_id}/roles/#{@id}", payload, reason: reason).wait
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
@@ -126,7 +126,7 @@ module Discorb
|
|
126
126
|
#
|
127
127
|
def delete!(reason: nil)
|
128
128
|
Async do
|
129
|
-
@client.
|
129
|
+
@client.http.delete("/guilds/#{@guild_id}/roles/#{@id}", reason: reason).wait
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
data/lib/discorb/sticker.rb
CHANGED
@@ -73,7 +73,7 @@ module Discorb
|
|
73
73
|
payload[:name] = name unless name == :unset
|
74
74
|
payload[:description] = description unless description == :unset
|
75
75
|
payload[:tags] = tag.name unless tag == :unset
|
76
|
-
@client.
|
76
|
+
@client.http.patch("/guilds/#{@guild_id}/stickers/#{@id}", payload, audit_log_reason: reason).wait
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -88,7 +88,7 @@ module Discorb
|
|
88
88
|
#
|
89
89
|
def delete!(reason: nil)
|
90
90
|
Async do
|
91
|
-
@client.
|
91
|
+
@client.http.delete("/guilds/#{@guild_id}/stickers/#{@id}", audit_log_reason: reason).wait
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
data/lib/discorb/user.rb
CHANGED
@@ -74,7 +74,7 @@ module Discorb
|
|
74
74
|
Async do
|
75
75
|
next @dm_channel_id if @dm_channel_id
|
76
76
|
|
77
|
-
dm_channel = @client.
|
77
|
+
dm_channel = @client.http.post("/users/#{@id}/channels", { recipient_id: @client.user.id }).wait
|
78
78
|
@dm_channel_id = dm_channel[:id]
|
79
79
|
"/channels/#{@dm_channel_id}"
|
80
80
|
end
|
@@ -155,7 +155,7 @@ module Discorb
|
|
155
155
|
else
|
156
156
|
payload[:avatar] = avatar.to_s
|
157
157
|
end
|
158
|
-
@client.
|
158
|
+
@client.http.patch("/users/@me", payload).wait
|
159
159
|
self
|
160
160
|
end
|
161
161
|
end
|
data/lib/discorb/voice_state.rb
CHANGED
@@ -179,7 +179,7 @@ module Discorb
|
|
179
179
|
payload = {}
|
180
180
|
payload[:topic] = topic if topic != :unset
|
181
181
|
payload[:privacy_level] = self.class.privacy_level.key(privacy_level) if privacy_level != :unset
|
182
|
-
@client.
|
182
|
+
@client.http.edit("/stage-instances/#{@channel_id}", payload, audit_log_reason: reason).wait
|
183
183
|
self
|
184
184
|
end
|
185
185
|
end
|
@@ -193,7 +193,7 @@ module Discorb
|
|
193
193
|
#
|
194
194
|
def delete!(reason: nil)
|
195
195
|
Async do
|
196
|
-
@client.
|
196
|
+
@client.http.delete("/stage-instances/#{@channel_id}", reason: reason).wait
|
197
197
|
self
|
198
198
|
end
|
199
199
|
end
|
data/lib/discorb/webhook.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "async/http/internet"
|
4
|
-
|
5
3
|
module Discorb
|
6
4
|
#
|
7
5
|
# Represents a webhook.
|
@@ -36,7 +34,7 @@ module Discorb
|
|
36
34
|
@token = ""
|
37
35
|
@application_id = data[:application_id]
|
38
36
|
@client = client
|
39
|
-
@
|
37
|
+
@http = Discorb::HTTP.new(client)
|
40
38
|
end
|
41
39
|
|
42
40
|
def inspect
|
@@ -79,13 +77,13 @@ module Discorb
|
|
79
77
|
payload[:avatar_url] = avatar_url if avatar_url != :unset
|
80
78
|
files = [file] if file
|
81
79
|
if files
|
82
|
-
headers, payload =
|
80
|
+
headers, payload = HTTP.multipart(payload, files)
|
83
81
|
else
|
84
82
|
headers = {
|
85
83
|
"Content-Type" => "application/json",
|
86
84
|
}
|
87
85
|
end
|
88
|
-
_resp, data = @
|
86
|
+
_resp, data = @http.post("#{url}?wait=#{wait}", payload, headers: headers).wait
|
89
87
|
|
90
88
|
data && Webhook::Message.new(self, data)
|
91
89
|
end
|
@@ -109,7 +107,7 @@ module Discorb
|
|
109
107
|
payload[:name] = name if name != :unset
|
110
108
|
payload[:avatar] = avatar if avatar != :unset
|
111
109
|
payload[:channel_id] = Utils.try(channel, :id) if channel != :unset
|
112
|
-
@
|
110
|
+
@http.patch(url.to_s, payload).wait
|
113
111
|
end
|
114
112
|
end
|
115
113
|
|
@@ -122,7 +120,7 @@ module Discorb
|
|
122
120
|
#
|
123
121
|
def delete!
|
124
122
|
Async do
|
125
|
-
@
|
123
|
+
@http.delete(url).wait
|
126
124
|
self
|
127
125
|
end
|
128
126
|
end
|
@@ -165,9 +163,9 @@ module Discorb
|
|
165
163
|
"Content-Type" => "application/json",
|
166
164
|
}
|
167
165
|
else
|
168
|
-
headers, payload =
|
166
|
+
headers, payload = HTTP.multipart(payload, files)
|
169
167
|
end
|
170
|
-
_resp, data = @
|
168
|
+
_resp, data = @http.patch("#{url}/messages/#{Utils.try(message, :id)}", payload, headers: headers).wait
|
171
169
|
message.send(:_set_data, data)
|
172
170
|
message
|
173
171
|
end
|
@@ -180,7 +178,7 @@ module Discorb
|
|
180
178
|
#
|
181
179
|
def delete_message!(message)
|
182
180
|
Async do
|
183
|
-
@
|
181
|
+
@http.delete("#{url}/messages/#{Utils.try(message, :id)}").wait
|
184
182
|
message
|
185
183
|
end
|
186
184
|
end
|
@@ -200,7 +198,7 @@ module Discorb
|
|
200
198
|
def initialize(url)
|
201
199
|
@url = url
|
202
200
|
@token = ""
|
203
|
-
@
|
201
|
+
@http = Discorb::HTTP.new(self)
|
204
202
|
end
|
205
203
|
end
|
206
204
|
|
@@ -362,6 +360,7 @@ module Discorb
|
|
362
360
|
# @return [Boolean] Whether the author is a bot.
|
363
361
|
# @note This will be always `true`.
|
364
362
|
attr_reader :bot
|
363
|
+
alias bot? bot
|
365
364
|
# @return [Discorb::Snowflake] The ID of the author.
|
366
365
|
attr_reader :id
|
367
366
|
# @return [String] The name of the author.
|
data/lib/discorb.rb
CHANGED
@@ -39,7 +39,7 @@ module Discorb
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
require_order = %w[common flag dictionary error
|
42
|
+
require_order = %w[common flag dictionary error http intents emoji_table modules] +
|
43
43
|
%w[user member guild emoji channel embed message] +
|
44
44
|
%w[application audit_logs color components event extension] +
|
45
45
|
%w[file guild_template image integration interaction invite log permission] +
|
metadata
CHANGED
@@ -1,25 +1,72 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discorb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
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-08-
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
11
|
+
date: 2021-08-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: async
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: async-http
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: async-websocket
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mime-types
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.3'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.3'
|
69
|
+
description:
|
23
70
|
email:
|
24
71
|
- sevenc-nanashi@sevenbot.jp
|
25
72
|
executables: []
|
@@ -71,11 +118,11 @@ files:
|
|
71
118
|
- lib/discorb/gateway_requests.rb
|
72
119
|
- lib/discorb/guild.rb
|
73
120
|
- lib/discorb/guild_template.rb
|
121
|
+
- lib/discorb/http.rb
|
74
122
|
- lib/discorb/image.rb
|
75
123
|
- lib/discorb/integration.rb
|
76
124
|
- lib/discorb/intents.rb
|
77
125
|
- lib/discorb/interaction.rb
|
78
|
-
- lib/discorb/internet.rb
|
79
126
|
- lib/discorb/invite.rb
|
80
127
|
- lib/discorb/log.rb
|
81
128
|
- lib/discorb/member.rb
|
@@ -90,14 +137,14 @@ files:
|
|
90
137
|
- lib/discorb/utils.rb
|
91
138
|
- lib/discorb/voice_state.rb
|
92
139
|
- lib/discorb/webhook.rb
|
93
|
-
homepage: https://github.com/
|
140
|
+
homepage: https://github.com/discorb-lib/discorb
|
94
141
|
licenses:
|
95
142
|
- MIT
|
96
143
|
metadata:
|
97
144
|
allowed_push_host: https://rubygems.org
|
98
|
-
homepage_uri: https://github.com/
|
99
|
-
source_code_uri: https://github.com/
|
100
|
-
changelog_uri: https://github.com/
|
145
|
+
homepage_uri: https://github.com/discorb-lib/discorb
|
146
|
+
source_code_uri: https://github.com/discorb-lib/discorb
|
147
|
+
changelog_uri: https://github.com/discorb-lib/discorb/blob/main/Changelog.md
|
101
148
|
post_install_message:
|
102
149
|
rdoc_options: []
|
103
150
|
require_paths:
|