discorb 0.19.0 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build_version.yml +2 -2
  3. data/.rubocop.yml +12 -75
  4. data/Changelog.md +10 -0
  5. data/Rakefile +482 -454
  6. data/lib/discorb/allowed_mentions.rb +68 -72
  7. data/lib/discorb/app_command/command.rb +466 -398
  8. data/lib/discorb/app_command/common.rb +65 -25
  9. data/lib/discorb/app_command/handler.rb +304 -266
  10. data/lib/discorb/app_command.rb +5 -5
  11. data/lib/discorb/application.rb +198 -197
  12. data/lib/discorb/asset.rb +101 -101
  13. data/lib/discorb/attachment.rb +134 -119
  14. data/lib/discorb/audit_logs.rb +412 -385
  15. data/lib/discorb/automod.rb +279 -269
  16. data/lib/discorb/channel/base.rb +107 -108
  17. data/lib/discorb/channel/category.rb +32 -32
  18. data/lib/discorb/channel/container.rb +44 -44
  19. data/lib/discorb/channel/dm.rb +26 -28
  20. data/lib/discorb/channel/guild.rb +311 -246
  21. data/lib/discorb/channel/stage.rb +156 -140
  22. data/lib/discorb/channel/text.rb +430 -336
  23. data/lib/discorb/channel/thread.rb +374 -325
  24. data/lib/discorb/channel/voice.rb +85 -79
  25. data/lib/discorb/channel.rb +5 -5
  26. data/lib/discorb/client.rb +635 -621
  27. data/lib/discorb/color.rb +178 -182
  28. data/lib/discorb/common.rb +168 -164
  29. data/lib/discorb/components/button.rb +107 -106
  30. data/lib/discorb/components/select_menu.rb +157 -145
  31. data/lib/discorb/components/text_input.rb +103 -106
  32. data/lib/discorb/components.rb +68 -66
  33. data/lib/discorb/dictionary.rb +135 -135
  34. data/lib/discorb/embed.rb +404 -398
  35. data/lib/discorb/emoji.rb +309 -302
  36. data/lib/discorb/emoji_table.rb +16099 -8857
  37. data/lib/discorb/error.rb +131 -131
  38. data/lib/discorb/event.rb +360 -314
  39. data/lib/discorb/event_handler.rb +39 -39
  40. data/lib/discorb/exe/about.rb +17 -17
  41. data/lib/discorb/exe/irb.rb +72 -67
  42. data/lib/discorb/exe/new.rb +323 -315
  43. data/lib/discorb/exe/run.rb +69 -68
  44. data/lib/discorb/exe/setup.rb +57 -55
  45. data/lib/discorb/exe/show.rb +12 -12
  46. data/lib/discorb/extend.rb +25 -45
  47. data/lib/discorb/extension.rb +89 -83
  48. data/lib/discorb/flag.rb +126 -128
  49. data/lib/discorb/gateway.rb +984 -804
  50. data/lib/discorb/gateway_events.rb +670 -638
  51. data/lib/discorb/gateway_requests.rb +45 -48
  52. data/lib/discorb/guild.rb +2115 -1626
  53. data/lib/discorb/guild_template.rb +280 -241
  54. data/lib/discorb/http.rb +247 -232
  55. data/lib/discorb/image.rb +42 -42
  56. data/lib/discorb/integration.rb +169 -161
  57. data/lib/discorb/intents.rb +161 -163
  58. data/lib/discorb/interaction/autocomplete.rb +76 -62
  59. data/lib/discorb/interaction/command.rb +279 -224
  60. data/lib/discorb/interaction/components.rb +114 -104
  61. data/lib/discorb/interaction/modal.rb +36 -32
  62. data/lib/discorb/interaction/response.rb +379 -336
  63. data/lib/discorb/interaction/root.rb +271 -257
  64. data/lib/discorb/interaction.rb +5 -5
  65. data/lib/discorb/invite.rb +154 -153
  66. data/lib/discorb/member.rb +344 -311
  67. data/lib/discorb/message.rb +615 -544
  68. data/lib/discorb/message_meta.rb +197 -186
  69. data/lib/discorb/modules.rb +371 -290
  70. data/lib/discorb/permission.rb +305 -291
  71. data/lib/discorb/presence.rb +352 -346
  72. data/lib/discorb/rate_limit.rb +81 -76
  73. data/lib/discorb/reaction.rb +55 -54
  74. data/lib/discorb/role.rb +272 -240
  75. data/lib/discorb/shard.rb +76 -74
  76. data/lib/discorb/sticker.rb +193 -171
  77. data/lib/discorb/user.rb +205 -188
  78. data/lib/discorb/utils/colored_puts.rb +16 -16
  79. data/lib/discorb/utils.rb +12 -16
  80. data/lib/discorb/voice_state.rb +305 -281
  81. data/lib/discorb/webhook.rb +537 -507
  82. data/lib/discorb.rb +62 -56
  83. data/sig/discorb/application.rbs +2 -0
  84. data/sig/discorb/automod.rbs +10 -1
  85. data/sig/discorb/guild.rbs +2 -0
  86. data/sig/discorb/message.rbs +2 -0
  87. data/sig/discorb/user.rbs +22 -20
  88. metadata +2 -2
