Class: Rubord::Mention

Inherits:
Object
  • Object
show all
Defined in:
lib/rubord/models/mention.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, client, guild) ⇒ Mention

Returns a new instance of Mention.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rubord/models/mention.rb', line 8

def initialize(data, client, guild)
  @everyone = data["mention_everyone"] || false

  @users = (data["mentions"] || []).map do |user_data|
    user = Rubord::User.new(user_data)
    client.users.set(user.id, user)
    user
  end

  @roles = (data["mention_roles"] || []).map do |role_id|
    guild&.roles&.get(role_id)
  end

  @channels = 
    if data["mention_channels"]
      data["mention_channels"].map do |channel_data|
        channel = Rubord::Channel.new(channel_data, client)
        client.channels.set(channel.id, channel)
        channel
      end
    else
      Rubord.Parser.channel_mentions(data["content"] || "").map do |channel_id|
        client.channels.get(channel_id) || Rubord::Channel.new({ "id" => channel_id }, client)
      end
    end
end

Instance Attribute Details

#channelsObject (readonly)

Returns the value of attribute channels.



3
4
5
# File 'lib/rubord/models/mention.rb', line 3

def channels
  @channels
end

#everyoneObject (readonly)

Returns the value of attribute everyone.



3
4
5
# File 'lib/rubord/models/mention.rb', line 3

def everyone
  @everyone
end

#rolesObject (readonly)

Returns the value of attribute roles.



3
4
5
# File 'lib/rubord/models/mention.rb', line 3

def roles
  @roles
end

#usersObject (readonly)

Returns the value of attribute users.



3
4
5
# File 'lib/rubord/models/mention.rb', line 3

def users
  @users
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/rubord/models/mention.rb', line 39

def empty?
  users.empty? && roles.empty? && channels.empty? && !everyone
end

#inspectObject



43
44
45
# File 'lib/rubord/models/mention.rb', line 43

def inspect
  "#<Rubord::Mention users=#{users.size} roles=#{roles.size} channels=#{channels.size} everyone=#{everyone}>"
end

#mention_everyone?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/rubord/models/mention.rb', line 35

def mention_everyone?
  @everyone
end