fluxerrb 0.0.1 → 0.2.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 +2 -2
- data/lib/fluxerrb/client.rb +103 -7
- data/lib/fluxerrb/version.rb +1 -1
- data/lib/fluxerrb/webhooks.rb +50 -4
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ce3d30732d6071dd57a8ba75bdc0243f23a0c24bf073e8ec08aa672b6f6bfb32
|
|
4
|
+
data.tar.gz: 4784b13a5d1861e7287523bcf34278db32b8d0bf6fb7ad5955ff8e510de64eb6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9c694a010ea1a056ac8e55f415a4a8d06ad96c58f4df0cace80381d5aa50b37dd4d0e90dafcda9107b07df2b350ca4d48d670f631ccd09bebda9807158676977
|
|
7
|
+
data.tar.gz: 49a78789ffc81af64ce102e0e1ef15bf1d7364d6f2a8ed82ff4634736aef1d6bc31f1e2e57d33f1522d37098f1de72d4afd37c93c3fddacea30dc6f6be740025
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# fluxerrb
|
|
2
2
|
|
|
3
|
-
Fluxerrb is a Ruby package (a.k.a. Gem) that allows you to make Fluxer.
|
|
3
|
+
Fluxerrb is a Ruby package (a.k.a. Gem) that allows you to make Fluxer.com bots and use Fluxer.com webhooks using the Ruby programming language. This package (a.k.a. Gem) is not officially endorsed by fluxer.com and this is not an official fluxer.com product.
|
|
4
4
|
|
|
5
5
|
You need Ruby 3.0 or newer in order to use this package (Ruby 3.2 or newer is recommended)
|
|
6
6
|
|
|
@@ -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
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
require 'net/http'
|
|
3
3
|
require 'json'
|
|
4
4
|
require 'websocket-client-simple'
|
|
5
|
+
require 'erb'
|
|
5
6
|
|
|
6
7
|
module Fluxerrb
|
|
7
8
|
class Bot
|
|
8
9
|
attr_accessor :base_url, :token, :prefix, :reconnect_attempts
|
|
9
10
|
|
|
10
11
|
def initialize(config = {})
|
|
11
|
-
@base_url = config[:base_url] || 'https://
|
|
12
|
-
@gateway_url = config[:gateway_url] || 'wss://gateway.fluxer.
|
|
12
|
+
@base_url = config[:base_url] || 'https://fluxer.com/api/v1'
|
|
13
|
+
@gateway_url = config[:gateway_url] || 'wss://gateway.fluxer.com/?v=1'
|
|
13
14
|
@token = config[:token]
|
|
14
15
|
@prefix = config[:prefix] || '!'
|
|
15
16
|
|
|
@@ -90,7 +91,7 @@ module Fluxerrb
|
|
|
90
91
|
@heartbeat_thread = Thread.new do
|
|
91
92
|
loop do
|
|
92
93
|
sleep interval
|
|
93
|
-
puts "[fluxerrb]: Sending heartbeat (Sequence: #{@sequence})..."
|
|
94
|
+
# puts "[fluxerrb]: Sending heartbeat (Sequence: #{@sequence})..."
|
|
94
95
|
send_payload(1, @sequence)
|
|
95
96
|
end
|
|
96
97
|
end
|
|
@@ -156,7 +157,7 @@ module Fluxerrb
|
|
|
156
157
|
|
|
157
158
|
public
|
|
158
159
|
|
|
159
|
-
def request(method, path, body = nil)
|
|
160
|
+
def request(method, path, body = nil, custom_headers = {})
|
|
160
161
|
uri = URI("#{@base_url}#{path}")
|
|
161
162
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
162
163
|
if uri.scheme == 'https'
|
|
@@ -165,10 +166,12 @@ module Fluxerrb
|
|
|
165
166
|
end
|
|
166
167
|
|
|
167
168
|
req_class = Object.const_get("Net::HTTP::#{method.capitalize}")
|
|
168
|
-
|
|
169
|
+
headers = {
|
|
169
170
|
'Authorization' => "Bot #{@token}",
|
|
170
171
|
'Content-Type' => 'application/json'
|
|
171
|
-
})
|
|
172
|
+
}.merge(custom_headers)
|
|
173
|
+
|
|
174
|
+
req = req_class.new(uri.path, headers)
|
|
172
175
|
req.body = body.to_json if body
|
|
173
176
|
response = http.request(req)
|
|
174
177
|
|
|
@@ -181,18 +184,80 @@ module Fluxerrb
|
|
|
181
184
|
JSON.parse(response.body) rescue response.body
|
|
182
185
|
end
|
|
183
186
|
|
|
187
|
+
|
|
184
188
|
def send_message(channel_id, content = "", embed = nil)
|
|
185
189
|
payload = {}
|
|
186
190
|
payload[:content] = content unless content.empty?
|
|
187
|
-
|
|
191
|
+
if embed
|
|
192
|
+
embed_array = embed.is_a?(Array) ? embed : [embed]
|
|
193
|
+
payload[:embed] = embed if embed.is_a?(Hash)
|
|
194
|
+
payload[:embeds] = embed_array
|
|
195
|
+
end
|
|
188
196
|
request('post', "/channels/#{channel_id}/messages", payload)
|
|
189
197
|
end
|
|
198
|
+
def forward_message(target_channel_id, source_channel_id, message_id)
|
|
199
|
+
payload = {
|
|
200
|
+
message_reference: {
|
|
201
|
+
message_id: message_id.to_s,
|
|
202
|
+
channel_id: source_channel_id.to_s,
|
|
203
|
+
type: 1
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
request('post', "/channels/#{target_channel_id}/messages", payload)
|
|
207
|
+
end
|
|
208
|
+
def edit_message(channel_id, message_id, content = "", embed = nil)
|
|
209
|
+
payload = {}
|
|
210
|
+
payload[:content] = content unless content.nil?
|
|
211
|
+
if embed
|
|
212
|
+
embed_array = embed.is_a?(Array) ? embed : [embed]
|
|
213
|
+
payload[:embed] = embed if embed.is_a?(Hash)
|
|
214
|
+
payload[:embeds] = embed_array
|
|
215
|
+
end
|
|
216
|
+
request('patch', "/channels/#{channel_id}/messages/#{message_id}", payload)
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
def create_reaction(channel_id, message_id, emoji)
|
|
220
|
+
encoded_emoji = ERB::Util.url_encode(emoji)
|
|
221
|
+
request('put', "/channels/#{channel_id}/messages/#{message_id}/reactions/#{encoded_emoji}/@me")
|
|
222
|
+
end
|
|
223
|
+
def delete_reaction(channel_id, message_id, emoji, user_id = "@me")
|
|
224
|
+
encoded_emoji = ERB::Util.url_encode(emoji)
|
|
225
|
+
request('delete', "/channels/#{channel_id}/messages/#{message_id}/reactions/#{encoded_emoji}/#{user_id}")
|
|
226
|
+
end
|
|
227
|
+
|
|
190
228
|
def get_channel(channel_id)
|
|
191
229
|
request('get', "/channels/#{channel_id}")
|
|
192
230
|
end
|
|
193
231
|
def get_guild(guild_id)
|
|
194
232
|
request('get', "/guilds/#{guild_id}")
|
|
195
233
|
end
|
|
234
|
+
def get_emoji(emoji_id)
|
|
235
|
+
request('get', "/emojis/#{emoji_id}/metadata")
|
|
236
|
+
end
|
|
237
|
+
def get_sticker(sticker_id)
|
|
238
|
+
request('get', "/stickers/#{sticker_id}/metadata")
|
|
239
|
+
end
|
|
240
|
+
def get_user(user_id)
|
|
241
|
+
request('get', "/users/#{user_id}")
|
|
242
|
+
end
|
|
243
|
+
def modify_guild_member(guild_id, user_id, options = {})
|
|
244
|
+
request('patch', "/guilds/#{guild_id}/members/#{user_id}", options)
|
|
245
|
+
end
|
|
246
|
+
def set_nickname(guild_id, user_id, nickname)
|
|
247
|
+
modify_guild_member(guild_id, user_id, { nick: nickname })
|
|
248
|
+
end
|
|
249
|
+
def timeout_user(guild_id, user_id, communcation_disabled_until)
|
|
250
|
+
modify_guild_member(guild_id, user_id, { communication_disabled_until: communcation_disabled_until })
|
|
251
|
+
end
|
|
252
|
+
def add_guild_member_role(guild_id, user_id, role_id, reason = nil)
|
|
253
|
+
headers = reason ? { 'X-Audit-Reason' => reason } : {}
|
|
254
|
+
request('put', "/guilds/#{guild_id}/members/#{user_id}/roles/#{role_id}", nil, headers)
|
|
255
|
+
end
|
|
256
|
+
def remove_guild_member_role(guild_id, user_id, role_id, reason = nil)
|
|
257
|
+
headers = reason ? { 'X-Audit-Reason' => reason } : {}
|
|
258
|
+
request('delete', "/guilds/#{guild_id}/members/#{user_id}/roles/#{role_id}", nil, headers)
|
|
259
|
+
end
|
|
260
|
+
|
|
196
261
|
def nsfw?(channel_or_id)
|
|
197
262
|
channel_data = channel_or_id.is_a?(Hash) ? channel_or_id : get_channel(channel_or_id)
|
|
198
263
|
!!channel_data['nsfw']
|
|
@@ -204,5 +269,36 @@ module Fluxerrb
|
|
|
204
269
|
def user_id?(author_id, target_id)
|
|
205
270
|
author_id.to_s == target_id.to_s
|
|
206
271
|
end
|
|
272
|
+
|
|
273
|
+
def create_forum_post(channel_id, name, content = "", embed = nil, applied_tags = [])
|
|
274
|
+
payload = {
|
|
275
|
+
name: name,
|
|
276
|
+
message: {}
|
|
277
|
+
}
|
|
278
|
+
payload[:message][:content] = content unless content.empty?
|
|
279
|
+
if embed
|
|
280
|
+
embed_array = embed.is_a?(Array) ? embed : [embed]
|
|
281
|
+
payload[:message][:embed] = embed if embed.is_a?(Hash)
|
|
282
|
+
payload[:message][:embeds] = embed_array
|
|
283
|
+
end
|
|
284
|
+
payload[:applied_tags] = applied_tags unless applied_tags.empty?
|
|
285
|
+
request('post', "/channels/#{channel_id}/threads", payload)
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
def create_thread(channel_id, name, auto_archive_duration = 1440, type = 11)
|
|
289
|
+
payload = {
|
|
290
|
+
name: name,
|
|
291
|
+
auto_archive_duration: auto_archive_duration,
|
|
292
|
+
type: type
|
|
293
|
+
}
|
|
294
|
+
request('post', "/channels/#{channel_id}/threads", payload)
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
def get_webhook(webhook_id)
|
|
298
|
+
request('get', "/webhooks/#{webhook_id}")
|
|
299
|
+
end
|
|
300
|
+
def delete_webhook(webhook_id)
|
|
301
|
+
request('delete', "/webhooks/#{webhook_id}")
|
|
302
|
+
end
|
|
207
303
|
end
|
|
208
304
|
end
|
data/lib/fluxerrb/version.rb
CHANGED
data/lib/fluxerrb/webhooks.rb
CHANGED
|
@@ -6,7 +6,7 @@ module Fluxerrb
|
|
|
6
6
|
class Webhook
|
|
7
7
|
attr_accessor :base_url, :webhook_id, :webhook_token
|
|
8
8
|
def initialize(config = {})
|
|
9
|
-
@base_url = config[:base_url] || 'https://
|
|
9
|
+
@base_url = config[:base_url] || 'https://fluxer.com/api/v1'
|
|
10
10
|
@webhook_id = config[:id]
|
|
11
11
|
@webhook_token = config[:token]
|
|
12
12
|
end
|
|
@@ -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
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fluxerrb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Roxanne Studios
|
|
@@ -43,14 +43,14 @@ dependencies:
|
|
|
43
43
|
requirements:
|
|
44
44
|
- - "~>"
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
|
-
version:
|
|
46
|
+
version: 0.9.0
|
|
47
47
|
type: :runtime
|
|
48
48
|
prerelease: false
|
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
50
50
|
requirements:
|
|
51
51
|
- - "~>"
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
|
-
version:
|
|
53
|
+
version: 0.9.0
|
|
54
54
|
description: The first Ruby package (a.k.a. gem) to exist for making Fluxer.app bots
|
|
55
55
|
and using Fluxer.app webhooks. This project is not officially endorsed by Fluxer.app
|
|
56
56
|
email:
|