Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
xdnw committed Jun 17, 2024
2 parents c1bf1d9 + b7aebe4 commit 67821db
Show file tree
Hide file tree
Showing 87 changed files with 14,457 additions and 5,140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public String onCommand(Guild guild, IMessageIO channel, User author, DBNation m

if (args.get(0).equalsIgnoreCase("*")) {
if (!Roles.INTERNAL_AFFAIRS.has(author, guild)) return "No permission";
JSONObject command = CM.role.autoassign.cmd.create(force + "").toJson();
JSONObject command = CM.role.autoassign.cmd.force(force + "").toJson();
return UtilityCommands.autoroleall(author, db, channel, command, force);
} else {
DBNation nation = DiscordUtil.parseNation(args.get(0));
Expand All @@ -64,7 +64,7 @@ public String onCommand(Guild guild, IMessageIO channel, User author, DBNation m
if (user == null) return "User is not registered.";
Member member = db.getGuild().getMember(user);
if (member == null) return "Member not found in guild: " + DiscordUtil.getFullUsername(user);
JSONObject command = CM.role.autorole.cmd.create(user.getAsMention(), force + "").toJson();
JSONObject command = CM.role.autorole.cmd.member(user.getAsMention()).force(force + "").toJson();
return UtilityCommands.autorole(db, channel, command, member, force);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public String register(Guild guild, GuildDB db, User user, int nationId, boolean
"2. Scroll down to where it says Discord Username:\n" +
"3. Put your discord username `" + fullDiscriminator + "` in the field\n" +
"4. Click save\n" +
"5. Run the command " + CM.register.cmd.create(nationId + "").toSlashCommand() + " again";
"5. Run the command " + CM.register.cmd.nation(nationId + "").toSlashCommand() + " again";

long id = user.getIdLong();
boolean checkId = false;
Expand All @@ -167,7 +167,7 @@ public String register(Guild guild, GuildDB db, User user, int nationId, boolean
"2. Scroll down to where it says Discord Username:\n" +
"3. Put your **DISCORD ID** `" + user.getIdLong() + "` in the field\n" +
"4. Click save\n" +
"5. Run the command " + CM.register.cmd.create(nationId + "").toSlashCommand() + " again";
"5. Run the command " + CM.register.cmd.nation(nationId + "").toSlashCommand() + " again";
checkId = fullDiscriminator.contains("#");
}
}
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/link/locutus/discord/commands/bank/GrantCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,22 +268,22 @@ else if (args.get(1).equalsIgnoreCase("warchest")) {
resources = PW.multiply(resources, factor);
}

JSONObject command = CM.transfer.resources.cmd.create(
me.getUrl(),
ResourceType.resourcesToString(resources),
grant.getType().toString(),
(nationAccount == null ? me : nationAccount).getUrl(),
allianceAccount != null ? allianceAccount.getUrl() : null,
offshoreAccount != null ? offshoreAccount.getUrl() : null,
taxAccount != null ? taxAccount.getQualifiedId() : null,
flags.contains('t') ? "true" : null,
String.valueOf(flags.contains('o')),
expire != null ? TimeUtil.secToTime(TimeUnit.MILLISECONDS, expire) : null,
decay != null ? TimeUtil.secToTime(TimeUnit.MILLISECONDS, decay) : null,
uuid.toString(),
String.valueOf(flags.contains('c')),
escrowMode == null ? null : escrowMode.name(),
String.valueOf(flags.contains('f')),
JSONObject command = CM.transfer.resources.cmd.receiver(
me.getUrl()).transfer(
ResourceType.resourcesToString(resources)).depositType(
grant.getType().toString()).nationAccount(
(nationAccount == null ? me : nationAccount).getUrl()).senderAlliance(
allianceAccount != null ? allianceAccount.getUrl() : null).allianceAccount(
offshoreAccount != null ? offshoreAccount.getUrl() : null).taxAccount(
taxAccount != null ? taxAccount.getQualifiedId() : null).existingTaxAccount(
flags.contains('t') ? "true" : null).onlyMissingFunds(
String.valueOf(flags.contains('o'))).expire(
expire != null ? TimeUtil.secToTime(TimeUnit.MILLISECONDS, expire) : null).decay(
decay != null ? TimeUtil.secToTime(TimeUnit.MILLISECONDS, decay) : null).token(
uuid.toString()).convertCash(
String.valueOf(flags.contains('c'))).escrow_mode(
escrowMode == null ? null : escrowMode.name()).bypassChecks(
String.valueOf(flags.contains('f'))).force(
"false"
).toJson();
StringBuilder msg = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,21 @@ public String onCommand(Guild guild, IMessageIO channel, User author, DBNation m

UUID token = null;
// String receiver, String transfer, String depositType, String nationAccount, String senderAlliance, String allianceAccount, String onlyMissingFunds, String expire, String token, String convertCash, String bypassChecks
JSONObject command = CM.transfer.resources.cmd.create(
receiver.getUrl(),
ResourceType.resourcesToString(transfer),
depositType.toString(),
nationAccount != null ? nationAccount.getUrl() : null,
allianceAccount != null ? allianceAccount.getUrl() : null,
offshoreAccount != null ? offshoreAccount.getUrl() : null,
taxAccount != null ? taxAccount.getQualifiedId() : null,
null,
String.valueOf(onlyMissingFunds),
expire == null ? null : TimeUtil.secToTime(TimeUnit.MILLISECONDS, expire),
decay == null ? null : TimeUtil.secToTime(TimeUnit.MILLISECONDS, decay),
token == null ? null : token.toString(),
String.valueOf(convertCash),
escrowMode == null ? null : escrowMode.name(),
String.valueOf(bypassChecks),
null
JSONObject command = CM.transfer.resources.cmd.receiver(
receiver.getUrl()).transfer(
ResourceType.resourcesToString(transfer)).depositType(
depositType.toString()).nationAccount(
nationAccount != null ? nationAccount.getUrl() : null).senderAlliance(
allianceAccount != null ? allianceAccount.getUrl() : null).allianceAccount(
offshoreAccount != null ? offshoreAccount.getUrl() : null).taxAccount(
taxAccount != null ? taxAccount.getQualifiedId() : null).onlyMissingFunds(
String.valueOf(onlyMissingFunds)).expire(
expire == null ? null : TimeUtil.secToTime(TimeUnit.MILLISECONDS, expire)).decay(
decay == null ? null : TimeUtil.secToTime(TimeUnit.MILLISECONDS, decay)).token(
token == null ? null : token.toString()).convertCash(
String.valueOf(convertCash)).escrow_mode(
escrowMode == null ? null : escrowMode.name()).bypassChecks(
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public String onCommand(Guild guild, IMessageIO channel, User author, DBNation m
}
}

CM.unit.history cmd = CM.unit.history.cmd.create(nation.getNation_id() + "", unit.name(), null);
CM.unit.history cmd = CM.unit.history.cmd.nation(nation.getNation_id() + "").unit(unit.name());

String title = "`" + nation.getNation() + "` " + unit.name() + " history";
int perPage = 15;
Expand Down
18 changes: 8 additions & 10 deletions src/main/java/link/locutus/discord/commands/info/Who.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,14 @@ public String onCommand(Guild guild, IMessageIO channel, User author, DBNation m
return "Usage: `" + Settings.commandPrefix(true) + "pnw-who <discord-user>`";
}
// String nationOrAlliances, String sortBy, String list, String listAlliances, String listRawUserIds, String listMentions, String listInfo, String listChannels, String page
CM.who command = CM.who.cmd.create(
arg0,
null,
flags.contains('l') ? "True" : null,
flags.contains('a') ? "True" : null,
flags.contains('r') ? "True" : null,
flags.contains('m') ? "True" : null,
flags.contains('i') ? "True" : null,
flags.contains('c') ? "True" : null,
null,
CM.who command = CM.who.cmd.nationOrAlliances(
arg0).list(
flags.contains('l') ? "True" : null).listAlliances(
flags.contains('a') ? "True" : null).listRawUserIds(
flags.contains('r') ? "True" : null).listMentions(
flags.contains('m') ? "True" : null).listInfo(
flags.contains('i') ? "True" : null).listChannels(
flags.contains('c') ? "True" : null).page(
page == null ? null : page.toString()
);
GuildDB db = guild == null ? null : Locutus.imp().getGuildDB(guild);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ private boolean sendPermissionMessage(Command cmd, Guild msgGuild, User msgUser,
{
Role registeredRole = Roles.REGISTERED.toRole(msgGuild);
if (registeredRole == null) {
channel.sendMessage("No registered role set, please have an admin use " + CM.role.setAlias.cmd.create(Roles.REGISTERED.name(), "", null, null).toSlashCommand() + "");
channel.sendMessage("No registered role set, please have an admin use " + CM.role.setAlias.cmd.locutusRole(Roles.REGISTERED.name()).discordRole("").toSlashCommand() + "");
return true;
} else {
assert member != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,6 @@ default void generatePojo(String parentPath, StringBuilder output, int indent) {
} else if (this instanceof ParametricCallable callable) {
Method method = callable.getMethod();
List<String> params = callable.getUserParameterMap().values().stream().map(ParameterData::getName).toList();
// join with comma
String typeArgs = params.stream().map(f -> "String " + f).collect(Collectors.joining(", "));
String args = params.stream().map(f -> "\"" + f + "\", " + f).collect(Collectors.joining(", "));

Class<?> clazz = method.getDeclaringClass();
String className = clazz.getName();
Expand Down Expand Up @@ -214,16 +211,23 @@ default void generatePojo(String parentPath, StringBuilder output, int indent) {
}
}

List<String> argMethods = new ArrayList<>();
for (String arg : params) {
argMethods.add(String.format("""
%1$spublic %2$s %3$s(String value) {
%1$s return set("%3$s", value);
%1$s}
""", indentStr, name, arg));
}

output.append(String.format("""
%1$s@AutoRegister(clazz=%2$s.class,method="%3$s"%7$s)
%1$s@AutoRegister(clazz=%2$s.class,method="%3$s"%5$s)
%1$spublic static class %4$s extends CommandRef {
%1$s public static final %4$s cmd = new %4$s();
%1$s public %4$s create(%5$s) {
%1$s return createArgs(%6$s);
%1$s }
%6$s
%1$s}
""",
indentStr, className, method.getName(), name, typeArgs, args, fieldExt));
indentStr, className, method.getName(), name, fieldExt, String.join("\n", argMethods)));
} else {
throw new IllegalArgumentException("Unknown callable type: " + this.getClass().getSimpleName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ public <T extends CommandRef> T createArgs(String... args) {
return createArgs(argMap);
}

public <T extends CommandRef> T createEmpty() {
return createArgs(new HashMap<>());
}

public <T extends CommandRef> T set(String arg, String value) {
CommandRef instance = this;
if (arguments.isEmpty()) {
instance = createArgs();
}
if (value != null) {
instance.arguments.put(arg, value);
} else {
instance.arguments.remove(arg);
}
return (T) instance;
}

public <T extends CommandRef> T createArgs(Map<String, String> args) {
try {
CommandRef instance = getClass().newInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ default IMessageBuilder modal(CommandBehavior behavior, Long outputChannel, Stri
arguments = arguments.entrySet().stream().collect(Collectors.toMap(e -> e.getKey().toLowerCase(Locale.ROOT),
Map.Entry::getValue, (a, b) -> b, LinkedHashMap::new));
String argumentJson = arguments.isEmpty() ? null : new Gson().toJson(arguments);
CM.modal.create attach = CM.modal.create.cmd.create(path, StringMan.join(promptFor, ","), argumentJson);
CM.modal.create attach = CM.modal.create.cmd.command(path).arguments(StringMan.join(promptFor, ",")).defaults(argumentJson);
return commandButton(behavior, attach, message);
}

Expand Down Expand Up @@ -115,7 +115,7 @@ default IMessageBuilder commandButton(CommandBehavior behavior, Long outputChann

@CheckReturnValue
default IMessageBuilder modalLegacy(CommandBehavior behavior, CommandRef ref, String message) {
CM.fun.say say = CM.fun.say.cmd.create(behavior.getValue() + ref.toSlashCommand());
CM.fun.say say = CM.fun.say.cmd.msg(behavior.getValue() + ref.toSlashCommand());
commandButton(behavior, say, message);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public static CompletableFuture<IModalBuilder> send(IMessageIO io, IModalBuilder
String argName = input.getId();
argList.add(argName);
}
CM.modal.create cmRef = CM.modal.create.cmd.create(cmd, StringMan.join(argList, " "), defaultsStr);
CM.modal.create cmRef = CM.modal.create.cmd.command(cmd).arguments(StringMan.join(argList, " ")).defaults(defaultsStr);
io.create().embed("Form: `" + cmd + "`", cmRef.toSlashCommand(true))
.commandButton(cmRef, "Open")
.send();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ public String announce(@Me GuildDB db, @Me Guild guild, @Me JSONObject command,
msg = msg.append(bottomText);
}

CM.announcement.view cmd = CM.announcement.view.cmd.create(annId + "", null, null);
CM.announcement.view cmd = CM.announcement.view.cmd.ann_id(annId + "");
msg.commandButton(CommandBehavior.EPHEMERAL, cmd, "view").send();
}

Expand Down Expand Up @@ -1296,15 +1296,15 @@ public static String aliasRole(@Me User author, @Me Guild guild, @Me GuildDB db,
}

if (removeRole) {
throw new IllegalArgumentException("Cannot remove role alias with this command. Use " + CM.role.unregister.cmd.create(locutusRole.name(), null).toSlashCommand() + "");
throw new IllegalArgumentException("Cannot remove role alias with this command. Use " + CM.role.unregister.cmd.locutusRole(locutusRole.name()).toSlashCommand() + "");
}


int aaId = alliance == null ? 0 : alliance.getAlliance_id();
String allianceStr = alliance == null ? "*" : alliance.getName() + "/" + aaId;
db.addRole(locutusRole, discordRole, aaId);
return "Added role alias: " + locutusRole.name().toLowerCase() + " to " + discordRole.getName() + " for alliance " + allianceStr + "\n" +
"To unregister, use " + CM.role.unregister.cmd.create(locutusRole.name(), null).toSlashCommand() + "";
"To unregister, use " + CM.role.unregister.cmd.locutusRole(locutusRole.name()).toSlashCommand() + "";
}

public String printApiStats(ApiKeyPool keys) {
Expand Down
Loading

0 comments on commit 67821db

Please sign in to comment.