Class: Rubord::Interaction
- Inherits:
-
Object
- Object
- Rubord::Interaction
- 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
-
#application_id ⇒ Object
readonly
Returns the value of attribute application_id.
-
#channel_id ⇒ Object
readonly
Returns the value of attribute channel_id.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#guild_id ⇒ Object
readonly
Returns the value of attribute guild_id.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#member ⇒ Object
readonly
Returns the value of attribute member.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #command? ⇒ Boolean
- #component? ⇒ Boolean
- #custom_id ⇒ Object
- #defer(ephemeral: false) ⇒ Object
- #deferUpdate ⇒ Object
- #edit(content = nil, embeds: nil, components: nil, flags: nil) ⇒ Object
- #followUp(content = nil, embeds: nil, components: nil, flags: nil) ⇒ Object
-
#initialize(data, client) ⇒ Interaction
constructor
A new instance of Interaction.
- #inspect ⇒ Object
- #is_type?(type) ⇒ Boolean
- #reply(content = nil, embeds: nil, components: nil, flags: nil) ⇒ Object
- #update(content = nil, embeds: nil, components: nil, flags: nil) ⇒ Object
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_id ⇒ Object (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_id ⇒ Object (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 |
#client ⇒ Object (readonly)
Returns the value of attribute client.
15 16 17 |
# File 'lib/rubord/models/interaction.rb', line 15 def client @client end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
15 16 17 |
# File 'lib/rubord/models/interaction.rb', line 15 def data @data end |
#guild_id ⇒ Object (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 |
#id ⇒ Object (readonly)
Returns the value of attribute id.
15 16 17 |
# File 'lib/rubord/models/interaction.rb', line 15 def id @id end |
#member ⇒ Object (readonly)
Returns the value of attribute member.
15 16 17 |
# File 'lib/rubord/models/interaction.rb', line 15 def member @member end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
15 16 17 |
# File 'lib/rubord/models/interaction.rb', line 15 def @message end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
15 16 17 |
# File 'lib/rubord/models/interaction.rb', line 15 def token @token end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
15 16 17 |
# File 'lib/rubord/models/interaction.rb', line 15 def type @type end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
15 16 17 |
# File 'lib/rubord/models/interaction.rb', line 15 def user @user end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
15 16 17 |
# File 'lib/rubord/models/interaction.rb', line 15 def values @values end |
#version ⇒ Object (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
115 116 117 |
# File 'lib/rubord/models/interaction.rb', line 115 def command? @type == TYPES[:application_command] end |
#component? ⇒ Boolean
119 120 121 |
# File 'lib/rubord/models/interaction.rb', line 119 def component? @type == TYPES[:message_component] end |
#custom_id ⇒ Object
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 |
#deferUpdate ⇒ Object
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: , 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: , components: components, flags: flags ) end |
#inspect ⇒ Object
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
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: , 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: , components: components, flags: flags ) end |