Skip to content

Commit

Permalink
Add import db file for conflicts plus...
Browse files Browse the repository at this point in the history
add name for post addd to conflict
  • Loading branch information
xdnw committed May 19, 2024
1 parent 53d8d23 commit 8c15689
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ public CommandManager2 registerDefaults() {
getCommands().registerMethod(new ConflictCommands(), List.of("conflict", "sync"), "recalculateGraphs", "recalculate_graphs");
getCommands().registerMethod(new ConflictCommands(), List.of("conflict", "sync"), "recalculateTables", "recalculate_tables");
getCommands().registerMethod(new ConflictCommands(), List.of("conflict", "sync"), "importAllianceNames", "alliance_names");
getCommands().registerMethod(new ConflictCommands(), List.of("conflict", "sync"), "importExternal", "db_file");

getCommands().registerMethod(new ConflictCommands(), List.of("conflict", "alliance"), "removeCoalition", "remove");
getCommands().registerMethod(new ConflictCommands(), List.of("conflict", "alliance"), "addCoalition", "add");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ public String purgeFeatured(ConflictManager manager, @Me IMessageIO io, @Me JSON
@Command(desc = "Purge permenent conflicts that aren't in the database")
@RolePermission(Roles.MILCOM)
@CoalitionPermission(Coalition.MANAGE_CONFLICTS)
public String addAnnouncement(ConflictManager manager, Conflict conflict, String url) throws SQLException, IOException {
public String addAnnouncement(ConflictManager manager, Conflict conflict, String url, @Default String desc) throws SQLException, IOException {
String urlPattern = "https://forum\\.politicsandwar\\.com/index\\.php\\?/topic/[0-9]+-.+/";
if (!url.matches(urlPattern)) {
return "Invalid URL format. Please provide a URL in the format: https://forum.politicsandwar.com/index.php?/topic/{topicId}-{topicUrlStub}/";
Expand All @@ -851,8 +851,8 @@ public String addAnnouncement(ConflictManager manager, Conflict conflict, String
conflict.deleteAnnouncement(topic.topic_id);
msgs.add("Deleted previous announcement for " + topic.topic_name);
}
conflict.addAnnouncement(topic.topic_name, topic, true);
msgs.add("Added announcement for " + topic.topic_name);
conflict.addAnnouncement(desc == null ? topic.topic_name : desc, topic, true);
msgs.add("Added announcement for " + topic.topic_name + "/" + topic.topic_id + " at " + DiscordUtil.timestamp(topic.timestamp, null));
conflict.push(manager, null, false, false);
return StringMan.join(msgs, "\n");
}
Expand Down Expand Up @@ -901,4 +901,17 @@ public String purgeTemporaryConflicts(ConflictManager manager, @Me IMessageIO io
return null;
}
}

@Command(desc = "Import from an external database file")
@RolePermission(value = Roles.ADMIN, root = true)
public String importExternal(ConflictManager manager, String fileLocation, @Me IMessageIO io) throws SQLException {
File file = new File(fileLocation);
if (!file.exists()) throw new IllegalArgumentException("File does not exist");
if (!file.getName().equalsIgnoreCase("war.db")) {
throw new IllegalArgumentException("File must be named `war.db`");
}
CompletableFuture<IMessageBuilder> msgFuture = io.send("Importing from " + file.getName() + "...");
manager.importFromExternal(file);
return "Done!";
}
}
2 changes: 1 addition & 1 deletion src/main/java/link/locutus/discord/db/ForumDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void createTables() {
}

public void addTopic(DBTopic topic) throws SQLException {
String sql = "INSERT INTO `FORUM_TOPICS` (`topic_id`, `section_id`, `topic_name`, `topic_urlname`, `section_name`, `section_urlname`, `timestamp`, `poster_id`, `poster_name`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
String sql = "INSERT OR REPLACE INTO `FORUM_TOPICS` (`topic_id`, `section_id`, `topic_name`, `topic_urlname`, `section_name`, `section_urlname`, `timestamp`, `poster_id`, `poster_name`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
try (PreparedStatement stmt = getConnection().prepareStatement(sql)) {
stmt.setInt(1, topic.topic_id);
stmt.setInt(2, topic.section_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ public synchronized byte[] getPsonGzip(ConflictManager manager) {
root.put("header_group", new ObjectArrayList<>(damageHeader.keySet().stream().map(f -> f.getType().name()).toList()));
root.put("header_type", new ObjectArrayList<>(damageHeader.keySet().stream().map(f -> f.isCount() ? 1 : 0).toList()));
root.put("war_web", warsVsAllianceJson());
root.put("update_ms", System.currentTimeMillis());
byte[] compressed = JteUtil.compress(JteUtil.toBinary(root));
flatStatsGzip = compressed;
return compressed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void createTables() {
db.executeStmt("CREATE TABLE IF NOT EXISTS attack_subtypes (attack_id INT PRIMARY KEY, subtype INT NOT NULL)");
}

public static void importData(Database sourceDb, Database targetDb, String tableName) throws SQLException {
private void importData(Database sourceDb, Database targetDb, String tableName) throws SQLException {
Connection sourceConnection = sourceDb.getConnection();
Connection targetConnection = targetDb.getConnection();

Expand Down

0 comments on commit 8c15689

Please sign in to comment.