Class: Rubord::Interaction

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

Constant Summary collapse

TYPES =
{
  ping: 1,
  application_command: 2,
  message_component: 3,
  modal_submit: 5
}
COMPONENT_TYPES =
{
  button: 2,
  select_menu: 3
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, client) ⇒ Interaction

Returns a new instance of Interaction.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rubord/models/interaction.rb', line 29

def initialize(data, client)
  @client         = client
  @id             = data["id"]
  @application_id = data["application_id"]
  @type           = data["type"]
  @data           = data["data"] || {}
  @values         = data["data"] ? data["data"]["values"] : nil
  @guild_id       = data["guild_id"]
  @channel_id     = data["channel_id"]
  @token          = data["token"]
  @version        = data["version"]

  @message        = Rubord::Message.new(data["message"], client) if data["message"]

  user_data       = data["user"] || data.dig("member", "user")
  @user           = Rubord::User.new(user_data) if user_data

  if (member = data["member"])
    member["guild_id"] = @guild_id
    @member = Rubord::Member.new(member, client)
  end
end

Instance Attribute Details

#application_idObject (readonly)

Returns the value of attribute application_id.



15
16
17
# File 'lib/rubord/models/interaction.rb', line 15

def application_id
  @application_id
end

#channel_idObject (readonly)

Returns the value of attribute channel_id.



15
16
17
# File 'lib/rubord/models/interaction.rb', line 15

def channel_id
  @channel_id
end

#clientObject (readonly)

Returns the value of attribute client.



15
16
17
# File 'lib/rubord/models/interaction.rb', line 15

def client
  @client
end

#dataObject (readonly)

Returns the value of attribute data.



15
16
17
# File 'lib/rubord/models/interaction.rb', line 15

def data
  @data
end

#guild_idObject (readonly)

Returns the value of attribute guild_id.



15
16
17
# File 'lib/rubord/models/interaction.rb', line 15

def guild_id
  @guild_id
end

#idObject (readonly)

Returns the value of attribute id.



15
16
17
# File 'lib/rubord/models/interaction.rb', line 15

def id
  @id
end

#memberObject (readonly)

Returns the value of attribute member.



15
16
17
# File 'lib/rubord/models/interaction.rb', line 15

def member
  @member
end

#messageObject (readonly)

Returns the value of attribute message.



15
16
17
# File 'lib/rubord/models/interaction.rb', line 15

def message
  @message
end

#tokenObject (readonly)

Returns the value of attribute token.



15
16
17
# File 'lib/rubord/models/interaction.rb', line 15

def token
  @token
end

#typeObject (readonly)

Returns the value of attribute type.



15
16
17
# File 'lib/rubord/models/interaction.rb', line 15

def type
  @type
end

#userObject (readonly)

Returns the value of attribute user.



15
16
17
# File 'lib/rubord/models/interaction.rb', line 15

def user
  @user
end

#valuesObject (readonly)

Returns the value of attribute values.



15
16
17
# File 'lib/rubord/models/interaction.rb', line 15

def values
  @values
end

#versionObject (readonly)

Returns the value of attribute version.



15
16
17
# File 'lib/rubord/models/interaction.rb', line 15

def version
  @version
end

Instance Method Details

#command?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/rubord/models/interaction.rb', line 115

def command?
  @type == TYPES[:application_command]
end

#component?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/rubord/models/interaction.rb', line 119

def component?
  @type == TYPES[:message_component]
end

#custom_idObject



127
128
129
# File 'lib/rubord/models/interaction.rb', line 127

def custom_id
  @data["custom_id"]
end

#defer(ephemeral: false) ⇒ Object



98
99
100
101
102
103
104
105
# File 'lib/rubord/models/interaction.rb', line 98

def defer(ephemeral: false)
  client.rest.interactions_response(
    @id,
    @token,
    type: 5,
    flags: ephemeral ? { flags: 64 } : nil
  )
end

#deferUpdateObject



107
108
109
110
111
112
113
# File 'lib/rubord/models/interaction.rb', line 107

def deferUpdate
  client.rest.interactions_response(
    @id,
    @token,
    type: 6
  )
end

#edit(content = nil, embeds: nil, components: nil, flags: nil) ⇒ Object



64
65
66
67
68
69
70
71
72
73
# File 'lib/rubord/models/interaction.rb', line 64

def edit(content = nil, embeds: nil, components: nil, flags: nil)
  client.rest.interaction_edit(
    @application_id,
    @token,
    content: content,
    embeds: embeds,
    components: components,
    flags: flags
  )
end

#followUp(content = nil, embeds: nil, components: nil, flags: nil) ⇒ Object



87
88
89
90
91
92
93
94
95
96
# File 'lib/rubord/models/interaction.rb', line 87

def followUp(content = nil, embeds: nil, components: nil, flags: nil)
  client.rest.interaction_followup(
    @application_id,
    @token,
    content: content,
    embeds: embeds,
    components: components,
    flags: flags
  )
end

#inspectObject



131
132
133
# File 'lib/rubord/models/interaction.rb', line 131

def inspect
  "#<Rubord::Interaction id=#{@id} type=#{@type} guild_id=#{@guild_id} channel_id=#{@channel_id}>"
end

#is_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


123
124
125
# File 'lib/rubord/models/interaction.rb', line 123

def is_type?(type)
  component? && @data["component_type"] == COMPONENT_TYPES[type.to_sym]
end

#reply(content = nil, embeds: nil, components: nil, flags: nil) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rubord/models/interaction.rb', line 52

def reply(content = nil, embeds: nil, components: nil, flags: nil)
  client.rest.interactions_response(
    @id,
    @token,
    type: 4,
    content: content,
    embeds: embeds,
    components: components,
    flags: flags
  )
end

#update(content = nil, embeds: nil, components: nil, flags: nil) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rubord/models/interaction.rb', line 75

def update(content = nil, embeds: nil, components: nil, flags: nil)
  client.rest.interactions_response(
    @id,
    @token,
    type: 7,
    content: content,
    embeds: embeds,
    components: components,
    flags: flags
  )
end