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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1afcd0591253a04f54e8458bcb1a51733f78ecf3afdb7a47a3a22fca8f61949
4
- data.tar.gz: 34ca494197af5511d3ef6f73c7358f6529a8554d9285701e1272b8bf9b9dce0a
3
+ metadata.gz: 321e207b8f64f41433dec714576ad793894425db42825c5eaca8a4322969ffc5
4
+ data.tar.gz: 8f34c1cbcbd38b509134b03b4c77ec069dc64e8d992b05086a8da7d0679b5f49
5
5
  SHA512:
6
- metadata.gz: 924dca7689bbd5ccca3b6c917c520597d0f8e9c266becb438232d1572d2a71b1374b345361eac0b26c0904e1d6731ca63356d91a2379518fe4c5b232f6d5f047
7
- data.tar.gz: b56704e5a38fde8f804a0f652f1495c2b6c4b9739e724ed286abf0e908e93e31d8d99f40b4966be4bb9146438ff8b1ebbcd6d42bc116d7ca26ac59b7c33114ac
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'
@@ -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
- payload[:embed] = embed if embed
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
@@ -1,3 +1,3 @@
1
1
  module FluxerrbVersion
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  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
- payload = { content: content }.merge(extra_params)
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.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roxanne Studios