Class: Discorb::GuildChannel Abstract
- Inherits:
-
Channel
- Object
- DiscordModel
- Channel
- Discorb::GuildChannel
- Includes:
- Comparable
- Defined in:
- lib/discorb/channel/guild.rb
Overview
Represents a channel in guild.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#permission_overwrites -> Hash{Discorb::Role, Discorb::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<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<Discorb::Invite>>
Fetch the channel's invites.
- #guild -> Object
- #inspect -> Object
- #mention -> Object
-
#move(position, lock_permissions: false, parent: Discorb::Unset, reason: nil) -> Async::Task<self>
Moves the channel to another position.
- #parent -> Object (also: #category)
-
#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{Discorb::Role, Discorb::Member => PermissionOverwrite} (readonly)
Returns The permission overwrites of the channel.
12 13 14 |
# File 'lib/discorb/channel/guild.rb', line 12 def @permission_overwrites end |
#position -> Integer (readonly)
Returns The position of the channel as integer.
10 11 12 |
# File 'lib/discorb/channel/guild.rb', line 10 def position @position end |
Instance Method Details
#<=>(other) -> -1, ...
Compares position of two channels.
36 37 38 39 40 |
# File 'lib/discorb/channel/guild.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/discorb/channel/guild.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<Invite>
Create an invite in the channel.
212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/discorb/channel/guild.rb', line 212 def create_invite(max_age: nil, max_uses: nil, temporary: false, unique: false, reason: nil) Async do _resp, data = @client.http.request( Route.new("/channels/#{@id}/invites", "//channels/:channel_id/invites", :post), { max_age: max_age, max_uses: max_uses, temporary: temporary, unique: unique, }, audit_log_reason: reason, ).wait Invite.new(@client, data, false) end end |
#delete(reason: nil) -> Async::Task<self> Also known as: close, destroy
Deletes the channel.
92 93 94 95 96 97 98 99 |
# File 'lib/discorb/channel/guild.rb', line 92 def delete(reason: nil) Async do @client.http.request(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.
172 173 174 175 176 177 178 179 |
# File 'lib/discorb/channel/guild.rb', line 172 def (target, reason: nil) Async do @client.http.request( 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<Discorb::Invite>>
Fetch the channel's invites.
191 192 193 194 195 196 197 |
# File 'lib/discorb/channel/guild.rb', line 191 def fetch_invites Async do _resp, data = @client.http.request(Route.new("/channels/#{@id}/invites", "//channels/:channel_id/invites", :get)).wait data.map { |invite| Invite.new(@client, invite, false) } end end |
#guild -> Object
76 77 78 |
# File 'lib/discorb/channel/guild.rb', line 76 def guild @client.guilds[@guild_id] end |
#inspect -> Object
80 81 82 |
# File 'lib/discorb/channel/guild.rb', line 80 def inspect "#<#{self.class} \"##{@name}\" id=#{@id}>" end |
#mention -> Object
64 65 66 |
# File 'lib/discorb/channel/guild.rb', line 64 def mention "<##{@id}>" end |
#move(position, lock_permissions: false, parent: Discorb::Unset, reason: nil) -> Async::Task<self>
Moves the channel to another position.
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/discorb/channel/guild.rb', line 115 def move(position, lock_permissions: false, parent: Discorb::Unset, reason: nil) Async do # @type var payload: Hash[Symbol, untyped] payload = { position: position, } payload[:lock_permissions] = payload[:parent_id] = parent&.id if parent != Discorb::Unset @client.http.request(Route.new("/guilds/#{@guild_id}/channels", "//guilds/:guild_id/channels", :patch), payload, audit_log_reason: reason).wait end end |
#parent -> Object Also known as: category
68 69 70 71 72 |
# File 'lib/discorb/channel/guild.rb', line 68 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.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/discorb/channel/guild.rb', line 138 def (target, reason: nil, **perms) Async do allow_value = @permission_overwrites[target]&.allow_value.to_i deny_value = @permission_overwrites[target]&.deny_value.to_i perms.each do |perm, value| allow_value[Discorb::Permission.bits[perm]] = 1 if value == true deny_value[Discorb::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( 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/discorb/channel/guild.rb', line 60 def to_s "##{@name}" end |