Skip to content

Commit

Permalink
Transfer pings
Browse files Browse the repository at this point in the history
  • Loading branch information
xdnw committed Feb 28, 2025
1 parent c418687 commit 4beef2f
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public String onCommand(Guild guild, IMessageIO channel, User author, DBNation m
taxAccount,
flags.contains('t'),
flags.contains('b'),
false, null,
flags.contains('f'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@ public String onCommand(Guild guild, IMessageIO channel, User author, DBNation m
String.valueOf(bypassChecks)
).toJson();

return BankCommands.transfer(channel, command, author, me, guildDb, receiver, transfer, depositType, nationAccount, allianceAccount, offshoreAccount, taxAccount, false, onlyMissingFunds, expire, decay, token, convertCash, escrowMode, bypassChecks, false);
return BankCommands.transfer(channel, command, author, me, guildDb, receiver, transfer, depositType, nationAccount, allianceAccount, offshoreAccount, taxAccount, false, onlyMissingFunds, expire, decay, token, convertCash, escrowMode, bypassChecks, false, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1333,9 +1333,14 @@ public static String disburse(@Me User author, @Me GuildDB db, @Me IMessageIO io


@Arg("Skip checking receiver activity, blockade, VM etc.")
@Switch("b") boolean bypass_checks,
@Switch("b") boolean bypass_checks,
@Switch("p") boolean ping_when_sent,
@Switch("pr") Roles ping_role,
@Switch("f") boolean force) throws GeneralSecurityException, IOException, ExecutionException, InterruptedException {
Set<DBNation> nations = new HashSet<>(nationList.getNations());
if (ping_when_sent && nations.size() > 1) {
throw new IllegalArgumentException("Cannot set `ping_when_sent` for multiple nations");
}

AllianceList allianceList = db.getAllianceList();
if (allianceList == null) {
Expand Down Expand Up @@ -1442,10 +1447,16 @@ else if (!bypass_checks) {
String.valueOf(deduct_as_cash)).escrow_mode(
escrow_mode == null ? null : escrow_mode.name()).bypassChecks(
String.valueOf(bypass_checks)).force(
String.valueOf(force)
).toJson();
String.valueOf(force)).ping_when_sent(
ping_when_sent ? "true" : null).toJson();

return transfer(io, command, author, me, db, nation, transfer, bank_note, nation_account, ingame_bank, offshore_account, tax_account, use_receiver_tax_account, false, expire, decay, null, deduct_as_cash, escrow_mode, bypass_checks, force);
if (ping_role != null) {
Role role = ping_role.toRole2(db);
if (role != null) {
io.send(role.getAsMention());
}
}
return transfer(io, command, author, me, db, nation, transfer, bank_note, nation_account, ingame_bank, offshore_account, tax_account, use_receiver_tax_account, false, expire, decay, null, deduct_as_cash, escrow_mode, bypass_checks, ping_when_sent, force);
} else {
UUID key = UUID.randomUUID();
TransferSheet sheet = new TransferSheet(db).write(fundsToSendNations, new LinkedHashMap<>()).build();
Expand Down Expand Up @@ -1859,6 +1870,7 @@ public String withdraw(@Me IMessageIO channel, @Me JSONObject command,
deduct_as_cash,
escrow_mode,
bypass_checks,
false,
force);
}

Expand Down Expand Up @@ -2095,6 +2107,7 @@ public static String transfer(@Me IMessageIO channel, @Me JSONObject command,
@Arg("Transfer valued at cash equivalent in nation holdings") @Switch("c") boolean convertCash,
@Arg("The mode for escrowing funds (e.g. if the receiver is blockaded)\nDefaults to never") @Switch("em") EscrowMode escrow_mode,
@Switch("b") boolean bypassChecks,
@Switch("p") boolean ping_when_sent,
@Switch("f") boolean force) throws IOException {
if (existingTaxAccount) {
if (taxAccount != null) throw new IllegalArgumentException("You can't specify both `tax_id` and `existingTaxAccount`");
Expand Down Expand Up @@ -2237,7 +2250,23 @@ public static String transfer(@Me IMessageIO channel, @Me JSONObject command,
return null;
}

channel.create().embed(result.toTitleString(), result.toEmbedString()).send();
IMessageBuilder msg = channel.create().embed(result.toTitleString(), result.toEmbedString());

if (ping_when_sent && receiver.isNation()) {
User user = receiver.asNation().getUser();
if (user != null) {
MessageChannel notify = GuildKey.GRANT_REQUEST_CHANNEL.getOrNull(guildDb);
if (notify == null) notify = guildDb.getResourceChannel(receiver.getAlliance_id());
if (notify == null) notify = guildDb.getResourceChannel(0);
if (notify != null) {
DiscordUtil.sendMessage(notify, user.getAsMention() + " " + result.getMessageJoined(false));
} else {
msg.append(user.getAsMention());
}
}
}

msg.send();
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public String grantCity(
@Switch("er") boolean exclude_city_refund,

@Switch("pr") Roles ping_role,
@Switch("cc") MessageChannel ping_when_sent,
@Switch("ps") boolean ping_when_sent,

@Switch("b") boolean bypass_checks,
@Switch("f") boolean force
Expand All @@ -103,7 +103,7 @@ public String grantCity(
int currentCity = receiver.getCities();
return Math.max(upTo ? amount - currentCity : amount, 0);
};
return Grant.generateCommandLogic(io, db, me, author, receivers, onlySendMissingFunds, depositsAccount, useAllianceBank, useOffshoreAccount, taxAccount, existingTaxAccount, expire, decay, ignore, convertToMoney, escrow_mode, bypass_checks, force,
return Grant.generateCommandLogic(io, db, me, author, receivers, onlySendMissingFunds, depositsAccount, useAllianceBank, useOffshoreAccount, taxAccount, existingTaxAccount, expire, decay, ignore, convertToMoney, escrow_mode, bypass_checks, ping_role, ping_when_sent, force,
(receiver, grant) -> {
int currentCity = receiver.getCities();
int numBuy = getNumBuy.apply(receiver);
Expand Down Expand Up @@ -171,10 +171,13 @@ public String grantProject(
@Arg(value = "Apply the specified project for determining cost", group = 4) @Switch("gsa") Boolean gov_support_agency,
@Arg(value = "Apply the specified project for determining cost", group = 4) @Switch("bda") Boolean domestic_affairs,

@Switch("pr") Roles ping_role,
@Switch("ps") boolean ping_when_sent,

@Switch("b") boolean bypass_checks,
@Switch("f") boolean force
) throws IOException, GeneralSecurityException {
return Grant.generateCommandLogic(io, db, me, author, receivers, onlySendMissingFunds, depositsAccount, useAllianceBank, useOffshoreAccount, taxAccount, existingTaxAccount, expire, decay, ignore, convertToMoney, escrow_mode, bypass_checks, force,
return Grant.generateCommandLogic(io, db, me, author, receivers, onlySendMissingFunds, depositsAccount, useAllianceBank, useOffshoreAccount, taxAccount, existingTaxAccount, expire, decay, ignore, convertToMoney, escrow_mode, bypass_checks, ping_role, ping_when_sent, force,
(receiver, grant) -> {
if (receiver.hasProject(project)) {
return new TransferResult(OffshoreInstance.TransferStatus.NOTHING_WITHDRAWN, receiver, new HashMap<>(), DepositType.PROJECT.withValue().toString()).addMessage("Nation already has project: " + project.name());
Expand Down Expand Up @@ -228,12 +231,13 @@ public String grantInfra(
@Arg(value = "Apply the specified project for determining cost", group = 4) @Switch("cfce") Boolean center_for_civil_engineering,
@Arg(value = "Apply the specified project for determining cost", group = 4) @Switch("gsa") Boolean gov_support_agency,
@Arg(value = "Apply the specified project for determining cost", group = 4) @Switch("bda") Boolean domestic_affairs,

@Switch("pr") Roles ping_role,
@Switch("ps") boolean ping_when_sent,
@Switch("b") boolean bypass_checks,
@Switch("f") boolean force

) throws IOException, GeneralSecurityException {
return Grant.generateCommandLogic(io, db, me, author, receivers, onlySendMissingFunds, depositsAccount, useAllianceBank, useOffshoreAccount, taxAccount, existingTaxAccount, expire, decay, ignore, convertToMoney, escrow_mode, bypass_checks, force,
return Grant.generateCommandLogic(io, db, me, author, receivers, onlySendMissingFunds, depositsAccount, useAllianceBank, useOffshoreAccount, taxAccount, existingTaxAccount, expire, decay, ignore, convertToMoney, escrow_mode, bypass_checks, ping_role, ping_when_sent, force,
(receiver, grant) -> {
double cost;
if (single_new_city) {
Expand Down Expand Up @@ -301,11 +305,12 @@ public String grantLand(
@Arg(value = "Apply the specified project for determining cost", group = 4) @Switch("ala") Boolean arable_land_agency,
@Arg(value = "Apply the specified project for determining cost", group = 4) @Switch("gsa") Boolean gov_support_agency,
@Arg(value = "Apply the specified project for determining cost", group = 4) @Switch("bda") Boolean domestic_affairs,

@Switch("pr") Roles ping_role,
@Switch("ps") boolean ping_when_sent,
@Switch("b") boolean bypass_checks,
@Switch("f") boolean force
) throws IOException, GeneralSecurityException {
return Grant.generateCommandLogic(io, db, me, author, receivers, onlySendMissingFunds, depositsAccount, useAllianceBank, useOffshoreAccount, taxAccount, existingTaxAccount, expire, decay, ignore, convertToMoney, escrow_mode, bypass_checks, force,
return Grant.generateCommandLogic(io, db, me, author, receivers, onlySendMissingFunds, depositsAccount, useAllianceBank, useOffshoreAccount, taxAccount, existingTaxAccount, expire, decay, ignore, convertToMoney, escrow_mode, bypass_checks, ping_role, ping_when_sent, force,
(receiver, grant) -> {
double cost = receiver.getBuyLandCost(to_land,
rapid_expansion != null ? rapid_expansion : false,
Expand Down Expand Up @@ -357,11 +362,12 @@ public String grantUnit(
@Arg(value = "Have the transfer valued as cash in nation holdings", group = 2)@Switch("c") boolean convertToMoney,

@Arg(value = "The mode for escrowing funds (e.g. if the receiver is blockaded)\nDefaults to never", group = 3) @Switch("em") EscrowMode escrow_mode,

@Switch("pr") Roles ping_role,
@Switch("ps") boolean ping_when_sent,
@Switch("b") boolean bypass_checks,
@Switch("f") boolean force
) throws IOException, GeneralSecurityException {
return Grant.generateCommandLogic(io, db, me, author, receivers, onlySendMissingFunds, depositsAccount, useAllianceBank, useOffshoreAccount, taxAccount, existingTaxAccount, expire, decay, ignore, convertToMoney, escrow_mode, bypass_checks, force,
return Grant.generateCommandLogic(io, db, me, author, receivers, onlySendMissingFunds, depositsAccount, useAllianceBank, useOffshoreAccount, taxAccount, existingTaxAccount, expire, decay, ignore, convertToMoney, escrow_mode, bypass_checks, ping_role, ping_when_sent, force,
(receiver, grant) -> {
Map<MilitaryUnit, Long> unitsToGrant = new HashMap<>();
units.forEach((unit, amount) -> {
Expand Down Expand Up @@ -415,11 +421,12 @@ public String grantMMR(
@Arg(value = "Have the transfer not deduct from balance", group = 2) @Switch("i") boolean ignore,
@Arg(value = "Have the transfer valued as cash in nation holdings", group = 2) @Switch("c") boolean convertToMoney,
@Arg(value = "The mode for escrowing funds (e.g. if the receiver is blockaded)\nDefaults to never", group = 3) @Switch("em") EscrowMode escrow_mode,

@Switch("pr") Roles ping_role,
@Switch("ps") boolean ping_when_sent,
@Switch("b") boolean bypass_checks,
@Switch("f") boolean force
) throws IOException, GeneralSecurityException {
return Grant.generateCommandLogic(io, db, me, author, receivers, onlySendMissingFunds, depositsAccount, useAllianceBank, useOffshoreAccount, taxAccount, existingTaxAccount, expire, decay, ignore, convertToMoney, escrow_mode, bypass_checks, force,
return Grant.generateCommandLogic(io, db, me, author, receivers, onlySendMissingFunds, depositsAccount, useAllianceBank, useOffshoreAccount, taxAccount, existingTaxAccount, expire, decay, ignore, convertToMoney, escrow_mode, bypass_checks, ping_role, ping_when_sent, force,
(receiver, grant) -> {
int cities = receiver.getCities();
Map<MilitaryUnit, Integer> unitsToGrant = new HashMap<>();
Expand Down Expand Up @@ -482,11 +489,12 @@ public String grantConsumption(
@Arg(value = "Have the transfer not deduct from balance", group = 3) @Switch("i") boolean ignore,
@Arg(value = "Have the transfer valued as cash in nation holdings", group = 3)@Switch("c") boolean convertToMoney,
@Arg(value = "The mode for escrowing funds (e.g. if the receiver is blockaded)\nDefaults to never", group = 4) @Switch("em") EscrowMode escrow_mode,

@Switch("pr") Roles ping_role,
@Switch("ps") boolean ping_when_sent,
@Switch("b") boolean bypass_checks,
@Switch("f") boolean force
) throws IOException, GeneralSecurityException {
return Grant.generateCommandLogic(io, db, me, author, receivers, onlySendMissingFunds, depositsAccount, useAllianceBank, useOffshoreAccount, taxAccount, existingTaxAccount, expire, decay, ignore, convertToMoney, escrow_mode, bypass_checks, force,
return Grant.generateCommandLogic(io, db, me, author, receivers, onlySendMissingFunds, depositsAccount, useAllianceBank, useOffshoreAccount, taxAccount, existingTaxAccount, expire, decay, ignore, convertToMoney, escrow_mode, bypass_checks, ping_role, ping_when_sent, force,
(receiver, grant) -> {
int cities = receiver.getCities();
Map<MilitaryUnit, Integer> numAttacks = new LinkedHashMap<>(Map.of(
Expand Down Expand Up @@ -559,6 +567,8 @@ public String grantBuild(
@Arg(value = "Have the transfer valued as cash in nation holdings", group = 3) @Switch("c") boolean convertToMoney,

@Arg(value = "The mode for escrowing funds (e.g. if the receiver is blockaded)\nDefaults to never", group = 4) @Switch("em") EscrowMode escrow_mode,
@Switch("pr") Roles ping_role,
@Switch("ps") boolean ping_when_sent,
@Switch("b") boolean bypass_checks,
@Switch("f") boolean force
) throws IOException, GeneralSecurityException {
Expand All @@ -580,7 +590,7 @@ public String grantBuild(
if (!notes.isEmpty()) {
notes.add("You can append partial city json to a city url to modify an existing build");
}
return Grant.generateCommandLogic(io, db, me, author, receivers, onlySendMissingFunds, depositsAccount, useAllianceBank, useOffshoreAccount, taxAccount, existingTaxAccount, expire, decay, ignore, convertToMoney, escrow_mode, bypass_checks, force,
return Grant.generateCommandLogic(io, db, me, author, receivers, onlySendMissingFunds, depositsAccount, useAllianceBank, useOffshoreAccount, taxAccount, existingTaxAccount, expire, decay, ignore, convertToMoney, escrow_mode, bypass_checks, ping_role, ping_when_sent, force,
(receiver, grant) -> {
JavaCity grantTo = new JavaCity(build);
try {
Expand Down Expand Up @@ -668,10 +678,12 @@ public String grantWarchest(
@Arg(value = "Have the transfer valued as cash in nation holdings", group = 2) @Switch("c") boolean convertToMoney,

@Arg(value = "The mode for escrowing funds (e.g. if the receiver is blockaded)\nDefaults to never", group = 3) @Switch("em") EscrowMode escrow_mode,
@Switch("pr") Roles ping_role,
@Switch("ps") boolean ping_when_sent,
@Switch("b") boolean bypass_checks,
@Switch("f") boolean force
) throws IOException, GeneralSecurityException {
return Grant.generateCommandLogic(io, db, me, author, receivers, onlySendMissingFunds, depositsAccount, useAllianceBank, useOffshoreAccount, taxAccount, existingTaxAccount, expire, decay, ignore, convertToMoney, escrow_mode, bypass_checks, force,
return Grant.generateCommandLogic(io, db, me, author, receivers, onlySendMissingFunds, depositsAccount, useAllianceBank, useOffshoreAccount, taxAccount, existingTaxAccount, expire, decay, ignore, convertToMoney, escrow_mode, bypass_checks, ping_role, ping_when_sent, force,
(receiver, grant) -> {
int cities = receiver.getCities();
Map<ResourceType, Double> perCity = db.getPerCityWarchest(receiver);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16208,7 +16208,9 @@ public resources bypassChecks(String value) {
public resources force(String value) {
return set("force", value);
}

public resources ping_when_sent(String value) {
return set("ping_when_sent", value);
}
}
@AutoRegister(clazz=link.locutus.discord.commands.manager.v2.impl.pw.commands.BankCommands.class,method="withdraw")
public static class self extends CommandRef {
Expand Down
Loading

0 comments on commit 4beef2f

Please sign in to comment.