Class: Discordrb::Channel
- Inherits:
-
Object
- Object
- Discordrb::Channel
- Defined in:
- lib/discordrb/data.rb
Overview
A Discord channel, including data like the topic
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#is_private ⇒ Object
readonly
Returns the value of attribute is_private.
-
#name ⇒ Object
Returns the value of attribute name.
-
#permission_overwrites ⇒ Object
readonly
Returns the value of attribute permission_overwrites.
-
#position ⇒ Object
Returns the value of attribute position.
-
#recipient ⇒ Object
readonly
Returns the value of attribute recipient.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#topic ⇒ Object
Returns the value of attribute topic.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#await(key, attributes = {}, &block) ⇒ Object
Add an await for a message in this channel.
- #delete ⇒ Object
-
#initialize(data, bot, server = nil) ⇒ Channel
constructor
A new instance of Channel.
- #send_file(file) ⇒ Object
- #send_message(content) ⇒ Object (also: #send, #message)
- #update_from(other) ⇒ Object
- #update_overwrites(overwrites) ⇒ Object
-
#users ⇒ Object
List of users currently in a channel.
Constructor Details
#initialize(data, bot, server = nil) ⇒ Channel
Returns a new instance of Channel.
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/discordrb/data.rb', line 145 def initialize(data, bot, server = nil) @bot = bot # data is a sometimes a Hash and othertimes an array of Hashes, you only want the last one if it's an array data = data[-1] if data.is_a?(Array) @id = data['id'].to_i @type = data['type'] || 'text' @topic = data['topic'] @position = data['position'] @is_private = data['is_private'] if @is_private @recipient = User.new(data['recipient'], bot) @name = @recipient.username else @name = data['name'] @server = bot.server(data['guild_id'].to_i) @server ||= server end # Populate permission overwrites = {} return unless data['permission_overwrites'] data['permission_overwrites'].each do |element| role_id = element['id'].to_i deny = Permissions.new(element['deny']) allow = Permissions.new(element['allow']) [role_id] = OpenStruct.new [role_id].deny = deny [role_id].allow = allow end end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
143 144 145 |
# File 'lib/discordrb/data.rb', line 143 def id @id end |
#is_private ⇒ Object (readonly)
Returns the value of attribute is_private.
143 144 145 |
# File 'lib/discordrb/data.rb', line 143 def is_private @is_private end |
#name ⇒ Object
Returns the value of attribute name.
143 144 145 |
# File 'lib/discordrb/data.rb', line 143 def name @name end |
#permission_overwrites ⇒ Object (readonly)
Returns the value of attribute permission_overwrites.
143 144 145 |
# File 'lib/discordrb/data.rb', line 143 def end |
#position ⇒ Object
Returns the value of attribute position.
143 144 145 |
# File 'lib/discordrb/data.rb', line 143 def position @position end |
#recipient ⇒ Object (readonly)
Returns the value of attribute recipient.
143 144 145 |
# File 'lib/discordrb/data.rb', line 143 def recipient @recipient end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
143 144 145 |
# File 'lib/discordrb/data.rb', line 143 def server @server end |
#topic ⇒ Object
Returns the value of attribute topic.
143 144 145 |
# File 'lib/discordrb/data.rb', line 143 def topic @topic end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
143 144 145 |
# File 'lib/discordrb/data.rb', line 143 def type @type end |
Instance Method Details
#await(key, attributes = {}, &block) ⇒ Object
Add an await for a message in this channel
230 231 232 |
# File 'lib/discordrb/data.rb', line 230 def await(key, attributes = {}, &block) @bot.add_await(key, MessageEvent, { in: @id }.merge(attributes), &block) end |
#delete ⇒ Object
187 188 189 |
# File 'lib/discordrb/data.rb', line 187 def delete API.delete_channel(@bot.token, @id) end |
#send_file(file) ⇒ Object
183 184 185 |
# File 'lib/discordrb/data.rb', line 183 def send_file(file) @bot.send_file(@id, file) end |
#send_message(content) ⇒ Object Also known as: send, message
179 180 181 |
# File 'lib/discordrb/data.rb', line 179 def (content) @bot.(@id, content) end |
#update_from(other) ⇒ Object
206 207 208 209 210 211 212 |
# File 'lib/discordrb/data.rb', line 206 def update_from(other) @topic = other.topic @name = other.name @is_private = other.is_private @recipient = other.recipient = other. end |
#update_overwrites(overwrites) ⇒ Object
225 226 227 |
# File 'lib/discordrb/data.rb', line 225 def update_overwrites(overwrites) = overwrites end |
#users ⇒ Object
List of users currently in a channel
215 216 217 218 219 220 221 222 223 |
# File 'lib/discordrb/data.rb', line 215 def users if @type == 'text' @server.members.select { |u| u.status != :offline } else @server.members.select do |user| user.voice_channel.id == @id if user.voice_channel end end end |