discordrb-webhooks 0.1.0 → 3.4.2

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
- SHA1:
3
- metadata.gz: 6e33e989ed634c58e7bec8ee4b270addbaf2afb1
4
- data.tar.gz: d75947052d5ba2f4047622e65d3a83a829cfbc05
2
+ SHA256:
3
+ metadata.gz: 44effaadc7c29e9e3e22abf7c4d01ba2a93495383de144e30816a41ed4c630b1
4
+ data.tar.gz: 6a5313cd404e6bf577cc2a34809ce5df22c17d1be58fcc65b0abb75cb99f1d1d
5
5
  SHA512:
6
- metadata.gz: '0093a27a7257c39ebb0f27d756be7c682e58a2479d7ec6a7bdaca72a1d251d36794ec5b503cd4ddc1d738f5fa91ae2170aa69fd1c334a944eac73078e54e96f9'
7
- data.tar.gz: 5781b554604a09ea88afb284c4cb522c16581ac4855974f71c54462a67ae89cce117f5c23c62ba2ba5bc0be3d1198e5ae346036b3b58e9207d7f50e06ee6540d
6
+ metadata.gz: 98da4d01dc7e8f50a3a6a7923a7eedd194f75fcdd1dd2256b076faff2813d2d919e9de0feefb79224ebb851aab0f75c305094cf4fd9354e4bf5eb73d0aadea71
7
+ data.tar.gz: 0a8a29adc73d9dd6c577c045a23f908a56925e44b6c90fccff84c9ae00a567318248b8ef19677c2f725f82ea910d56b5b083537ad0bdb0c1fb9df22b1e8dc69d
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'discordrb/webhooks/embeds'
2
4
 
3
5
  module Discordrb::Webhooks
@@ -35,6 +37,7 @@ module Discordrb::Webhooks
35
37
  # @param file [File] A file to be sent.
36
38
  def file=(file)
37
39
  raise ArgumentError, 'Embeds and files are mutually exclusive!' unless @embeds.empty?
40
+
38
41
  @file = file
39
42
  end
40
43
 
@@ -42,6 +45,7 @@ module Discordrb::Webhooks
42
45
  # @param embed [Embed] The embed to add.
43
46
  def <<(embed)
44
47
  raise ArgumentError, 'Embeds and files are mutually exclusive!' if @file
48
+
45
49
  @embeds << embed
46
50
  end
47
51
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rest-client'
2
4
  require 'json'
3
5
 
@@ -13,11 +15,7 @@ module Discordrb::Webhooks
13
15
  # @param token [String] The webhook's authorisation token. Will only be used
14
16
  # if `url` is not set.
15
17
  def initialize(url: nil, id: nil, token: nil)
16
- @url = if url
17
- url
18
- else
19
- generate_url(id, token)
20
- end
18
+ @url = url || generate_url(id, token)
21
19
  end
22
20
 
23
21
  # Executes the webhook this client points to with the given data.
@@ -66,7 +64,7 @@ module Discordrb::Webhooks
66
64
  end
67
65
 
68
66
  def generate_url(id, token)
69
- "https://discordapp.com/api/v6/webhooks/#{id}/#{token}"
67
+ "https://discord.com/api/v6/webhooks/#{id}/#{token}"
70
68
  end
71
69
  end
72
70
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Discordrb::Webhooks
2
4
  # An embed is a multipart-style attachment to a webhook message that can have a variety of different purposes and
3
5
  # appearances.
@@ -8,7 +10,7 @@ module Discordrb::Webhooks
8
10
  @description = description
9
11
  @url = url
10
12
  @timestamp = timestamp
11
- @colour = colour || color
13
+ self.colour = colour || color
12
14
  @footer = footer
13
15
  @image = image
14
16
  @thumbnail = thumbnail
@@ -18,68 +20,66 @@ module Discordrb::Webhooks
18
20
  @fields = fields
19
21
  end
20
22
 
21
- # The title of this embed that will be displayed above everything else.
22
- # @return [String]
23
+ # @return [String, nil] title of the embed that will be displayed above everything else.
23
24
  attr_accessor :title
24
25
 
25
- # The description for this embed.
26
- # @return [String]
26
+ # @return [String, nil] description for this embed
27
27
  attr_accessor :description
28
28
 
29
- # The URL the title should point to.
30
- # @return [String]
29
+ # @return [String, nil] URL the title should point to
31
30
  attr_accessor :url
32
31
 
33
- # The timestamp for this embed. Will be displayed just below the title.
34
- # @return [Time]
32
+ # @return [Time, nil] timestamp for this embed. Will be displayed just below the title.
35
33
  attr_accessor :timestamp
36
34
 
37
- # @return [Integer] the colour of the bar to the side, in decimal form.
35
+ # @return [Integer, nil] the colour of the bar to the side, in decimal form
38
36
  attr_reader :colour
39
37
  alias_method :color, :colour
40
38
 
41
39
  # Sets the colour of the bar to the side of the embed to something new.