@@ -1,119 +1,134 @@
1
- # frozen_string_literal: true
2
-
3
- require "mime/types"
4
- require "stringio"
5
-
6
- module Discorb
7
- #
8
- # Represents a attachment file.
9
- #
10
- class Attachment
11
- # @return [#read] The file content.
12
- attr_reader :io
13
- # @return [String] The attachment filename.
14
- attr_reader :filename
15
- # @return [String] The attachment content type.
16
- attr_reader :content_type
17
- # @return [String] The attachment description.
18
- attr_reader :description
19
- # @return [Discorb::Snowflake] The attachment id.
20
- attr_reader :id
21
- # @return [Integer] The attachment size in bytes.
22
- attr_reader :size
23
- # @return [String] The attachment url.
24
- attr_reader :url
25
- # @return [String] The attachment proxy url.
26
- attr_reader :proxy_url
27
- # @return [Integer] The image height.
28
- # @return [nil] If the attachment is not an image.
29
- attr_reader :height
30
- # @return [Integer] The image width.
31
- # @return [nil] If the attachment is not an image.
32
- attr_reader :width
33
- # @return [:client, :discord] The attachment was created by.
34
- attr_reader :created_by
35
- # @private
36
- # @return [Boolean] Whether the attachment will be closed after it is sent.
37
- attr_reader :will_close
38
-
39
- # @!attribute [r] image?
40
- # @return [Boolean] whether the file is an image.
41
-
42
- #
43
- # Creates a new attachment.
44
- #
45
- # @param [#read, String] source The Source of the attachment.
46
- # @param [String] filename The filename of the attachment. If not set, path or object_id of the IO is used.
47
- # @param [String] description The description of the attachment.
48
- # @param [String] content_type The content type of the attachment. If not set, it is guessed from the filename.
49
- # If failed to guess, it is set to `application/octet-stream`.
50
- # @param [Boolean] will_close Whether the IO will be closed after the attachment is sent.
51
- #
52
- def initialize(source, filename = nil, description: nil, content_type: nil, will_close: true)
53
- @io = if source.respond_to?(:read)
54
- source
55
- else
56
- File.open(source, "rb")
57
- end
58
- @filename = filename || (@io.respond_to?(:path) ? @io.path : @io.object_id)
59
- @description = description
60
- @content_type = content_type || MIME::Types.type_for(@filename.to_s)[0].to_s
61
- @content_type = "application/octet-stream" if @content_type == ""
62
- @will_close = will_close
63
- @created_by = :client
64
- end
65
-
66
- #
67
- # Initializes the object from a hash.
68
- # @private
69
- #
70
- def initialize_hash(data)
71
- @id = Snowflake.new(data[:id])
72
- @filename = data[:filename]
73
- @content_type = data[:content_type] || "application/octet-stream"
74
- @size = data[:size]
75
- @url = data[:url]
76
- @proxy_url = data[:proxy_url]
77
- @height = data[:height]
78
- @width = data[:width]
79
- @created_by = :discord
80
- end
81
-
82
- def image?
83
- @content_type.start_with? "image/"
84
- end
85
-
86
- def inspect
87
- if @created_by == :discord
88
- "<#{self.class} #{@id}: #{@filename}>"
89
- else
90
- "<#{self.class} #{io.fileno}: #{@filename}>"
91
- end
92
- end
93
-
94
- #
95
- # Creates a new file from a hash.
96
- # @private
97
- #
98
- def self.from_hash(data)
99
- inst = allocate
100
- inst.initialize_hash(data)
101
- inst
102
- end
103
-
104
- #
105
- # Creates a new file from a string.
106
- #
107
- # @param [String] string The string to create the file from.
108
- # @param [String] filename The filename of the file. object_id of the string is used if not set.
109
- # @param [String] content_type The content type of the file. If not set, it is guessed from the filename.
110
- #
111
- # @return [Discorb::Attachment] The new file.
112
- #
113
- def self.from_string(string, filename = nil, content_type: nil, description: nil)
114
- io = StringIO.new(string)
115
- filename ||= string.object_id.to_s + ".txt"
116
- new(io, filename, content_type: content_type, description: description, will_close: true)
117
- end
118
- end
119
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "mime/types"
4
+ require "stringio"
5
+
6
+ module Discorb
7
+ #
8
+ # Represents a attachment file.
9
+ #
10
+ class Attachment
11
+ # @return [#read] The file content.
12
+ attr_reader :io
13
+ # @return [String] The attachment filename.
14
+ attr_reader :filename
15
+ # @return [String] The attachment content type.
16
+ attr_reader :content_type
17
+ # @return [String] The attachment description.
18
+ attr_reader :description
19
+ # @return [Discorb::Snowflake] The attachment id.
20
+ attr_reader :id
21
+ # @return [Integer] The attachment size in bytes.
22
+ attr_reader :size
23
+ # @return [String] The attachment url.
24
+ attr_reader :url
25
+ # @return [String] The attachment proxy url.
26
+ attr_reader :proxy_url
27
+ # @return [Integer] The image height.
28
+ # @return [nil] If the attachment is not an image.
29
+ attr_reader :height
30
+ # @return [Integer] The image width.
31
+ # @return [nil] If the attachment is not an image.
32
+ attr_reader :width
33
+ # @return [:client, :discord] The attachment was created by.
34
+ attr_reader :created_by
35
+ # @private
36
+ # @return [Boolean] Whether the attachment will be closed after it is sent.
37
+ attr_reader :will_close
38
+
39
+ # @!attribute [r] image?
40
+ # @return [Boolean] whether the file is an image.
41
+
42
+ #
43
+ # Creates a new attachment.
44
+ #
45
+ # @param [#read, String] source The Source of the attachment.
46
+ # @param [String] filename The filename of the attachment. If not set, path or object_id of the IO is used.
47
+ # @param [String] description The description of the attachment.
48
+ # @param [String] content_type The content type of the attachment. If not set, it is guessed from the filename.
49
+ # If failed to guess, it is set to `application/octet-stream`.
50
+ # @param [Boolean] will_close Whether the IO will be closed after the attachment is sent.
51
+ #
52
+ def initialize(
53
+ source,
54
+ filename = nil,
55
+ description: nil,
56
+ content_type: nil,
57
+ will_close: true
58
+ )
59
+ @io = (source.respond_to?(:read) ? source : File.open(source, "rb"))
60
+ @filename =
61
+ filename || (@io.respond_to?(:path) ? @io.path : @io.object_id)
62
+ @description = description
63
+ @content_type =
64
+ content_type || MIME::Types.type_for(@filename.to_s)[0].to_s
65
+ @content_type = "application/octet-stream" if @content_type == ""
66
+ @will_close = will_close
67
+ @created_by = :client
68
+ end
69
+
70
+ #
71
+ # Initializes the object from a hash.
72
+ # @private
73
+ #
74
+ def initialize_hash(data)
75
+ @id = Snowflake.new(data[:id])
76
+ @filename = data[:filename]
77
+ @content_type = data[:content_type] || "application/octet-stream"
78
+ @size = data[:size]
79
+ @url = data[:url]
80
+ @proxy_url = data[:proxy_url]
81
+ @height = data[:height]
82
+ @width = data[:width]
83
+ @created_by = :discord
84
+ end
85
+
86
+ def image?
87
+ @content_type.start_with? "image/"
88
+ end
89
+
90
+ def inspect
91
+ if @created_by == :discord
92
+ "<#{self.class} #{@id}: #{@filename}>"
93
+ else
94
+ "<#{self.class} #{io.fileno}: #{@filename}>"
95
+ end
96
+ end
97
+
98
+ #
99
+ # Creates a new file from a hash.
100
+ # @private
101
+ #
102
+ def self.from_hash(data)
103
+ inst = allocate
104
+ inst.initialize_hash(data)
105
+ inst
106
+ end
107
+
108
+ #
109
+ # Creates a new file from a string.
110
+ #
111
+ # @param [String] string The string to create the file from.
112
+ # @param [String] filename The filename of the file. object_id of the string is used if not set.
113
+ # @param [String] content_type The content type of the file. If not set, it is guessed from the filename.
114
+ #
115
+ # @return [Discorb::Attachment] The new file.
116
+ #
117
+ def self.from_string(
118
+ string,
119
+ filename = nil,
120
+ content_type: nil,
121
+ description: nil
122
+ )
123
+ io = StringIO.new(string)
124
+ filename ||= "#{string.object_id}.txt"
125
+ new(
126
+ io,
127
+ filename,
128
+ content_type: content_type,
129
+ description: description,
130
+ will_close: true
131
+ )
132
+ end
133
+ end
134
+ end