Class: RubyCord::Guild::Channel
- Inherits:
-
Channel
- Object
- DiscordModel
- Channel
- RubyCord::Guild::Channel
- Includes:
- Comparable
- Defined in:
- lib/rubycord/guild/channel.rb
Direct Known Subclasses
CategoryChannel, ForumChannel, StageChannel, TextChannel, ThreadChannel, VoiceChannel
Instance Attribute Summary collapse
-
#permission_overwrites ⇒ Hash{RubyCord::Role, RubyCord::Guild::Member => PermissionOverwrite}
readonly
The permission overwrites of the channel.
-
#position ⇒ Integer
readonly
The position of the channel as integer.
Attributes inherited from Channel
Instance Method Summary collapse
-
#<=>(other) ⇒ -1, ...
Compares position of two channels.
-
#==(other) ⇒ Boolean
Checks if the channel is same as another.
-
#create_invite(max_age: nil, max_uses: nil, temporary: false, unique: false, reason: nil) ⇒ Async::Task<Guild::Invite>
Create an invite in the channel.
-
#delete(reason: nil) ⇒ Async::Task<self>
(also: #close, #destroy)
Deletes the channel.
-
#delete_permissions(target, reason: nil) ⇒ Async::Task<void>
(also: #delete_permission, #destroy_permissions, #destroy_permission)
Delete the channel's permission overwrite.
-
#fetch_invites ⇒ Async::Task<Array<RubyCord::Guild::Invite>>
Fetch the channel's invites.
- #guild ⇒ RubyCord::Guild
-
#inspect ⇒ String
Object class and attributes.
-
#mention ⇒ String
Mentionable string.
-
#move(position, lock_permissions: false, parent: RubyCord::Unset, reason: nil) ⇒ Async::Task<self>
Moves the channel to another position.
-
#parent ⇒ RubyCord::Guild::CategoryChannel?
(also: #category)
The parent of the channel.
-
#set_permissions(target, reason: nil, **perms) ⇒ Async::Task<void>
(also: #modify_permissions, #modify_permisssion, #edit_permissions, #edit_permission)
Set the channel's permission overwrite.
-
#to_s ⇒ String
Stringifies the channel.
Methods inherited from Channel
Methods inherited from DiscordModel
Instance Attribute Details
#permission_overwrites ⇒ Hash{RubyCord::Role, RubyCord::Guild::Member => PermissionOverwrite} (readonly)
Returns The permission overwrites of the channel.
14 15 16 |
# File 'lib/rubycord/guild/channel.rb', line 14 def end |
#position ⇒ Integer (readonly)
Returns The position of the channel as integer.
12 13 14 |
# File 'lib/rubycord/guild/channel.rb', line 12 def position @position end |
Instance Method Details
#<=>(other) ⇒ -1, ...
Compares position of two channels.
36 37 38 39 40 |
# File 'lib/rubycord/guild/channel.rb', line 36 def <=>(other) return nil unless other.respond_to?(:position) @position <=> other.position end |
#==(other) ⇒ Boolean
Checks if the channel is same as another.
49 50 51 52 53 |
# File 'lib/rubycord/guild/channel.rb', line 49 def ==(other) return false unless other.respond_to?(:id) @id == other.id end |
#create_invite(max_age: nil, max_uses: nil, temporary: false, unique: false, reason: nil) ⇒ Async::Task<Guild::Invite>
Create an invite in the channel.
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/rubycord/guild/channel.rb', line 263 def create_invite( max_age: nil, max_uses: nil, temporary: false, unique: false, reason: nil ) Async do _resp, data = @client .http .request( RubyCord::Internal::Route.new( "/channels/#{@id}/invites", "//channels/:channel_id/invites", :post ), { max_age:, max_uses:, temporary:, unique: }, audit_log_reason: reason ) .wait Guild::Invite.new(@client, data, false) end end |
#delete(reason: nil) ⇒ Async::Task<self> Also known as: close, destroy
Deletes the channel.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/rubycord/guild/channel.rb', line 96 def delete(reason: nil) Async do @client .http .request( RubyCord::Internal::Route.new( base_url.wait.to_s, "//webhooks/:webhook_id/:token", :delete ), {}, audit_log_reason: reason ) .wait @deleted = true self end end |
#delete_permissions(target, reason: nil) ⇒ Async::Task<void> Also known as: delete_permission, destroy_permissions, destroy_permission
Delete the channel's permission overwrite.
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/rubycord/guild/channel.rb', line 206 def (target, reason: nil) Async do @client .http .request( RubyCord::Internal::Route.new( "/channels/#{@id}/permissions/#{target.id}", "//channels/:channel_id/permissions/:target_id", :delete ), {}, audit_log_reason: reason ) .wait end end |
#fetch_invites ⇒ Async::Task<Array<RubyCord::Guild::Invite>>
Fetch the channel's invites.
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/rubycord/guild/channel.rb', line 233 def fetch_invites Async do _resp, data = @client .http .request( RubyCord::Internal::Route.new( "/channels/#{@id}/invites", "//channels/:channel_id/invites", :get ) ) .wait data.map { |invite| Guild::Invite.new(@client, invite, false) } end end |
#guild ⇒ RubyCord::Guild
79 80 81 |
# File 'lib/rubycord/guild/channel.rb', line 79 def guild @client.guilds[@guild_id] end |
#inspect ⇒ String
Returns Object class and attributes.
84 85 86 |
# File 'lib/rubycord/guild/channel.rb', line 84 def inspect "#<#{self.class} \"##{@name}\" id=#{@id}>" end |
#mention ⇒ String
Returns Mentionable string.
65 66 67 |
# File 'lib/rubycord/guild/channel.rb', line 65 def mention "<##{@id}>" end |
#move(position, lock_permissions: false, parent: RubyCord::Unset, reason: nil) ⇒ Async::Task<self>
Moves the channel to another position.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/rubycord/guild/channel.rb', line 129 def move( position, lock_permissions: false, parent: RubyCord::Unset, reason: nil ) Async do payload = { position: } payload[:lock_permissions] = payload[:parent_id] = parent&.id if parent != RubyCord::Unset @client .http .request( RubyCord::Internal::Route.new( "/guilds/#{@guild_id}/channels", "//guilds/:guild_id/channels", :patch ), payload, audit_log_reason: reason ) .wait end end |
#parent ⇒ RubyCord::Guild::CategoryChannel? Also known as: category
Returns The parent of the channel.
70 71 72 73 74 |
# File 'lib/rubycord/guild/channel.rb', line 70 def parent return nil unless @parent_id @client.channels[@parent_id] end |
#set_permissions(target, reason: nil, **perms) ⇒ Async::Task<void> Also known as: modify_permissions, modify_permisssion, edit_permissions, edit_permission
Set the channel's permission overwrite.
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/rubycord/guild/channel.rb', line 164 def (target, reason: nil, **perms) Async do allow_value = [target]&.allow_value.to_i deny_value = [target]&.deny_value.to_i perms.each do |perm, value| allow_value[RubyCord::Permission.bits[perm]] = 1 if value == true deny_value[RubyCord::Permission.bits[perm]] = 1 if value == false end payload = { allow: allow_value, deny: deny_value, type: target.is_a?(Member) ? 1 : 0 } @client .http .request( RubyCord::Internal::Route.new( "/channels/#{@id}/permissions/#{target.id}", "//channels/:channel_id/permissions/:target_id", :put ), payload, audit_log_reason: reason ) .wait end end |
#to_s ⇒ String
Stringifies the channel.
60 61 62 |
# File 'lib/rubycord/guild/channel.rb', line 60 def to_s "##{@name}" end |