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?, #hash

Instance Attribute Details

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

Returns The permission overwrites of the channel.

Returns:



95
96
97
# File 'lib/discorb/channel.rb', line 95

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.



93
94
95
# File 'lib/discorb/channel.rb', line 93

def position
  @position
end

Instance Method Details

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

Compares position of two channels.

Parameters:

Returns:

  • (-1, 1)

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



119
120
121
122
123
# File 'lib/discorb/channel.rb', line 119

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.



132
133
134
135
136
# File 'lib/discorb/channel.rb', line 132

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

  @id == other.id
end

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

Note:

This is an asynchronous method, it will return a Async::Task object. Use Async::Task#wait to get the result.

Note:

This method calls HTTP request.

Deletes the channel.

Parameters:

  • reason (String) (defaults to: nil)

    The reason of deleting the channel.

Returns:

  • (self)

    The deleted channel.

Raises:



176
177
178
179
180
181
182
# File 'lib/discorb/channel.rb', line 176

def delete!(reason: nil)
  Async do
    @client.internet.delete(base_url.wait.to_s, audit_log_reason: reason).wait
    @deleted = true
    self
  end
end

#guild -> Object



159
160
161
# File 'lib/discorb/channel.rb', line 159

def guild
  @client.guilds[@guild_id]
end

#inspect -> Object



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

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

#mention -> Object



147
148
149
# File 'lib/discorb/channel.rb', line 147

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

#move(position, lock_permissions: false, parent: :unset, reason: nil) -> self

Note:

This is an asynchronous method, it will return a Async::Task object. Use Async::Task#wait to get the result.

Note:

This method calls HTTP request.

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: :unset)

    The parent of channel.

  • reason (String) (defaults to: nil)

    The reason of moving the channel.

Returns:

  • (self)

    The moved channel.

Raises:



199
200
201
202
203
204
205
206
207
208
# File 'lib/discorb/channel.rb', line 199

def move(position, lock_permissions: false, parent: :unset, reason: nil)
  Async do
    payload = {
      position: position,
    }
    payload[:lock_permissions] = lock_permissions
    payload[:parent_id] = parent&.id if parent != :unset
    @client.internet.patch("/guilds/#{@guild_id}/channels", payload, audit_log_reason: reason).wait
  end
end

#parent -> Object Also known as: category



151
152
153
154
155
# File 'lib/discorb/channel.rb', line 151

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 #.



143
144
145
# File 'lib/discorb/channel.rb', line 143

def to_s
  "##{@name}"
end