Class: ESM::Command::Territory::Add

Inherits:
ApplicationCommand show all
Defined in:
lib/esm/command/territory/add.rb

Defined Under Namespace

Modules: V1

Instance Method Summary collapse

Instance Method Details

#on_executeObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/esm/command/territory/add.rb', line 30

def on_execute
  # Either a memer or admin trying to add themselves. Either way, the arma server handles this.
  return on_request_accepted if same_user?

  # Checks for a registered target user.
  # This also keeps people from adding via steam_uid only
  check_for_registered_target_user!
  check_for_pending_request!

  add_request(
    to: target_user,
    description: I18n.t(
      "commands.add.request_description",
      current_user: current_user.distinct,
      target_user: target_user.mention,
      territory_id: arguments.territory_id,
      server_id: target_server.server_id
    )
  )

  embed = ESM::Embed.build(:success, description: I18n.t("commands.request.sent"))
  reply(embed)
end

#on_request_acceptedObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/esm/command/territory/add.rb', line 54

def on_request_accepted
  response = call_sqf_function!(
    "ESMs_command_add",
    territory_id: arguments.territory_id
  )

  # Parse both first in case there are errors
  requestee_embed = embed_from_hash!(response.data.requestee)
  requestor_embed = embed_from_hash!(response.data.requestor)

  # Send to the requestee first since they can be the requestor
  ESM.bot.deliver(requestee_embed, to: target_user)

  # And if they are the same person, don't send them the second message
  return if same_user?

  reply(requestor_embed)
end