fluxerrb 0.0.1 → 0.1.0
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 +1 -1
- data/lib/fluxerrb/client.rb +47 -1
- data/lib/fluxerrb/version.rb +1 -1
- data/lib/fluxerrb/webhooks.rb +49 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 321e207b8f64f41433dec714576ad793894425db42825c5eaca8a4322969ffc5
|
|
4
|
+
data.tar.gz: 8f34c1cbcbd38b509134b03b4c77ec069dc64e8d992b05086a8da7d0679b5f49
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b693dfa3abdbc10e4becf1e60b4563acea3a5111138263d02ebcc462c27bca91fcc3307206218be10569a3c9a6a6831b375cb8fe8c48b922dbd8dfcbb449ca4c
|
|
7
|
+
data.tar.gz: febde934783ad50adf734d3d79ed99ffaaa9ab191c369d4ef391530de4b2201f544f3e6f4a0cb28ff90ff83d1bf6bf8461903a85be275e5e43ee4a4f99e518bc
|
data/README.md
CHANGED
|
@@ -19,7 +19,7 @@ Add the following to your Gemfile file and run the "[bundle install](https://rub
|
|
|
19
19
|
gem 'fluxerrb'
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
or add the following to your Gemfile file to install with Git.
|
|
22
|
+
or add the following to your Gemfile file to install with Git (Do note that you may be installing dev builds which may be unstable when installing through git).
|
|
23
23
|
|
|
24
24
|
```ruby
|
|
25
25
|
gem 'fluxerrb', git: 'https://codeberg.org/roxannewolf/fluxerrb'
|
data/lib/fluxerrb/client.rb
CHANGED
|
@@ -181,18 +181,57 @@ module Fluxerrb
|
|
|
181
181
|
JSON.parse(response.body) rescue response.body
|
|
182
182
|
end
|
|
183
183
|
|
|
184
|
+
|
|
184
185
|
def send_message(channel_id, content = "", embed = nil)
|
|
185
186
|
payload = {}
|
|
186
187
|
payload[:content] = content unless content.empty?
|
|
187
|
-
|
|
188
|
+
if embed
|
|
189
|
+
embed_array = embed.is_a?(Array) ? embed : [embed]
|
|
190
|
+
payload[:embed] = embed if embed.is_a?(Hash)
|
|
191
|
+
payload[:embeds] = embed_array
|
|
192
|
+
end
|
|
188
193
|
request('post', "/channels/#{channel_id}/messages", payload)
|
|
189
194
|
end
|
|
195
|
+
def forward_message(target_channel_id, source_channel_id, message_id)
|
|
196
|
+
payload = {
|
|
197
|
+
message_reference: {
|
|
198
|
+
message_id: message_id.to_s,
|
|
199
|
+
channel_id: source_channel_id.to_s,
|
|
200
|
+
type: 1
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
request('post', "/channels/#{target_channel_id}/messages", payload)
|
|
204
|
+
end
|
|
205
|
+
def edit_message(channel_id, message_id, content = "", embed = nil)
|
|
206
|
+
payload = {}
|
|
207
|
+
payload[:content] = content unless content.nil?
|
|
208
|
+
if embed
|
|
209
|
+
embed_array = embed.is_a?(Array) ? embed : [embed]
|
|
210
|
+
payload[:embed] = embed if embed.is_a?(Hash)
|
|
211
|
+
payload[:embeds] = embed_array
|
|
212
|
+
end
|
|
213
|
+
request('patch', "/channels/#{channel_id}/messages/#{message_id}", payload)
|
|
214
|
+
end
|
|
215
|
+
|
|
190
216
|
def get_channel(channel_id)
|
|
191
217
|
request('get', "/channels/#{channel_id}")
|
|
192
218
|
end
|
|
193
219
|
def get_guild(guild_id)
|
|
194
220
|
request('get', "/guilds/#{guild_id}")
|
|
195
221
|
end
|
|
222
|
+
def get_user(user_id)
|
|
223
|
+
request('get', "/users/#{user_id}")
|
|
224
|
+
end
|
|
225
|
+
def modify_guild_member(guild_id, user_id, options = {})
|
|
226
|
+
request('patch', "/guilds/#{guild_id}/members/#{user_id}", options)
|
|
227
|
+
end
|
|
228
|
+
def set_nickname(guild_id, user_id, nickname)
|
|
229
|
+
modify_guild_member(guild_id, user_id, { nick: nickname })
|
|
230
|
+
end
|
|
231
|
+
def timeout_user(guild_id, user_id, communcation_disabled_until)
|
|
232
|
+
modify_guild_member(guild_id, user_id, { communication_disabled_until: communcation_disabled_until })
|
|
233
|
+
end
|
|
234
|
+
|
|
196
235
|
def nsfw?(channel_or_id)
|
|
197
236
|
channel_data = channel_or_id.is_a?(Hash) ? channel_or_id : get_channel(channel_or_id)
|
|
198
237
|
!!channel_data['nsfw']
|
|
@@ -204,5 +243,12 @@ module Fluxerrb
|
|
|
204
243
|
def user_id?(author_id, target_id)
|
|
205
244
|
author_id.to_s == target_id.to_s
|
|
206
245
|
end
|
|
246
|
+
|
|
247
|
+
def get_webhook(webhook_id)
|
|
248
|
+
request('get', "/webhooks/#{webhook_id}")
|
|
249
|
+
end
|
|
250
|
+
def delete_webhook(webhook_id)
|
|
251
|
+
request('delete', "/webhooks/#{webhook_id}")
|
|
252
|
+
end
|
|
207
253
|
end
|
|
208
254
|
end
|
data/lib/fluxerrb/version.rb
CHANGED
data/lib/fluxerrb/webhooks.rb
CHANGED
|
@@ -22,12 +22,20 @@ module Fluxerrb
|
|
|
22
22
|
new(base_url: base, id: id, token: token)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
def send_message(content, extra_params = {})
|
|
25
|
+
def send_message(content="", embed = nil, extra_params = {})
|
|
26
26
|
raise "[fluxerrb]: Webhook ID/Token not set" unless @webhook_id && @webhook_token
|
|
27
|
-
|
|
28
27
|
path = "/webhooks/#{@webhook_id}/#{@webhook_token}"
|
|
29
28
|
uri = URI("#{@base_url}#{path}")
|
|
30
|
-
|
|
29
|
+
|
|
30
|
+
payload = {}
|
|
31
|
+
payload[:content] = content unless content.nil? || content.empty?
|
|
32
|
+
if embed
|
|
33
|
+
embed_array = embed.is_a?(Array) ? embed : [embed]
|
|
34
|
+
payload[:embed] = embed if embed.is_a?(Hash)
|
|
35
|
+
payload[:embeds] = embed_array
|
|
36
|
+
end
|
|
37
|
+
payload = payload.merge(extra_params) unless extra_params.empty?
|
|
38
|
+
|
|
31
39
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
32
40
|
if uri.scheme == 'https'
|
|
33
41
|
http.use_ssl = true
|
|
@@ -44,5 +52,43 @@ module Fluxerrb
|
|
|
44
52
|
|
|
45
53
|
response.code.to_i == 200 || response.code.to_i == 204
|
|
46
54
|
end
|
|
55
|
+
|
|
56
|
+
def get_info
|
|
57
|
+
raise "[fluxerrb]: Webhook ID/Token not set" unless @webhook_id && @webhook_token
|
|
58
|
+
path = "/webhooks/#{@webhook_id}/#{@webhook_token}"
|
|
59
|
+
uri = URI("#{@base_url}#{path}")
|
|
60
|
+
|
|
61
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
62
|
+
http.use_ssl = true if uri.scheme == 'https'
|
|
63
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
64
|
+
req = Net::HTTP::Get.new(uri.path, { 'Content-Type' => 'application/json' })
|
|
65
|
+
response = http.request(req)
|
|
66
|
+
|
|
67
|
+
if response.code.to_i == 429
|
|
68
|
+
puts "[fluxerrb]: AN ERROR HAS OCCURED: 429 Ratelimit."
|
|
69
|
+
return false
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
JSON.parse(response.body) rescue response.body
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def delete
|
|
76
|
+
raise "[fluxerrb]: Webhook ID/Token not set" unless @webhook_id && @webhook_token
|
|
77
|
+
path = "/webhooks/#{@webhook_id}/#{@webhook_token}"
|
|
78
|
+
uri = URI("#{@base_url}#{path}")
|
|
79
|
+
|
|
80
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
81
|
+
http.use_ssl = true if uri.scheme == 'https'
|
|
82
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
83
|
+
req = Net::HTTP::Delete.new(uri.path, { 'Content-Type' => 'application/json' })
|
|
84
|
+
response = http.request(req)
|
|
85
|
+
|
|
86
|
+
if response.code.to_i == 429
|
|
87
|
+
puts "[fluxerrb]: AN ERROR HAS OCCURED: 429 Ratelimit."
|
|
88
|
+
return false
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
response.code.to_i == 204 || response.code.to_i == 200
|
|
92
|
+
end
|
|
47
93
|
end
|
|
48
94
|
end
|