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
- #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.
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 178 179 180 181 |
# File 'lib/discordrb/data.rb', line 149 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 @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']) @permission_overwrites[role_id] = OpenStruct.new @permission_overwrites[role_id].deny = deny @permission_overwrites[role_id].allow = allow end end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
145 146 147 |
# File 'lib/discordrb/data.rb', line 145 def id @id end |
#is_private ⇒ Object (readonly)
Returns the value of attribute is_private.
145 146 147 |
# File 'lib/discordrb/data.rb', line 145 def is_private @is_private end |
#name ⇒ Object
Returns the value of attribute name.
145 146 147 |
# File 'lib/discordrb/data.rb', line 145 def name @name end |
#permission_overwrites ⇒ Object (readonly)
Returns the value of attribute permission_overwrites.
147 148 149 |
# File 'lib/discordrb/data.rb', line 147 def @permission_overwrites end |
#position ⇒ Object
Returns the value of attribute position.
145 146 147 |
# File 'lib/discordrb/data.rb', line 145 def position @position end |
#recipient ⇒ Object (readonly)
Returns the value of attribute recipient.
145 146 147 |
# File 'lib/discordrb/data.rb', line 145 def recipient @recipient end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
145 146 147 |
# File 'lib/discordrb/data.rb', line 145 def server @server end |
#topic ⇒ Object
Returns the value of attribute topic.
145 146 147 |
# File 'lib/discordrb/data.rb', line 145 def topic @topic end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
145 146 147 |
# File 'lib/discordrb/data.rb', line 145 def type @type end |
Instance Method Details
#delete ⇒ Object
191 192 193 |
# File 'lib/discordrb/data.rb', line 191 def delete API.delete_channel(@bot.token, @id) end |
#send_file(file) ⇒ Object
187 188 189 |
# File 'lib/discordrb/data.rb', line 187 def send_file(file) @bot.send_file(@id, file) end |
#send_message(content) ⇒ Object Also known as: send, message
183 184 185 |
# File 'lib/discordrb/data.rb', line 183 def (content) @bot.(@id, content) end |
#update_from(other) ⇒ Object
210 211 212 213 214 215 216 |
# File 'lib/discordrb/data.rb', line 210 def update_from(other) @topic = other.topic @name = other.name @is_private = other.is_private @recipient = other.recipient @permission_overwrites = other. end |
#update_overwrites(overwrites) ⇒ Object
229 230 231 |
# File 'lib/discordrb/data.rb', line 229 def update_overwrites(overwrites) @permission_overwrites = overwrites end |
#users ⇒ Object
List of users currently in a channel
219 220 221 222 223 224 225 226 227 |
# File 'lib/discordrb/data.rb', line 219 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 |