42
- # @param value [Integer, String, {Integer, Integer, Integer}] The colour in decimal, hexadecimal, or R/G/B decimal
40
+ # @param value [String, Integer, {Integer, Integer, Integer}, #to_i, nil] The colour in decimal, hexadecimal, R/G/B decimal, or nil to clear the embeds colour
43
41
  # form.
44
42
  def colour=(value)
45
- if value.is_a? Integer
43
+ if value.nil?
44
+ @colour = nil
45
+ elsif value.is_a? Integer
46
46
  raise ArgumentError, 'Embed colour must be 24-bit!' if value >= 16_777_216
47
+
47
48
  @colour = value
48
49
  elsif value.is_a? String
49
50
  self.colour = value.delete('#').to_i(16)
50
51
  elsif value.is_a? Array
51
52
  raise ArgumentError, 'Colour tuple must have three values!' if value.length != 3
53
+
52
54
  self.colour = value[0] << 16 | value[1] << 8 | value[2]
55
+ else
56
+ self.colour = value.to_i
53
57
  end
54
58
  end
55
59
 
56
60
  alias_method :color=, :colour=
57
61
 
58
- # The footer for this embed.
59
62
  # @example Add a footer to an embed
60
63
  # embed.footer = Discordrb::Webhooks::EmbedFooter.new(text: 'Hello', icon_url: 'https://i.imgur.com/j69wMDu.jpg')
61
- # @return [EmbedFooter]
64
+ # @return [EmbedFooter, nil] footer for this embed
62
65
  attr_accessor :footer
63
66
 
64
- # The image for this embed.
65
67
  # @see EmbedImage
66
68
  # @example Add a image to an embed
67
69
  # embed.image = Discordrb::Webhooks::EmbedImage.new(url: 'https://i.imgur.com/PcMltU7.jpg')
68
- # @return [EmbedImage]
70
+ # @return [EmbedImage, nil] image for this embed
69
71
  attr_accessor :image
70
72
 
71
- # The thumbnail for this embed.
72
73
  # @see EmbedThumbnail
73
74
  # @example Add a thumbnail to an embed
74
75
  # embed.thumbnail = Discordrb::Webhooks::EmbedThumbnail.new(url: 'https://i.imgur.com/xTG3a1I.jpg')
75
- # @return [EmbedThumbnail]
76
+ # @return [EmbedThumbnail, nil] thumbnail for this embed
76
77
  attr_accessor :thumbnail
77
78
 
78
- # The author for this embed.
79
79
  # @see EmbedAuthor
80
80
  # @example Add a author to an embed
81
81
  # embed.author = Discordrb::Webhooks::EmbedAuthor.new(name: 'meew0', url: 'https://github.com/meew0', icon_url: 'https://avatars2.githubusercontent.com/u/3662915?v=3&s=466')
82
- # @return [EmbedAuthor]
82
+ # @return [EmbedAuthor, nil] author for this embed
83
83
  attr_accessor :author
84
84
 
85
85
  # Add a field object to this embed.
@@ -94,13 +94,13 @@ module Discordrb::Webhooks
94
94
  # embed.add_field(name: 'A field', value: "The field's content")
95
95
  # @param name [String] The field's name
96
96
  # @param value [String] The field's value
97
- # @param inline [true, false] Whether the field should be inlined
97
+ # @param inline [true, false] Whether the field should be inline
98
98
  def add_field(name: nil, value: nil, inline: nil)
99
99
  self << EmbedField.new(name: name, value: value, inline: inline)
100
100
  end
101
101
 
102
102
  # @return [Array<EmbedField>] the fields attached to this embed.
103
- attr_reader :fields
103
+ attr_accessor :fields
104
104
 
105
105
  # @return [Hash] a hash representation of this embed, to be converted to JSON.
106
106
  def to_hash
@@ -108,14 +108,14 @@ module Discordrb::Webhooks
108
108
  title: @title,
109
109
  description: @description,
110
110
  url: @url,
111
- timestamp: @timestamp && @timestamp.utc.iso8601,
111
+ timestamp: @timestamp&.utc&.iso8601,
112
112
  color: @colour,
113
- footer: @footer && @footer.to_hash,
114
- image: @image && @image.to_hash,
115
- thumbnail: @thumbnail && @thumbnail.to_hash,
116
- video: @video && @video.to_hash,
117
- provider: @provider && @provider.to_hash,
118
- author: @author && @author.to_hash,
113
+ footer: @footer&.to_hash,
114
+ image: @image&.to_hash,
115
+ thumbnail: @thumbnail&.to_hash,
116
+ video: @video&.to_hash,
117
+ provider: @provider&.to_hash,
118
+ author: @author&.to_hash,
119
119
  fields: @fields.map(&:to_hash)
120
120
  }
121
121
  end
@@ -124,6 +124,12 @@ module Discordrb::Webhooks
124
124
  # An embed's footer will be displayed at the very bottom of an embed, together with the timestamp. An icon URL can be
125
125
  # set together with some text to be displayed.
126
126
  class EmbedFooter
127
+ # @return [String, nil] text to be displayed in the footer
128
+ attr_accessor :text
129
+
130
+ # @return [String, nil] URL to an icon to be showed alongside the text
131
+ attr_accessor :icon_url
132
+
127
133
  # Creates a new footer object.
