fluxerrb 0.1.0 → 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 +1 -1
- data/lib/fluxerrb/client.rb +56 -6
- data/lib/fluxerrb/version.rb +1 -1
- data/lib/fluxerrb/webhooks.rb +1 -1
- 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
|
|
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
|
|
|
@@ -213,12 +216,27 @@ module Fluxerrb
|
|
|
213
216
|
request('patch', "/channels/#{channel_id}/messages/#{message_id}", payload)
|
|
214
217
|
end
|
|
215
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
|
+
|
|
216
228
|
def get_channel(channel_id)
|
|
217
229
|
request('get', "/channels/#{channel_id}")
|
|
218
230
|
end
|
|
219
231
|
def get_guild(guild_id)
|
|
220
232
|
request('get', "/guilds/#{guild_id}")
|
|
221
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
|
|
222
240
|
def get_user(user_id)
|
|
223
241
|
request('get', "/users/#{user_id}")
|
|
224
242
|
end
|
|
@@ -231,6 +249,14 @@ module Fluxerrb
|
|
|
231
249
|
def timeout_user(guild_id, user_id, communcation_disabled_until)
|
|
232
250
|
modify_guild_member(guild_id, user_id, { communication_disabled_until: communcation_disabled_until })
|
|
233
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
|
|
234
260
|
|
|
235
261
|
def nsfw?(channel_or_id)
|
|
236
262
|
channel_data = channel_or_id.is_a?(Hash) ? channel_or_id : get_channel(channel_or_id)
|
|
@@ -244,6 +270,30 @@ module Fluxerrb
|
|
|
244
270
|
author_id.to_s == target_id.to_s
|
|
245
271
|
end
|
|
246
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
|
+
|
|
247
297
|
def get_webhook(webhook_id)
|
|
248
298
|
request('get', "/webhooks/#{webhook_id}")
|
|
249
299
|
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
|
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.
|
|
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:
|