Class: ESM::Command::My::Requests

Inherits:
ApplicationCommand show all
Defined in:
lib/esm/command/my/requests.rb

Instance Method Summary collapse

Instance Method Details

#on_executeObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/esm/command/my/requests.rb', line 19

def on_execute
  requests = current_user.pending_requests.select(
    :uuid, :uuid_short, :command_name, :requestor_user_id, :expires_at
  ).order(:command_name)

  return send_no_requests_message if requests.blank?

  embed = ESM::Embed.build do |e|
    e.title = "Pending Requests"

    e.description = requests.map do |r|
      description = "`#{r.command_name}` - "

      # Performance optimization, only query if needed
      description += "#{r.requestor.distinct} - " if current_user.id != r.requestor_user_id

      description + <<~STRING
        Expires on #{r.expires_at}
        [Accept](#{accept_request_url(r.uuid)}) - `/requests accept uuid:#{r.uuid_short}`
        [Decline](#{decline_request_url(r.uuid)}) - `/requests decline uuid:#{r.uuid_short}`
      STRING
    end.join("\n")
  end

  reply(embed)
end