Class: Discorb::GuildChannel Abstract

Inherits:
Channel show all
Includes:
Comparable
Defined in:
lib/discorb/channel.rb

Overview

This class is abstract.

Represents a channel in guild.

Instance Attribute Summary collapse

Attributes inherited from Channel

#id, #name

Instance Method Summary collapse

Methods inherited from Channel

#type

Methods inherited from DiscordModel

#eql?

Instance Attribute Details

#permission_overwrites -> Hash{Discorb::Role, Discorb::Member => PermissionOverwrite} (readonly)

Returns The permission overwrites of the channel.

Returns:



116
117
118
# File 'lib/discorb/channel.rb', line 116

def permission_overwrites
  @permission_overwrites
end

#position -> Integer (readonly)

Returns The position of the channel as integer.

Returns:

  • (Integer)

    The position of the channel as integer.



114
115
116
# File 'lib/discorb/channel.rb', line 114

def position
  @position
end

Instance Method Details

#<=>(other) -> -1, ...

Compares position of two channels.

Parameters:

Returns:

  • (-1, 0, 1)

    -1 if the channel is at lower than the other, 1 if the channel is at highter than the other.



140
141
142
143
144
# File 'lib/discorb/channel.rb', line 140

def <=>(other)
  return 0 unless other.respond_to?(:position)

  @position <=> other.position
end

#==(other) -> Boolean

Checks if the channel is same as another.

Parameters:

Returns:

  • (Boolean)

    true if the channel is same as another.



153
154
155
156
157
# File 'lib/discorb/channel.rb', line 153

def ==(other)
  return false unless other.respond_to?(:id)

  @id == other.id
end

#delete!(reason: nil) -> Async::Task<self> Also known as: close!, destroy!

Deletes the channel.

Parameters:

  • reason (String) (defaults to: nil)

    The reason of deleting the channel.

Returns:

  • (Async::Task<self>)

    The deleted channel.



196
197
198
199
200
201
202
# File 'lib/discorb/channel.rb', line 196

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

#guild -> Object



180
181
182
# File 'lib/discorb/channel.rb', line 180

def guild
  @client.guilds[@guild_id]
end

#inspect -> Object



184
185
186
# File 'lib/discorb/channel.rb', line 184

def inspect
  "#<#{self.class} \"##{@name}\" id=#{@id}>"
end

#mention -> Object



168
169
170
# File 'lib/discorb/channel.rb', line 168

def mention
  "<##{@id}>"
end

#move(position, lock_permissions: false, parent: Discorb::Unset, reason: nil) -> Async::Task<self>

Moves the channel to another position.

Parameters:

  • position (Integer)

    The position to move the channel.

  • lock_permissions (Boolean) (defaults to: false)

    Whether to lock the permissions of the channel.

  • parent (Discorb::CategoryChannel) (defaults to: Discorb::Unset)

    The parent of channel.

  • reason (String) (defaults to: nil)

    The reason of moving the channel.

Returns:

  • (Async::Task<self>)

    The moved channel.



218
219
220
221
222
223
224
225
226
227
# File 'lib/discorb/channel.rb', line 218

def move(position, lock_permissions: false, parent: Discorb::Unset, reason: nil)
  Async do
    payload = {
      position: position,
    }
    payload[:lock_permissions] = 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



172
173
174
175
176
# File 'lib/discorb/channel.rb', line 172

def parent
  return nil unless @parent_id

  @client.channels[@parent_id]
end

#to_s -> String

Stringifies the channel.

Returns:

  • (String)

    The name of the channel with #.



164
165
166
# File 'lib/discorb/channel.rb', line 164

def to_s
  "##{@name}"
end