disrb 0.1.1.3 → 0.1.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 +4 -4
- data/README.md +2 -2
- data/lib/disrb/message.rb +207 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a71630cce586da07c2c33b6a782b08021b519c47c81e291589f80812203dacfd
|
4
|
+
data.tar.gz: ca079c9aa02046d884534807fd22262dea26638c3981da7100868a212b69b211
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dadbc64d9568ca3a67735e71bab510c91d42745fea7cfeb4269030ed87b5ad4020dea8614d43df6a168213972a10946465e175b43c33fd37b1e508ac273e919
|
7
|
+
data.tar.gz: 003a2895459efead777585cb1beee52a3f082b3519cfa182df4d2766c3b1087e5364b93c6622283a9f5708e0f2e8008fdc16605c3eb89ed40df30e211e6eeffc
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[Changelog](CHANGELOG.md) | [Licensed under the MIT License](LICENSE)
|
4
4
|
|
5
|
-
](https://github.com/hoovad/discord.rb/actions/workflows/main.yml) [](https://badge.fury.io/rb/disrb)
|
6
6
|
|
7
7
|
W.I.P. Discord API wrapper written in Ruby for fun.
|
8
8
|
|
@@ -22,7 +22,7 @@ The test.rb file creates two commands "test" and "test2", that return "Hi" and "
|
|
22
22
|
- [ ] Alpha release (v0.2.0)
|
23
23
|
- [ ] Add support for all Discord API endpoints
|
24
24
|
- [ ] Add support for all Discord Gateway events and properly handle the connection
|
25
|
-
- [ ] Documentation (v0.1.
|
25
|
+
- [ ] Documentation (v0.1.3)
|
26
26
|
- [x] Transition to Faraday for HTTP requests (v0.1.1)
|
27
27
|
- [x] Functions where all options are optional, check if atleast one is provided (v0.1.1.1)
|
28
28
|
- [x] Prefer to use keyword arguments over positional arguments if there are more than 1 optional arguments (v0.1.1.1)
|
data/lib/disrb/message.rb
CHANGED
@@ -3,6 +3,43 @@
|
|
3
3
|
# DiscordApi
|
4
4
|
# The class that contains everything that interacts with the Discord API.
|
5
5
|
class DiscordApi
|
6
|
+
def get_channel_messages(channel_id, around: nil, before: nil, after: nil, limit: nil)
|
7
|
+
options = { around: around, before: before, after: after }
|
8
|
+
specified_keys = options.reject { |_k, v| v.nil? }.keys
|
9
|
+
|
10
|
+
if specified_keys.size > 1
|
11
|
+
@logger.error('You can only specify one of around, before or after. Setting all to nil.')
|
12
|
+
around, before, after = nil
|
13
|
+
elsif specified_keys.size == 1
|
14
|
+
instance_variable_set("@#{specified_keys.first}", options[specified_keys.first])
|
15
|
+
end
|
16
|
+
|
17
|
+
query_string_hash = {}
|
18
|
+
query_string_hash[:around] = around unless around.nil?
|
19
|
+
query_string_hash[:before] = before unless before.nil?
|
20
|
+
query_string_hash[:after] = after unless after.nil?
|
21
|
+
query_string_hash[:limit] = limit unless limit.nil?
|
22
|
+
query_string = DiscordApi.handle_query_strings(query_string_hash)
|
23
|
+
url = "#{@base_url}/channels/#{channel_id}/messages#{query_string}"
|
24
|
+
headers = { 'Authorization': @authorization_header }
|
25
|
+
response = DiscordApi.get(url, headers)
|
26
|
+
return response unless response.status != 200
|
27
|
+
|
28
|
+
@logger.error("Failed to get messages from channel with ID #{channel_id}. Response: #{response.body}")
|
29
|
+
response
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_channel_message(channel_id, message_id)
|
33
|
+
url = "#{@base_url}/channels/#{channel_id}/messages/#{message_id}"
|
34
|
+
headers = { 'Authorization': @authorization_header }
|
35
|
+
response = DiscordApi.get(url, headers)
|
36
|
+
return response unless response.status != 200
|
37
|
+
|
38
|
+
@logger.error("Failed to get message with ID #{message_id} from channel with ID #{channel_id}. " \
|
39
|
+
"Response: #{response.body}")
|
40
|
+
response
|
41
|
+
end
|
42
|
+
|
6
43
|
def create_message(channel_id, content: nil, nonce: nil, tts: nil, embeds: nil, allowed_mentions: nil,
|
7
44
|
message_reference: nil, components: nil, sticker_ids: nil, files: nil, attachments: nil,
|
8
45
|
flags: nil, enforce_nonce: nil, poll: nil)
|
@@ -33,4 +70,174 @@ class DiscordApi
|
|
33
70
|
@logger.error("Failed to create message in channel #{channel_id}. Response: #{response.body}")
|
34
71
|
response
|
35
72
|
end
|
73
|
+
|
74
|
+
def crosspost_message(channel_id, message_id)
|
75
|
+
url = "#{@base_url}/channels/#{channel_id}/messages/#{message_id}/crosspost"
|
76
|
+
headers = { 'Authorization': @authorization_header }
|
77
|
+
response = DiscordApi.post(url, nil, headers)
|
78
|
+
return response unless response.status != 200
|
79
|
+
|
80
|
+
@logger.error("Failed to crosspost message with ID #{message_id} in channel with ID #{channel_id}. " \
|
81
|
+
"Response: #{response.body}")
|
82
|
+
response
|
83
|
+
end
|
84
|
+
|
85
|
+
def create_reaction(channel_id, message_id, emoji_id)
|
86
|
+
url = "#{@base_url}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji_id}/@me"
|
87
|
+
headers = { 'Authorization': @authorization_header }
|
88
|
+
response = DiscordApi.put(url, nil, headers)
|
89
|
+
return response unless response.status != 204
|
90
|
+
|
91
|
+
@logger.error("Failed to create reaction with emoji ID #{emoji_id} in channel with ID #{channel_id} " \
|
92
|
+
"for message with ID #{message_id}. Response: #{response.body}")
|
93
|
+
response
|
94
|
+
end
|
95
|
+
|
96
|
+
def delete_own_reaction(channel_id, message_id, emoji_id)
|
97
|
+
url = "#{@base_url}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji_id}/@me"
|
98
|
+
headers = { 'Authorization': @authorization_header }
|
99
|
+
response = DiscordApi.delete(url, headers)
|
100
|
+
return response unless response.status != 204
|
101
|
+
|
102
|
+
@logger.error("Failed to delete own reaction with emoji ID #{emoji_id} in channel with ID #{channel_id} " \
|
103
|
+
"for message with ID #{message_id}. Response: #{response.body}")
|
104
|
+
response
|
105
|
+
end
|
106
|
+
|
107
|
+
def delete_user_reaction(channel_id, message_id, emoji_id, user_id)
|
108
|
+
url = "#{@base_url}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji_id}/#{user_id}"
|
109
|
+
headers = { 'Authorization': @authorization_header }
|
110
|
+
response = DiscordApi.delete(url, headers)
|
111
|
+
return response unless response.status != 204
|
112
|
+
|
113
|
+
@logger.error("Failed to delete user reaction with emoji ID #{emoji_id} in channel with ID #{channel_id} " \
|
114
|
+
"for message with ID #{message_id} by user with ID #{user_id}. Response: #{response.body}")
|
115
|
+
response
|
116
|
+
end
|
117
|
+
|
118
|
+
def get_reactions(channel_id, message_id, emoji_id, type: nil, after: nil, limit: nil)
|
119
|
+
query_string_hash = {}
|
120
|
+
query_string_hash[:type] = type unless type.nil?
|
121
|
+
query_string_hash[:after] = after unless after.nil?
|
122
|
+
query_string_hash[:limit] = limit unless limit.nil?
|
123
|
+
query_string = DiscordApi.handle_query_strings(query_string_hash)
|
124
|
+
url = "#{@base_url}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji_id}#{query_string}"
|
125
|
+
headers = { 'Authorization': @authorization_header }
|
126
|
+
response = DiscordApi.get(url, headers)
|
127
|
+
return response unless response.status != 200
|
128
|
+
|
129
|
+
@logger.error("Failed to get reactions for emoji with ID #{emoji_id} in channel with ID #{channel_id} " \
|
130
|
+
"for message with ID #{message_id}. Response: #{response.body}")
|
131
|
+
response
|
132
|
+
end
|
133
|
+
|
134
|
+
def delete_all_reactions(channel_id, message_id)
|
135
|
+
url = "#{@base_url}/channels/#{channel_id}/messages/#{message_id}/reactions"
|
136
|
+
headers = { 'Authorization': @authorization_header }
|
137
|
+
response = DiscordApi.delete(url, headers)
|
138
|
+
return response unless response.status != 204
|
139
|
+
|
140
|
+
@logger.error("Failed to delete all reactions in channel with ID #{channel_id} for message with ID #{message_id}" \
|
141
|
+
". Response: #{response.body}")
|
142
|
+
end
|
143
|
+
|
144
|
+
def delete_all_reactions_for_emoji(channel_id, message_id, emoji_id)
|
145
|
+
url = "#{@base_url}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji_id}"
|
146
|
+
headers = { 'Authorization': @authorization_header }
|
147
|
+
response = DiscordApi.delete(url, headers)
|
148
|
+
return response unless response.status != 204
|
149
|
+
|
150
|
+
@logger.error("Failed to delete all reactions for emoji with ID #{emoji_id} in channel with ID #{channel_id} for " \
|
151
|
+
"message with ID #{message_id}. Response: #{response.body}")
|
152
|
+
end
|
153
|
+
|
154
|
+
def edit_message(channel_id, message_id, content: nil, embeds: nil, flags: nil, allowed_mentions: nil,
|
155
|
+
components: nil, files: nil, payload_json: nil, attachments: nil)
|
156
|
+
if args[2..].all?(&:nil?)
|
157
|
+
@logger.warn("No modifications provided for message with ID #{message_id} in channel with ID #{channel_id}. " \
|
158
|
+
'Skipping function.')
|
159
|
+
return nil
|
160
|
+
end
|
161
|
+
output = {}
|
162
|
+
output[:content] = content unless content.nil?
|
163
|
+
output[:embeds] = embeds unless embeds.nil?
|
164
|
+
output[:flags] = flags unless flags.nil?
|
165
|
+
output[:allowed_mentions] = allowed_mentions unless allowed_mentions.nil?
|
166
|
+
output[:components] = components unless components.nil?
|
167
|
+
output[:files] = files unless files.nil?
|
168
|
+
output[:payload_json] = payload_json unless payload_json.nil?
|
169
|
+
output[:attachments] = attachments unless attachments.nil?
|
170
|
+
url = "#{@base_url}/channels/#{channel_id}/messages/#{message_id}"
|
171
|
+
data = JSON.generate(output)
|
172
|
+
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
173
|
+
response = DiscordApi.patch(url, data, headers)
|
174
|
+
return response unless response.status != 200
|
175
|
+
|
176
|
+
@logger.error("Failed to edit message with ID #{message_id} in channel with ID #{channel_id}. " \
|
177
|
+
"Response: #{response.body}")
|
178
|
+
response
|
179
|
+
end
|
180
|
+
|
181
|
+
def delete_message(channel_id, message_id, audit_reason = nil)
|
182
|
+
url = "#{@base_url}/channels/#{channel_id}/messages/#{message_id}"
|
183
|
+
headers = { 'Authorization': @authorization_header }
|
184
|
+
headers[:'X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
185
|
+
response = DiscordApi.delete(url, headers)
|
186
|
+
return response unless response.status != 204
|
187
|
+
|
188
|
+
@logger.error("Failed to delete message with ID #{message_id} in channel with ID #{channel_id}. " \
|
189
|
+
"Response: #{response.body}")
|
190
|
+
response
|
191
|
+
end
|
192
|
+
|
193
|
+
def bulk_delete_messages(channel_id, messages, audit_reason = nil)
|
194
|
+
output = { messages: messages }
|
195
|
+
url = "#{@base_url}/channels/#{channel_id}/messages/bulk-delete"
|
196
|
+
data = JSON.generate(output)
|
197
|
+
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
198
|
+
headers[:'X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
199
|
+
response = DiscordApi.post(url, data, headers)
|
200
|
+
return response unless response.status != 204
|
201
|
+
|
202
|
+
@logger.error("Failed to bulk delete messages in channel with ID #{channel_id}. Response: #{response.body}")
|
203
|
+
response
|
204
|
+
end
|
205
|
+
|
206
|
+
def get_channel_pins(channel_id, before: nil, limit: nil)
|
207
|
+
query_string_hash = {}
|
208
|
+
query_string_hash[:before] = before unless before.nil?
|
209
|
+
query_string_hash[:limit] = limit unless limit.nil?
|
210
|
+
query_string = DiscordApi.handle_query_strings(query_string_hash)
|
211
|
+
url = "#{@base_url}/channels/#{channel_id}/messages/pins#{query_string}"
|
212
|
+
headers = { 'Authorization': @authorization_header }
|
213
|
+
response = DiscordApi.get(url, headers)
|
214
|
+
return response unless response.status != 200
|
215
|
+
|
216
|
+
@logger.error("Failed to get pinned messages in channel with ID #{channel_id}. Response: #{response.body}")
|
217
|
+
response
|
218
|
+
end
|
219
|
+
|
220
|
+
def pin_message(channel_id, message_id, audit_reason = nil)
|
221
|
+
url = "#{@base_url}/channels/#{channel_id}/messages/pins/#{message_id}"
|
222
|
+
headers = { 'Authorization': @authorization_header }
|
223
|
+
headers[:'X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
224
|
+
response = DiscordApi.put(url, nil, headers)
|
225
|
+
return response unless response.status != 204
|
226
|
+
|
227
|
+
@logger.error("Failed to pin message with ID #{message_id} in channel with ID #{channel_id}. " \
|
228
|
+
"Response: #{response.body}")
|
229
|
+
response
|
230
|
+
end
|
231
|
+
|
232
|
+
def unpin_message(channel_id, message_id, audit_reason = nil)
|
233
|
+
url = "#{@base_url}/channels/#{channel_id}/messages/pins/#{message_id}"
|
234
|
+
headers = { 'Authorization': @authorization_header }
|
235
|
+
headers[:'X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
236
|
+
response = DiscordApi.delete(url, headers)
|
237
|
+
return response unless response.status != 204
|
238
|
+
|
239
|
+
@logger.error("Failed to unpin message with ID #{message_id} in channel with ID #{channel_id}. " \
|
240
|
+
"Response: #{response.body}")
|
241
|
+
response
|
242
|
+
end
|
36
243
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: disrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hoovad
|
@@ -94,7 +94,7 @@ files:
|
|
94
94
|
- lib/disrb/logger.rb
|
95
95
|
- lib/disrb/message.rb
|
96
96
|
- lib/disrb/user.rb
|
97
|
-
homepage: https://
|
97
|
+
homepage: https://github.com/hoovad/discord.rb
|
98
98
|
licenses:
|
99
99
|
- MIT
|
100
100
|
metadata: {}
|