From 9c799d337c21e0283fec9f0071d2fffe646eb6d9 Mon Sep 17 00:00:00 2001 From: test Date: Fri, 25 Oct 2024 03:05:52 +1100 Subject: [PATCH 1/3] pojo --- .../v2/impl/pw/filter/NationPlaceholders.java | 3 ++- .../commands/manager/v2/impl/pw/refs/CM.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/filter/NationPlaceholders.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/filter/NationPlaceholders.java index edd3e125..c7e879c5 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/filter/NationPlaceholders.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/filter/NationPlaceholders.java @@ -89,7 +89,8 @@ public Set getSelectorInfo() { new SelectorInfo("USER_ID", "123456789012345678", "A discord user id"), new SelectorInfo("https://politicsandwar.com/index.php?id=15&tax_id=TAX_ID", "https://politicsandwar.com/index.php?id=15&tax_id=1234", "A full tax url"), new SelectorInfo("TAX_ID", "tax_id=1234", "A tax bracket id or url"), - new SelectorInfo("*", null, "All nations") + new SelectorInfo("*", null, "All nations"), + new SelectorInfo("nation(,):SELECTOR", "nation(5d,true):*", "As a sheet tab name; a snapshot selector, with optional timestamp and includeVM") )); } diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/refs/CM.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/refs/CM.java index cba4ff1f..09e8cd97 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/refs/CM.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/refs/CM.java @@ -8664,6 +8664,22 @@ public VM_ALERT_CHANNEL channel(String value) { } } public static class settings_recruit{ + @AutoRegister(clazz=link.locutus.discord.db.guild.GuildKey.class,method="MAIL_NEW_APPLICANTS", field="MAIL_NEW_APPLICANTS") + public static class MAIL_NEW_APPLICANTS extends CommandRef { + public static final MAIL_NEW_APPLICANTS cmd = new MAIL_NEW_APPLICANTS(); + public MAIL_NEW_APPLICANTS enabled(String value) { + return set("enabled", value); + } + + } + @AutoRegister(clazz=link.locutus.discord.db.guild.GuildKey.class,method="MAIL_NEW_APPLICANTS_TEXT", field="MAIL_NEW_APPLICANTS_TEXT") + public static class MAIL_NEW_APPLICANTS_TEXT extends CommandRef { + public static final MAIL_NEW_APPLICANTS_TEXT cmd = new MAIL_NEW_APPLICANTS_TEXT(); + public MAIL_NEW_APPLICANTS_TEXT message(String value) { + return set("message", value); + } + + } @AutoRegister(clazz=link.locutus.discord.db.guild.GuildKey.class,method="RECRUIT_MESSAGE_CONTENT", field="RECRUIT_MESSAGE_CONTENT") public static class RECRUIT_MESSAGE_CONTENT extends CommandRef { public static final RECRUIT_MESSAGE_CONTENT cmd = new RECRUIT_MESSAGE_CONTENT(); From 301afb6e9aae6c5dc5c11387ef6f75e760d17207 Mon Sep 17 00:00:00 2001 From: test Date: Fri, 25 Oct 2024 03:09:20 +1100 Subject: [PATCH 2/3] Update WikiRecruitmentPage.java --- src/main/java/link/locutus/wiki/pages/WikiRecruitmentPage.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/link/locutus/wiki/pages/WikiRecruitmentPage.java b/src/main/java/link/locutus/wiki/pages/WikiRecruitmentPage.java index f6bd4a8c..8f3b46d7 100644 --- a/src/main/java/link/locutus/wiki/pages/WikiRecruitmentPage.java +++ b/src/main/java/link/locutus/wiki/pages/WikiRecruitmentPage.java @@ -37,6 +37,9 @@ public String generateMarkdown() { commandMarkdownSpoiler(CM.settings_recruit.RECRUIT_MESSAGE_DELAY.cmd), "# Send a test message", commandMarkdownSpoiler(CM.mail.recruit.cmd), + "# Configure a message to send new applicants", + commandMarkdownSpoiler(CM.settings_recruit.MAIL_NEW_APPLICANTS.cmd), + commandMarkdownSpoiler(CM.settings_recruit.MAIL_NEW_APPLICANTS_TEXT.cmd), """ # Other recruitment strategies - Members inviting their friends to the game From 4c091fca32824f2b8b63541eb3697ee185668891 Mon Sep 17 00:00:00 2001 From: test Date: Fri, 25 Oct 2024 03:48:37 +1100 Subject: [PATCH 3/3] redirect --- .../web/commands/binding/AuthBindings.java | 4 ++-- .../web/commands/page/EndpointPages.java | 2 +- .../discord/web/commands/page/IAPages.java | 4 ++++ .../discord/web/commands/page/IndexPages.java | 15 ++++++++------ .../discord/web/commands/page/PageHelper.java | 16 ++++++++++++--- .../discord/web/commands/page/WarPages.java | 2 ++ .../discord/web/jooby/PageHandler.java | 20 ++++++++++--------- src/main/jte/auth/redirect.jte | 7 +++++++ 8 files changed, 49 insertions(+), 21 deletions(-) create mode 100644 src/main/jte/auth/redirect.jte diff --git a/src/main/java/link/locutus/discord/web/commands/binding/AuthBindings.java b/src/main/java/link/locutus/discord/web/commands/binding/AuthBindings.java index 38503083..fff104a0 100644 --- a/src/main/java/link/locutus/discord/web/commands/binding/AuthBindings.java +++ b/src/main/java/link/locutus/discord/web/commands/binding/AuthBindings.java @@ -135,7 +135,7 @@ public static Guild guild(Context context, @Default @Me DBNation nation, @Defaul public static final String TOKEN_URL = "https://discord.com/api/oauth2/token"; public static final String API_URL = "https://discord.com/api/users/@me"; - public static void logout(Context context, @Nullable DBAuthRecord auth, boolean redirect) { + public static void logout(WebStore ws, Context context, @Nullable DBAuthRecord auth, boolean redirect) { for (PageHandler.CookieType type : PageHandler.CookieType.values()) { context.removeCookie(type.getCookieId()); } @@ -143,7 +143,7 @@ public static void logout(Context context, @Nullable DBAuthRecord auth, boolean WebRoot.db().removeToken(auth.getUUID(), auth.getNationIdRaw(), auth.getUserIdRaw()); } if (redirect) { - PageHelper.redirect(context, WebRoot.REDIRECT); + PageHelper.redirect(ws, context, WebRoot.REDIRECT); } } diff --git a/src/main/java/link/locutus/discord/web/commands/page/EndpointPages.java b/src/main/java/link/locutus/discord/web/commands/page/EndpointPages.java index b9a05d43..2daecf4a 100644 --- a/src/main/java/link/locutus/discord/web/commands/page/EndpointPages.java +++ b/src/main/java/link/locutus/discord/web/commands/page/EndpointPages.java @@ -132,7 +132,7 @@ public String login(WebStore ws, Context context, @Default Integer nation, @Defa public String logout(WebStore ws, Context context) throws IOException { DBAuthRecord auth = AuthBindings.getAuth(ws, context, false, false, false); Guild guild = auth == null ? null : AuthBindings.guild(context, auth.getNation(true), auth.getUser(true), false); - AuthBindings.logout(context, auth, false); + AuthBindings.logout(ws, context, auth, false); if (auth != null) { if (guild == null) guild = auth.getDefaultGuild(); Map data = auth.toMap(); diff --git a/src/main/java/link/locutus/discord/web/commands/page/IAPages.java b/src/main/java/link/locutus/discord/web/commands/page/IAPages.java index 93e40624..eac643cc 100644 --- a/src/main/java/link/locutus/discord/web/commands/page/IAPages.java +++ b/src/main/java/link/locutus/discord/web/commands/page/IAPages.java @@ -6,6 +6,7 @@ import link.locutus.discord.commands.manager.v2.binding.WebStore; import link.locutus.discord.commands.manager.v2.binding.annotation.Command; import link.locutus.discord.commands.manager.v2.binding.annotation.Me; +import link.locutus.discord.commands.manager.v2.binding.annotation.NoForm; import link.locutus.discord.commands.manager.v2.impl.discord.permission.IsAlliance; import link.locutus.discord.commands.manager.v2.impl.discord.permission.RolePermission; import link.locutus.discord.db.GuildDB; @@ -51,6 +52,7 @@ public class IAPages { @Command() @RolePermission(Roles.INTERNAL_AFFAIRS_STAFF) @IsAlliance + @NoForm public String iaChannels(WebStore ws, @Me GuildDB db, @Me DBNation me, @Me User author) throws ExecutionException, InterruptedException { IACategory iaCat = db.getIACategory(); iaCat.load(); @@ -154,6 +156,7 @@ public String iaChannels(WebStore ws, @Me GuildDB db, @Me DBNation me, @Me User @Command() @RolePermission(Roles.INTERNAL_AFFAIRS_STAFF) @IsAlliance + @NoForm public Object memberAuditIndex(WebStore ws, @Me GuildDB db) throws IOException { AllianceList alliance = db.getAllianceList(); IACheckup checkup = new IACheckup(db, alliance, true); @@ -193,6 +196,7 @@ public Object memberAuditIndex(WebStore ws, @Me GuildDB db) throws IOException { @Command() @IsAlliance @RolePermission(Roles.INTERNAL_AFFAIRS_STAFF) + @NoForm public Object mentorIndex(WebStore ws, IACategory iaCat, @Me Guild guild, @Me GuildDB db, @Me DBNation me) throws IOException { List mentors = new ArrayList<>(); Roles[] mentorRoles = new Roles[]{Roles.INTERVIEWER, Roles.MENTOR}; diff --git a/src/main/java/link/locutus/discord/web/commands/page/IndexPages.java b/src/main/java/link/locutus/discord/web/commands/page/IndexPages.java index 3221ab17..75e0a618 100644 --- a/src/main/java/link/locutus/discord/web/commands/page/IndexPages.java +++ b/src/main/java/link/locutus/discord/web/commands/page/IndexPages.java @@ -211,6 +211,7 @@ private void recursive(CommandCallable root, Consumer onEach) { } @Command() + @NoForm public Object guildindex(WebStore ws, @Me GuildDB db, @Me User user, ArgumentStack stack) { CommandGroup commands = Locutus.imp().getCommandManager().getV2().getCommands(); CommandGroup pages = WebRoot.getInstance().getPageHandler().getCommands(); @@ -230,9 +231,10 @@ public Object guildindex(WebStore ws, @Me GuildDB db, @Me User user, ArgumentSta } @Command() + @NoForm public Object register(WebStore ws, Context context, @Default @Me User user) throws IOException { if (user == null) { - return PageHelper.redirect(context, AuthBindings.getDiscordAuthUrl()); + return PageHelper.redirect(ws, context, AuthBindings.getDiscordAuthUrl()); } DBAuthRecord auth = AuthBindings.getAuth(ws, context, true, true, true); return WebStore.render(f -> JteunregisterGenerated.render(f, null, ws)); @@ -249,7 +251,7 @@ public Object login(WebStore ws, Context context, @Default @Me GuildDB current, // return and redirect String url = AuthBindings.getRedirect(context, true); if (url != null) { - return PageHelper.redirect(context, url); + return PageHelper.redirect(ws, context, url); } Map result = new HashMap<>(); if (nation != null) { @@ -271,9 +273,9 @@ public Object login(WebStore ws, Context context, @Default @Me GuildDB current, } @Command() - public Object setguild(Context context, Guild guild) { + public Object setguild(WebStore ws, Context context, Guild guild) { AuthBindings.setGuild(context, guild); - return PageHelper.redirect(context, AuthBindings.getRedirect(context, true)); + return PageHelper.redirect(ws, context, AuthBindings.getRedirect(context, true)); } @Command() @@ -329,12 +331,13 @@ public Object logout(WebStore ws, Context context, @Me @Default DBAuthRecord aut if (context.method() != HandlerType.POST) { return WebStore.render(f -> JtelogoutGenerated.render(f, null, ws, auth)); } else { - AuthBindings.logout(context, auth, true); + AuthBindings.logout(ws, context, auth, true); return null; } } @Command + @NoForm public Object unregister(WebStore ws, Context context, @Me @Default DBAuthRecord auth) throws IOException { if (auth == null) { return "You are not logged in"; @@ -349,7 +352,7 @@ public Object unregister(WebStore ws, Context context, @Me @Default DBAuthRecord } Locutus.imp().getDiscordDB().unregister(nationId, userId); Locutus.imp().getDiscordDB().deleteApiKeyPairByNation(nationId); - AuthBindings.logout(context, auth, true); + AuthBindings.logout(ws, context, auth, true); return "Unregistering. If you are not redirected, please visit " + WebRoot.REDIRECT + ""; } } diff --git a/src/main/java/link/locutus/discord/web/commands/page/PageHelper.java b/src/main/java/link/locutus/discord/web/commands/page/PageHelper.java index f1c6818d..9f398885 100644 --- a/src/main/java/link/locutus/discord/web/commands/page/PageHelper.java +++ b/src/main/java/link/locutus/discord/web/commands/page/PageHelper.java @@ -1,13 +1,23 @@ package link.locutus.discord.web.commands.page; import io.javalin.http.Context; +import link.locutus.discord.commands.manager.v2.binding.WebStore; import link.locutus.discord.util.MarkupUtil; +import gg.jte.generated.precompiled.auth.JteredirectGenerated; +import java.net.MalformedURLException; +import java.net.URL; public class PageHelper { - public static String redirect(Context context, String url) { + public static String redirect(WebStore ws, Context context, String url) { context.redirect(url); - context.status(304); + context.status(302); context.header("cache-control", "no-store"); - return "Redirecting to " + MarkupUtil.htmlUrl(url, url) + ". If you are not redirected, click the link."; + URL urlObj; + try { + urlObj = new URL(url); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } + return WebStore.render(f -> JteredirectGenerated.render(f, null, ws, urlObj)); } } diff --git a/src/main/java/link/locutus/discord/web/commands/page/WarPages.java b/src/main/java/link/locutus/discord/web/commands/page/WarPages.java index a32c2616..4a7f69a3 100644 --- a/src/main/java/link/locutus/discord/web/commands/page/WarPages.java +++ b/src/main/java/link/locutus/discord/web/commands/page/WarPages.java @@ -3,6 +3,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList; import link.locutus.discord.Locutus; import link.locutus.discord.commands.manager.v2.binding.WebStore; +import link.locutus.discord.commands.manager.v2.binding.annotation.NoForm; import link.locutus.discord.commands.manager.v2.impl.pw.refs.CM; import link.locutus.discord.commands.WarCategory; import link.locutus.discord.commands.manager.v2.binding.annotation.Command; @@ -52,6 +53,7 @@ public class WarPages { // } @Command(desc = "Wars which are currently uncountered") + @NoForm @RolePermission(Roles.MILCOM) public String counter(WebStore ws, @Me GuildDB db) { Set offshore = db.getCoalition(Coalition.OFFSHORE); diff --git a/src/main/java/link/locutus/discord/web/jooby/PageHandler.java b/src/main/java/link/locutus/discord/web/jooby/PageHandler.java index 4c7cca68..e559c7a9 100644 --- a/src/main/java/link/locutus/discord/web/jooby/PageHandler.java +++ b/src/main/java/link/locutus/discord/web/jooby/PageHandler.java @@ -413,8 +413,10 @@ private ArgumentStack createStack(Context ctx, List args) { } private void handleCommand(Context ctx) { + WebStore ws = null; try { ArgumentStack stack = createStack(ctx); + ws = stack.getStore().getProvided(WebStore.class); ctx.header("Content-Type", "text/html;charset=UTF-8"); String path = stack.getCurrent(); boolean isPost = ctx.method() == HandlerType.POST; @@ -434,8 +436,7 @@ private void handleCommand(Context ctx) { String prefix = cmd instanceof ParametricCallable ? "sse" : "command"; String endpoint = WebRoot.REDIRECT + "/" + prefix + "/" + cmd.getFullPath("/"); if (!endpoint.endsWith("/")) endpoint += "/"; - ctx.result(WebUtil.minify(cmd.toHtml(stack.getStore().getProvided(WebStore.class), stack.getPermissionHandler(), endpoint, true))); - ctx.status(200); + ctx.result(WebUtil.minify(cmd.toHtml(ws, stack.getPermissionHandler(), endpoint, true))); break; } // page @@ -463,13 +464,12 @@ private void handleCommand(Context ctx) { } Object[] parsed = parametric.parseArgumentMap(queryMap, stack.getStore(), validators, permisser); Object cmdResult = parametric.call(parametric.getObject(), stack.getStore(), parsed); - result = wrap(stack.getStore().getProvided(WebStore.class), cmdResult, ctx); + result = wrap(ws, cmdResult, ctx); } else { - result = cmd.toHtml(stack.getStore().getProvided(WebStore.class), stack.getPermissionHandler(), false); + result = cmd.toHtml(ws, stack.getPermissionHandler(), false); } if (result != null && (!(result instanceof String) || !result.toString().isEmpty())) { ctx.result(WebUtil.minify(result.toString())); - ctx.status(200); } else if (result != null) { throw new IllegalArgumentException("Illegal result: " + result + " for " + path); } else { @@ -479,11 +479,11 @@ private void handleCommand(Context ctx) { } } catch (Throwable e) { System.out.println("Throwable " + e.getMessage()); - handleErrors(e, ctx); + handleErrors(e, ws, ctx); } } - private void handleErrors(Throwable e, Context ctx) { + private void handleErrors(Throwable e, WebStore ws, Context ctx) { while (e.getCause() != null) { Throwable tmp = e.getCause(); if (tmp == e) break; @@ -497,7 +497,7 @@ private void handleErrors(Throwable e, Context ctx) { ctx.result(WebUtil.minify(msg)); return; } - PageHelper.redirect(ctx, redirectResponse.getMessage()); + PageHelper.redirect(ws, ctx, redirectResponse.getMessage()); return; } e.printStackTrace(); @@ -581,6 +581,7 @@ private LocalValueStore setupLocals(LocalValueStore locals, Context ctx, } public void sseCmdPage(SseClient2 sse) throws IOException { + WebStore ws = null; try { Context ctx = sse.ctx; String pathStr = ctx.path(); @@ -588,6 +589,7 @@ public void sseCmdPage(SseClient2 sse) throws IOException { List path = new ArrayList<>(Arrays.asList(pathStr.split("/"))); path.remove("command"); LocalValueStore locals = setupLocals(null, ctx, path); + ws = (WebStore) locals.getProvided(WebStore.class); CommandCallable cmd = commands.getCallable(path); if (cmd == null) { sseMessage(sse, "Command not found: " + path, false); @@ -618,7 +620,7 @@ public void sseCmdPage(SseClient2 sse) throws IOException { response.addProperty("value", redirect); sse.sendEvent(response); } catch (Throwable e) { - handleErrors(e, sse.ctx); + handleErrors(e, ws, sse.ctx); } } diff --git a/src/main/jte/auth/redirect.jte b/src/main/jte/auth/redirect.jte new file mode 100644 index 00000000..d1120551 --- /dev/null +++ b/src/main/jte/auth/redirect.jte @@ -0,0 +1,7 @@ +@param link.locutus.discord.commands.manager.v2.binding.WebStore ws +@param java.net.URL url + +@template.main(ws = ws, content = @` + Redirecting to ${url.toString()} + If you are not redirected, click the link. +`, title = "Redirect", navbar = null) \ No newline at end of file