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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 321e207b8f64f41433dec714576ad793894425db42825c5eaca8a4322969ffc5
4
- data.tar.gz: 8f34c1cbcbd38b509134b03b4c77ec069dc64e8d992b05086a8da7d0679b5f49
3
+ metadata.gz: ce3d30732d6071dd57a8ba75bdc0243f23a0c24bf073e8ec08aa672b6f6bfb32
4
+ data.tar.gz: 4784b13a5d1861e7287523bcf34278db32b8d0bf6fb7ad5955ff8e510de64eb6
5
5
  SHA512:
6
- metadata.gz: b693dfa3abdbc10e4becf1e60b4563acea3a5111138263d02ebcc462c27bca91fcc3307206218be10569a3c9a6a6831b375cb8fe8c48b922dbd8dfcbb449ca4c
7
- data.tar.gz: febde934783ad50adf734d3d79ed99ffaaa9ab191c369d4ef391530de4b2201f544f3e6f4a0cb28ff90ff83d1bf6bf8461903a85be275e5e43ee4a4f99e518bc
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.app bots and use Fluxer.app webhooks using the Ruby programming language. This package (a.k.a. Gem) is not officially endorsed by fluxer.app and this is not an official fluxer.app product.
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
 
@@ -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://api.fluxer.app/v1'
12
- @gateway_url = config[:gateway_url] || 'wss://gateway.fluxer.app/?v=1'
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
- req = req_class.new(uri.path, {
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
@@ -1,3 +1,3 @@
1
1
  module FluxerrbVersion
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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://api.fluxer.app/v1'
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.1.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: '0.3'
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: '0.3'
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: