Skip to content

Commit

Permalink
Add conflict info command
Browse files Browse the repository at this point in the history
  • Loading branch information
xdnw committed May 4, 2024
1 parent 4b70fa6 commit 3cd4c45
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public CommandManager2 registerDefaults() {
getCommands().registerMethod(new WarCommands(), List.of("war", "room"), "deleteForEnemies", "delete_for_enemies");
getCommands().registerMethod(new UtilityCommands(), List.of("land"), "landROI", "roi");
getCommands().registerMethod(new UtilityCommands(), List.of("infra"), "infraROI", "roi");

getCommands().registerMethod(new ConflictCommands(), List.of("conflict"), "syncConflictData", "sync");
getCommands().registerMethod(new ConflictCommands(), List.of("conflict"), "deleteConflict", "delete");
getCommands().registerMethod(new ConflictCommands(), List.of("conflict"), "listConflicts", "list");
Expand All @@ -198,6 +199,7 @@ public CommandManager2 registerDefaults() {
getCommands().registerMethod(new ConflictCommands(), List.of("conflict", "alliance"), "removeCoalition", "remove");
getCommands().registerMethod(new ConflictCommands(), List.of("conflict", "alliance"), "addCoalition", "add");
getCommands().registerMethod(new ConflictCommands(), List.of("conflict"), "importConflictData", "clone");
getCommands().registerMethod(new ConflictCommands(), List.of("conflict"), "info", "info");

getCommands().registerMethod(new AllianceMetricCommands(), List.of("admin", "sync"), "saveMetrics", "saveMetrics");
getCommands().registerMethod(new AllianceMetricCommands(), List.of("stats_tier"), "metricByGroup", "metric_by_group");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package link.locutus.discord.commands.manager.v2.impl.pw.commands;

import link.locutus.discord.db.CoalitionSide;
import link.locutus.discord.util.*;
import link.locutus.discord.util.discord.DiscordUtil;
import link.locutus.wiki.game.PWWikiUtil;
import link.locutus.discord.Locutus;
import link.locutus.discord.apiv1.enums.Rank;
Expand All @@ -19,10 +22,6 @@
import link.locutus.discord.db.entities.Treaty;
import link.locutus.discord.db.entities.conflict.ConflictCategory;
import link.locutus.discord.user.Roles;
import link.locutus.discord.util.MathMan;
import link.locutus.discord.util.PW;
import link.locutus.discord.util.StringMan;
import link.locutus.discord.util.TimeUtil;
import link.locutus.discord.util.math.ArrayUtil;
import link.locutus.discord.web.jooby.AwsManager;
import link.locutus.discord.web.jooby.WebRoot;
Expand Down Expand Up @@ -65,6 +64,54 @@
import java.util.stream.Collectors;

public class ConflictCommands {
@Command
public String info(ConflictManager manager, Conflict conflict, boolean showParticipants) {
StringBuilder response = new StringBuilder();

response.append("**__" + conflict.getName() + " - `#" + conflict.getId() + "` - " + conflict.getCategory().name() + "__**\n");
response.append("wiki: `" + conflict.getWiki() + "`\n");
response.append("Start: " + DiscordUtil.timestamp(TimeUtil.getTimeFromTurn(conflict.getStartTurn()), null) + "\n");
response.append("End: " + (conflict.getEndTurn() == Long.MAX_VALUE ? "Ongoing" : DiscordUtil.timestamp(TimeUtil.getTimeFromTurn(conflict.getEndTurn()), null)) + "\n");
response.append("Casus Belli: `" + conflict.getCasusBelli() + "`\n");
response.append("Status: `" + conflict.getStatusDesc() + "`\n");

CoalitionSide col1 = conflict.getSide(true);
CoalitionSide col2 = conflict.getSide(false);
List<CoalitionSide> sides = Arrays.asList(col1, col2);
if (showParticipants) {
for (CoalitionSide side : sides) {
response.append("\n**" + col1.getName() + "**\n");
for (int aaId : side.getAllianceIdsSorted()) {
long start = conflict.getStartTurn(aaId);
long end = conflict.getEndTurn(aaId);
String aaName = manager.getAllianceName(aaId);
response.append("- " + MarkupUtil.markdownUrl(aaName, PW.getAllianceUrl(aaId)) + " | ");
if (start == conflict.getStartTurn()) {
response.append("Initial");
} else {
response.append(DiscordUtil.timestamp(TimeUtil.getTimeFromTurn(start), null));
}
response.append(" -> ");
if (end >= conflict.getEndTurn()) {
response.append("Present");
} else {
response.append(DiscordUtil.timestamp(TimeUtil.getTimeFromTurn(end), null));
}
response.append("\n");
}

}

} else {
for (CoalitionSide side : sides) {
response.append(side.getName() + ": `" + StringMan.join(side.getAllianceIdsSorted(), ",") + "`\n");
}
response.append("Use `showParticipants: True` to list participants");
}

return response.toString();
}

@Command
@RolePermission(value = Roles.ADMIN, root = true)
public String syncConflictData(ConflictManager manager, @Default Set<Conflict> conflicts, @Switch("g") boolean includeGraphs, @Switch("w") boolean reloadWars) {
Expand Down
43 changes: 4 additions & 39 deletions src/main/java/link/locutus/wiki/WikiGenHandler.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,7 @@
package link.locutus.wiki;

import com.google.gson.JsonObject;
import link.locutus.wiki.pages.WikiAiTools;
import link.locutus.wiki.pages.WikiArgumentsPage;
import link.locutus.wiki.pages.WikiBankPage;
import link.locutus.wiki.pages.WikiBeigeCyclingPage;
import link.locutus.wiki.pages.WikiBlitzPage;
import link.locutus.wiki.pages.WikiBlockadePage;
import link.locutus.wiki.pages.WikiCoalitionsPage;
import link.locutus.wiki.pages.WikiCustomEmbeds;
import link.locutus.wiki.pages.WikiCustomSheetsPage;
import link.locutus.wiki.pages.WikiDelegateServers;
import link.locutus.wiki.pages.WikiDepositsPage;
import link.locutus.wiki.pages.WikiEscrowPage;
import link.locutus.wiki.pages.WikiFindingTargetsPage;
import link.locutus.wiki.pages.WikiGrantTemplate;
import link.locutus.wiki.pages.WikiInterviewPage;
import link.locutus.wiki.pages.WikiPlaceholderPage;
import link.locutus.wiki.pages.WikiSetupPage;
import link.locutus.wiki.pages.WikiStatisticsPage;
import link.locutus.wiki.pages.WikiTaxBracketPage;
import link.locutus.wiki.pages.WikiTradePage;
import link.locutus.wiki.pages.WikiWarAlertsPage;
import link.locutus.wiki.pages.WikiWarRoomPage;
import link.locutus.wiki.pages.WikiAntiLeakPage;
import link.locutus.wiki.pages.WikiAuditingPage;
import link.locutus.wiki.pages.WikiAutoMaskingPage;
import link.locutus.wiki.pages.WikiBankFlows;
import link.locutus.wiki.pages.WikiCommandsPage;
import link.locutus.wiki.pages.WikiCounteringPage;
import link.locutus.wiki.pages.WikiDNRPage;
import link.locutus.wiki.pages.WikiEmbassyPage;
import link.locutus.wiki.pages.WikiHelpPage;
import link.locutus.wiki.pages.WikiHostingLocutus;
import link.locutus.wiki.pages.WikiLoanPage;
import link.locutus.wiki.pages.WikiPermsPage;
import link.locutus.wiki.pages.WikiRecruitmentPage;
import link.locutus.wiki.pages.WikiReportPage;
import link.locutus.wiki.pages.WikiSelfRoles;
import link.locutus.wiki.pages.WikiSendTargetsPage;
import link.locutus.wiki.pages.WikiSpyWarPage;
import link.locutus.wiki.pages.*;
import link.locutus.discord.Locutus;
import link.locutus.discord.commands.manager.v2.impl.pw.CommandManager2;
import link.locutus.discord.commands.manager.v2.impl.pw.filter.PlaceholdersMap;
Expand Down Expand Up @@ -181,6 +143,9 @@ public void writeDefaults() throws IOException {
for (BotWikiGen page : allPages) {
writePage(page);
}

// Unlisted
writePage(new WikiConflictsPage(manager));
}

private void writePage(BotWikiGen page) throws IOException {
Expand Down
62 changes: 62 additions & 0 deletions src/main/java/link/locutus/wiki/pages/WikiConflictsPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package link.locutus.wiki.pages;

import link.locutus.wiki.BotWikiGen;
import link.locutus.discord.commands.manager.v2.impl.pw.refs.CM;
import link.locutus.discord.commands.manager.v2.impl.pw.CommandManager2;
import link.locutus.discord.db.entities.Coalition;
import link.locutus.discord.db.guild.GuildKey;
import link.locutus.discord.user.Roles;
import link.locutus.discord.util.MarkupUtil;

public class WikiConflictsPage extends BotWikiGen {
public WikiConflictsPage(CommandManager2 manager) {
super(manager, "conflict_webpage");
}

@Override
public String generateMarkdown() {
return build(
"""
Live at: <https://wars.locutus.link/>
Browse featured Alliance Vs Alliance conflicts and statistics
For fine grained war stats, please use other bot commands
""",
"# Listing conflicts",
commandMarkdownSpoiler(CM.conflict.list.cmd),
"# Viewing conflict attributes on discord",
"TODO",
"# Site Administration",
"!! ONLY AVAILABLE TO SITE MODERATORS !!",
"Note: Conflicts created within the bot are NOT automatically pushed to the site, see below for instructions",
"## Importing conflicts",
"TODO: Instructions for wiki/ctowned importing",
commandMarkdownSpoiler(CM.conflict.clone.cmd),
"## Manually Creating/Deleting a conflict",
"TODO: Instructions for manually creating/deleting a conflict",
commandMarkdownSpoiler(CM.conflict.create.cmd),
commandMarkdownSpoiler(CM.conflict.delete.cmd),
"## Configuring a conflict",
"### Start/End date",
commandMarkdownSpoiler(CM.conflict.start.cmd),
commandMarkdownSpoiler(CM.conflict.end.cmd),
"### Participants",
"TODO participant START/END",
commandMarkdownSpoiler(CM.conflict.alliance.add.cmd),
commandMarkdownSpoiler(CM.conflict.alliance.remove.cmd),
"### Attributes",
commandMarkdownSpoiler(CM.conflict.rename.cmd),
"TODO: Wiki link",
"## Pushing stats to webpage",
"This does NOT create any new conflicts within the bot, only updating the site with the conflicts that already exist",
"Note: To recalculate conflict stats before updating the site, set `reloadWars: True`",
"If `includeGraphs` is false, the graph pages will not be updated",
"### Updating ALL conflicts",
CM.conflict.sync.cmd.create("*", "true", null).toString(),
"### Updating a specific conflict",
"The conflict ID is in the conflict URL",
CM.conflict.sync.cmd.create("1234", "true", null).toString()
);
}
}

0 comments on commit 3cd4c45

Please sign in to comment.