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,153 +1,154 @@
1
- # frozen_string_literal: true
2
-
3
- module Discorb
4
- #
5
- # Represents invite of discord.
6
- #
7
- class Invite < DiscordModel
8
- # @return [String] The code of invite.
9
- attr_reader :code
10
-
11
- # @return [:voice, :stream, :guild] The type of invite.
12
- attr_reader :target_type
13
-
14
- # @return [User] The user of invite.
15
- attr_reader :target_user
16
-
17
- # @return [Integer] The approximate number of online users of invite.
18
- attr_reader :approximate_presence_count
19
-
20
- # @return [Integer] The approximate number of members of invite.
21
- attr_reader :approximate_member_count
22
-
23
- # @return [Time] The time when invite expires.
24
- # @return [nil] The invite never expires.
25
- # @macro [new] nometa
26
- # @return [nil] The invite doesn't have metadata.
27
- attr_reader :expires_at
28
-
29
- # @return [Integer] The number of uses of invite.
30
- # @macro nometa
31
- attr_reader :uses
32
-
33
- # @return [Integer] The maximum number of uses of invite.
34
- # @macro nometa
35
- attr_reader :max_uses
36
-
37
- # @return [Integer] Duration of invite in seconds.
38
- # @macro nometa
39
- attr_reader :max_age
40
-
41
- # @return [Time] The time when invite was created.
42
- # @macro nometa
43
- attr_reader :created_at
44
-
45
- # @!attribute [r] channel
46
- # Channel of the invite.
47
- #
48
- # @return [Discorb::Channel] Channel of invite.
49
- # @macro client_cache
50
- #
51
- # @!attribute [r] guild
52
- # Guild of the invite.
53
- #
54
- # @return [Discorb::Guild] Guild of invite.
55
- # @macro client_cache
56
- #
57
- # @!attribute [r] remain_uses
58
- # Number of remaining uses of invite.
59
- # @return [Integer] Number of remaining uses of invite.
60
- #
61
- # @!attribute [r] url
62
- # Full url of invite.
63
- # @return [String] Full url of invite.
64
- #
65
- # @!attribute [r] temporary?
66
- # Whether the invite is temporary.
67
- # @return [Boolean]
68
-
69
- # @private
70
- # @return [{Integer => Symbol}] The mapping of target types.
71
- TARGET_TYPES = {
72
- nil => :voice,
73
- 1 => :stream,
74
- 2 => :guild,
75
- }.freeze
76
-
77
- #
78
- # Initialize a new invite.
79
- # @private
80
- #
81
- # @param [Discorb::Client] client The client.
82
- # @param [Hash] data The data of invite.
83
- # @param [Boolean] gateway Whether the data is from gateway.
84
- #
85
- def initialize(client, data, gateway)
86
- @client = client
87
- @data = data[:data]
88
- _set_data(data, gateway)
89
- end
90
-
91
- def channel
92
- @client.channels[@channel_data[:id]]
93
- end
94
-
95
- def guild
96
- @client.guilds[@guild_data[:id]]
97
- end
98
-
99
- def url
100
- "https://discord.gg/#{@code}"
101
- end
102
-
103
- def remain_uses
104
- @max_uses && @max_uses - @uses
105
- end
106
-
107
- def temporary?
108
- @temporary
109
- end
110
-
111
- # Delete the invite.
112
- # @async
113
- # @return [Async::Task<void>] The task.
114
- #
115
- def delete(reason: nil)
116
- Async do
117
- @client.http.request(Route.new("/invites/#{@code}", "//invites/:code", :delete), {}, audit_log_reason: reason)
118
- end
119
- end
120
-
121
- private
122
-
123
- def _set_data(data, gateway)
124
- @code = data[:code]
125
- if gateway
126
- @channel_data = { id: data[:channel_id] }
127
- @guild_data = { id: data[:guild_id] }
128
- else
129
- @guild_data = data[:guild]
130
- @channel_data = data[:channel]
131
- @approximate_presence_count = data[:approximate_presence_count]
132
- @approximate_member_count = data[:approximate_member_count]
133
- @expires_at = data[:expires_at] && Time.iso8601(data[:expires_at])
134
- end
135
- @inviter_data = data[:inviter]
136
- @target_type = TARGET_TYPES[data[:target_type]]
137
- if data[:target_user]
138
- @target_user = @client.users[data[:target_user][:id]] || User.new(@client,
139
- data[:target_user])
140
- end
141
- # @target_application = nil
142
-
143
- # @stage_instance = data[:stage_instance] && Invite::StageInstance.new(self, data[:stage_instance])
144
- return unless data.key?(:uses)
145
-
146
- @uses = data[:uses]
147
- @max_uses = data[:max_uses]
148
- @max_age = data[:max_age]
149
- @temporary = data[:temporary]
150
- @created_at = Time.iso8601(data[:created_at])
151
- end
152
- end
153
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Discorb
4
+ #
5
+ # Represents invite of discord.
6
+ #
7
+ class Invite < DiscordModel
8
+ # @return [String] The code of invite.
9
+ attr_reader :code
10
+
11
+ # @return [:voice, :stream, :guild] The type of invite.
12
+ attr_reader :target_type
13
+
14
+ # @return [User] The user of invite.
15
+ attr_reader :target_user
16
+
17
+ # @return [Integer] The approximate number of online users of invite.
18
+ attr_reader :approximate_presence_count
19
+
20
+ # @return [Integer] The approximate number of members of invite.
21
+ attr_reader :approximate_member_count
22
+
23
+ # @return [Time] The time when invite expires.
24
+ # @return [nil] The invite never expires.
25
+ # @macro [new] nometa
26
+ # @return [nil] The invite doesn't have metadata.
27
+ attr_reader :expires_at
28
+
29
+ # @return [Integer] The number of uses of invite.
30
+ # @macro nometa
31
+ attr_reader :uses
32
+
33
+ # @return [Integer] The maximum number of uses of invite.
34
+ # @macro nometa
35
+ attr_reader :max_uses
36
+
37
+ # @return [Integer] Duration of invite in seconds.
38
+ # @macro nometa
39
+ attr_reader :max_age
40
+
41
+ # @return [Time] The time when invite was created.
42
+ # @macro nometa
43
+ attr_reader :created_at
44
+
45
+ # @!attribute [r] channel
46
+ # Channel of the invite.
47
+ #
48
+ # @return [Discorb::Channel] Channel of invite.
49
+ # @macro client_cache
50
+ #
51
+ # @!attribute [r] guild
52
+ # Guild of the invite.
53
+ #
54
+ # @return [Discorb::Guild] Guild of invite.
55
+ # @macro client_cache
56
+ #
57
+ # @!attribute [r] remain_uses
58
+ # Number of remaining uses of invite.
59
+ # @return [Integer] Number of remaining uses of invite.
60
+ #
61
+ # @!attribute [r] url
62
+ # Full url of invite.
63
+ # @return [String] Full url of invite.
64
+ #
65
+ # @!attribute [r] temporary?
66
+ # Whether the invite is temporary.
67
+ # @return [Boolean]
68
+
69
+ # @private
70
+ # @return [{Integer => Symbol}] The mapping of target types.
71
+ TARGET_TYPES = { nil => :voice, 1 => :stream, 2 => :guild }.freeze
72
+
73
+ #
74
+ # Initialize a new invite.
75
+ # @private
76
+ #
77
+ # @param [Discorb::Client] client The client.
78
+ # @param [Hash] data The data of invite.
79
+ # @param [Boolean] gateway Whether the data is from gateway.
80
+ #
81
+ def initialize(client, data, gateway)
82
+ @client = client
83
+ @data = data[:data]
84
+ _set_data(data, gateway)
85
+ end
86
+
87
+ def channel
88
+ @client.channels[@channel_data[:id]]
89
+ end
90
+
91
+ def guild
92
+ @client.guilds[@guild_data[:id]]
93
+ end
94
+
95
+ def url
96
+ "https://discord.gg/#{@code}"
97
+ end
98
+
99
+ def remain_uses
100
+ @max_uses && (@max_uses - @uses)
101
+ end
102
+
103
+ def temporary?
104
+ @temporary
105
+ end
106
+
107
+ # Delete the invite.
108
+ # @async
109
+ # @return [Async::Task<void>] The task.
110
+ #
111
+ def delete(reason: nil)
112
+ Async do
113
+ @client.http.request(
114
+ Route.new("/invites/#{@code}", "//invites/:code", :delete),
115
+ {},
116
+ audit_log_reason: reason
117
+ )
118
+ end
119
+ end
120
+
121
+ private
122
+
123
+ def _set_data(data, gateway)
124
+ @code = data[:code]
125
+ if gateway
126
+ @channel_data = { id: data[:channel_id] }
127
+ @guild_data = { id: data[:guild_id] }
128
+ else
129
+ @guild_data = data[:guild]
130
+ @channel_data = data[:channel]
131
+ @approximate_presence_count = data[:approximate_presence_count]
132
+ @approximate_member_count = data[:approximate_member_count]
133
+ @expires_at = data[:expires_at] && Time.iso8601(data[:expires_at])
134
+ end
135
+ @inviter_data = data[:inviter]
136
+ @target_type = TARGET_TYPES[data[:target_type]]
137
+ if data[:target_user]
138
+ @target_user =
139
+ @client.users[data[:target_user][:id]] ||
140
+ User.new(@client, data[:target_user])
141
+ end
142
+ # @target_application = nil
143
+
144
+ # @stage_instance = data[:stage_instance] && Invite::StageInstance.new(self, data[:stage_instance])
145
+ return unless data.key?(:uses)
146
+
147
+ @uses = data[:uses]
148
+ @max_uses = data[:max_uses]
149
+ @max_age = data[:max_age]
150
+ @temporary = data[:temporary]
151
+ @created_at = Time.iso8601(data[:created_at])
152
+ end
153
+ end
154
+ end