Class: OnyxCord::Interactions::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/onyxcord/interactions/context.rb

Defined Under Namespace

Classes: Proxy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event, command) ⇒ Context

Returns a new instance of Context.



8
9
10
11
# File 'lib/onyxcord/interactions/context.rb', line 8

def initialize(event, command)
  @event = event
  @command = command
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



6
7
8
# File 'lib/onyxcord/interactions/context.rb', line 6

def command
  @command
end

#eventObject (readonly)

Returns the value of attribute event.



6
7
8
# File 'lib/onyxcord/interactions/context.rb', line 6

def event
  @event
end

Instance Method Details

#botObject



13
14
15
# File 'lib/onyxcord/interactions/context.rb', line 13

def bot
  event.bot
end

#channelObject



35
36
37
# File 'lib/onyxcord/interactions/context.rb', line 35

def channel
  event.channel
end

#channel_idObject



39
40
41
# File 'lib/onyxcord/interactions/context.rb', line 39

def channel_id
  event.channel_id
end

#deferObject



78
79
80
# File 'lib/onyxcord/interactions/context.rb', line 78

def defer(...)
  event.defer(...)
end

#delete_originalObject



86
87
88
# File 'lib/onyxcord/interactions/context.rb', line 86

def delete_original
  event.delete_response
end

#edit_originalObject



82
83
84
# File 'lib/onyxcord/interactions/context.rb', line 82

def edit_original(...)
  event.edit_response(...)
end

#followupObject



90
91
92
# File 'lib/onyxcord/interactions/context.rb', line 90

def followup(...)
  event.send_message(...)
end

#guildObject



27
28
29
# File 'lib/onyxcord/interactions/context.rb', line 27

def guild
  event.server
end

#guild_idObject



31
32
33
# File 'lib/onyxcord/interactions/context.rb', line 31

def guild_id
  event.server_id
end

#guild_localeObject



55
56
57
# File 'lib/onyxcord/interactions/context.rb', line 55

def guild_locale
  event.server_locale
end

#localeObject



51
52
53
# File 'lib/onyxcord/interactions/context.rb', line 51

def locale
  event.user_locale
end

#memberObject



21
22
23
24
25
# File 'lib/onyxcord/interactions/context.rb', line 21

def member
  return unless event.respond_to?(:interaction) && event.interaction

  event.interaction.user if event.interaction.user.is_a?(OnyxCord::Member)
end

#optionsObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/onyxcord/interactions/context.rb', line 59

def options
  return {} unless event.data

  if event.data['options']
    result = {}
    event.data['options'].each do |opt|
      key = opt['name'].to_sym
      result[key] = opt['value']
    end
    result
  else
    {}
  end
end

#respondObject



74
75
76
# File 'lib/onyxcord/interactions/context.rb', line 74

def respond(...)
  event.respond(...)
end

#serverObject



43
44
45
# File 'lib/onyxcord/interactions/context.rb', line 43

def server
  event.server
end

#server_idObject



47
48
49
# File 'lib/onyxcord/interactions/context.rb', line 47

def server_id
  event.server_id
end

#userObject



17
18
19
# File 'lib/onyxcord/interactions/context.rb', line 17

def user
  event.user
end