Class: Discordrb::Channel
- Inherits:
-
Object
- Object
- Discordrb::Channel
- Defined in:
- lib/discordrb/data.rb
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
readonly
Returns the value of attribute name.
-
#permission_overwrites ⇒ Object
readonly
Returns the value of attribute permission_overwrites.
-
#recipient ⇒ Object
readonly
Returns the value of attribute recipient.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(data, bot, server = nil) ⇒ Channel
constructor
A new instance of Channel.
- #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.
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/discordrb/data.rb', line 192 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'] @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 if !@server end # Populate permission overwrites = {} if 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 end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
188 189 190 |
# File 'lib/discordrb/data.rb', line 188 def id @id end |
#is_private ⇒ Object (readonly)
Returns the value of attribute is_private.
188 189 190 |
# File 'lib/discordrb/data.rb', line 188 def is_private @is_private end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
188 189 190 |
# File 'lib/discordrb/data.rb', line 188 def name @name end |
#permission_overwrites ⇒ Object (readonly)
Returns the value of attribute permission_overwrites.
190 191 192 |
# File 'lib/discordrb/data.rb', line 190 def end |
#recipient ⇒ Object (readonly)
Returns the value of attribute recipient.
188 189 190 |
# File 'lib/discordrb/data.rb', line 188 def recipient @recipient end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
188 189 190 |
# File 'lib/discordrb/data.rb', line 188 def server @server end |
#topic ⇒ Object (readonly)
Returns the value of attribute topic.
188 189 190 |
# File 'lib/discordrb/data.rb', line 188 def topic @topic end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
188 189 190 |
# File 'lib/discordrb/data.rb', line 188 def type @type end |
Instance Method Details
#send_message(content) ⇒ Object Also known as: send, message
226 227 228 |
# File 'lib/discordrb/data.rb', line 226 def (content) @bot.(@id, content) end |
#update_from(other) ⇒ Object
230 231 232 233 234 235 236 |
# File 'lib/discordrb/data.rb', line 230 def update_from(other) @topic = other.topic @name = other.name @is_private = other.is_private @recipient = other.recipient = other. end |
#update_overwrites(overwrites) ⇒ Object
251 252 253 |
# File 'lib/discordrb/data.rb', line 251 def update_overwrites(overwrites) = overwrites end |
#users ⇒ Object
List of users currently in a channel
239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/discordrb/data.rb', line 239 def users if @type == 'text' @server.members.select {|u| u.status != :offline } else @server.members.select do |user| if user.voice_channel user.voice_channel.id == @id end end end end |