Skip to content

Commit

Permalink
Add missing check to channel sort
Browse files Browse the repository at this point in the history
  • Loading branch information
xdnw committed Jul 22, 2024
1 parent 5c9593d commit 3663a33
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@
import java.util.stream.Collectors;

public class IACommands {
@Command(desc = "Rename channels in a category to match the nation registered to the user added")
@Command(desc = "Rename channels and set their topic (if empty) in a category to match the nation registered to the user added")
@RolePermission(Roles.INTERNAL_AFFAIRS_STAFF)
public String renameInterviewChannels(@Me GuildDB db, @Me Guild guild, @Me User author, @Me DBNation me, @Me IMessageIO io, @Me JSONObject command,
Set<Category> categories,
@Switch("m") boolean allow_non_members,
@Switch("v") boolean allow_vm,
@Switch("n") Set<DBNation> list_missing,
@Switch("f") boolean force) {
for (Category category : categories) {
if (!category.getGuild().equals(guild)) throw new IllegalArgumentException("Category " + category.getName() + " is not in this guild");
Expand Down Expand Up @@ -127,6 +128,10 @@ public String renameInterviewChannels(@Me GuildDB db, @Me Guild guild, @Me User
} else if (!allow_vm && nation.getVm_turns() > 0) {
warnings.put(channel, "Nation is a VM: " + nation.getMarkdownUrl() + " (ignore with `allow_vm: True`");
}
if (channel.getTopic().isEmpty()) {
String newTopic = nation.getUrl();
RateLimitUtil.queue(channel.getManager().setTopic(newTopic));
}
String newName = nation.getName() + "-" + nation.getId();
if (channel.getName().replace(" ", "-").equalsIgnoreCase(newName.replace(" ", "-"))) continue;
changes.add(channel.getAsMention() + ": " + channel.getName() + " -> " + nation.getName() + "-" + nation.getId());
Expand Down Expand Up @@ -169,6 +174,24 @@ public String renameInterviewChannels(@Me GuildDB db, @Me Guild guild, @Me User
msg.file("warnings.txt", warningsStr.toString());
}

if (list_missing != null) {
Set<DBNation> missing = new LinkedHashSet<>();
for (DBNation nation : list_missing) {
if (!nationChannels.containsKey(nation)) {
missing.add(nation);
}
}
if (!missing.isEmpty()) {
List<String> missingRows = new ArrayList<>();
missingRows.add("nation_id\tnation_name\tdiscord\turl");
for (DBNation nation : missing) {
String userName = nation.getUserDiscriminator();
missingRows.add(nation.getId() + "\t" + nation.getName() + "\t" + userName + "\t" + nation.getUrl());
}
msg.file("missing.txt", StringMan.join(missingRows, "\n"));
}
}

if (changes.isEmpty()) {
append.append("No changes to be made");
msg.append(append.toString()).send();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ public void createTables() {
}

public void deleteTemplate(AGrantTemplate template) {
// remove from map
templates.remove(template.getName());

String table = template.getType().getTable();
Expand Down

0 comments on commit 3663a33

Please sign in to comment.