128
134
  # @param text [String, nil] The text to be displayed in the footer.
129
135
  # @param icon_url [String, nil] The URL to an icon to be showed alongside the text.
@@ -143,6 +149,9 @@ module Discordrb::Webhooks
143
149
 
144
150
  # An embed's image will be displayed at the bottom, in large format. It will replace a footer icon URL if one is set.
145
151
  class EmbedImage
152
+ # @return [String, nil] URL of the image
153
+ attr_accessor :url
154
+
146
155
  # Creates a new image object.
147
156
  # @param url [String, nil] The URL of the image.
148
157
  def initialize(url: nil)
@@ -160,6 +169,9 @@ module Discordrb::Webhooks
160
169
  # An embed's thumbnail will be displayed at the right of the message, next to the description and fields. When clicked
161
170
  # it will point to the embed URL.
162
171
  class EmbedThumbnail
172
+ # @return [String, nil] URL of the thumbnail
173
+ attr_accessor :url
174
+
163
175
  # Creates a new thumbnail object.
164
176
  # @param url [String, nil] The URL of the thumbnail.
165
177
  def initialize(url: nil)
@@ -176,6 +188,15 @@ module Discordrb::Webhooks
176
188
 
177
189
  # An embed's author will be shown at the top to indicate who "authored" the particular event the webhook was sent for.
178
190
  class EmbedAuthor
191
+ # @return [String, nil] name of the author
192
+ attr_accessor :name
193
+
194
+ # @return [String, nil] URL the name should link to
195
+ attr_accessor :url
196
+
197
+ # @return [String, nil] URL of the icon to be displayed next to the author
198
+ attr_accessor :icon_url
199
+
179
200
  # Creates a new author object.
180
201
  # @param name [String, nil] The name of the author.
181
202
  # @param url [String, nil] The URL the name should link to.
@@ -198,11 +219,20 @@ module Discordrb::Webhooks
198
219
 
199
220
  # A field is a small block of text with a header that can be relatively freely layouted with other fields.
200
221
  class EmbedField
222
+ # @return [String, nil] name of the field, displayed in bold at the top of the field.
223
+ attr_accessor :name
224
+
225
+ # @return [String, nil] value of the field, displayed in normal text below the name.
226
+ attr_accessor :value
227
+
228
+ # @return [true, false] whether the field should be displayed inline with other fields.
229
+ attr_accessor :inline
230
+
201
231
  # Creates a new field object.
202
- # @param name [String, nil] The name of the field, displayed in bold at the top.
232
+ # @param name [String, nil] The name of the field, displayed in bold at the top of the field.
203
233
  # @param value [String, nil] The value of the field, displayed in normal text below the name.
204
- # @param inline [true, false] Whether the field should be displayed in-line with other fields.
205
- def initialize(name: nil, value: nil, inline: nil)
234
+ # @param inline [true, false] Whether the field should be displayed inline with other fields.
235
+ def initialize(name: nil, value: nil, inline: false)
206
236
  @name = name
207
237
  @value = value
208
238
  @inline = inline
@@ -4,6 +4,6 @@
4
4
  module Discordrb
5
5
  module Webhooks
6
6
  # The current version of discordrb-webhooks.
7
- VERSION = '0.1.0'.freeze
7
+ VERSION = '3.4.2'
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discordrb-webhooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 3.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - meew0
8
+ - swarley
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2017-01-29 00:00:00.000000000 Z
12
+ date: 2021-02-05 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rest-client
@@ -16,14 +17,14 @@ dependencies:
16
17
  requirements:
17
18
  - - ">="
18
19
  - !ruby/object:Gem::Version
19
- version: '0'
20
+ version: 2.0.0
20
21
  type: :runtime
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
25
  - - ">="
25
26
  - !ruby/object:Gem::Version
26
- version: '0'
27
+ version: 2.0.0
27
28
  description: A client for Discord's webhooks to fit alongside [discordrb](https://rubygems.org/gems/discordrb).
28
29
  email:
29
30
  - ''
@@ -36,7 +37,7 @@ files:
36
37
  - lib/discordrb/webhooks/client.rb
37
38
  - lib/discordrb/webhooks/embeds.rb
38
39
  - lib/discordrb/webhooks/version.rb
39
- homepage: https://github.com/meew0/discordrb
40
+ homepage: https://github.com/shardlab/discordrb
40
41
  licenses:
41
42
  - MIT
42
43
  metadata: {}
@@ -48,17 +49,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
48
49
  requirements:
49
50
  - - ">="
50
51
  - !ruby/object:Gem::Version
51
- version: 2.1.0
52
+ version: '2.5'
52
53
  required_rubygems_version: !ruby/object:Gem::Requirement
53
54
  requirements:
54
55
  - - ">="
55
56
  - !ruby/object:Gem::Version
56
57
  version: '0'
57
58
  requirements: []
58
- rubyforge_project:
59
- rubygems_version: 2.6.10
59
+ rubygems_version: 3.1.4
60
60
  signing_key:
61
61
  specification_version: 4
62
62
  summary: Webhook client for discordrb
63
63
  test_files: []
64
- has_rdoc: