diff options
| author | Pinapelz <yukais@pinapelz.com> | 2024-01-27 13:06:50 -0800 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2024-01-27 13:06:50 -0800 |
| commit | 56f6fda144654743356dbb7d4e701d0388fe5e2f (patch) | |
| tree | bb655c5355b923c08537c064f8b716403df48dc3 /src/main | |
| parent | 269aecc66773265e47c526ebbdd29770cf1aa292 (diff) | |
fix: change purge channel to occur before updating schedule
- allows for multiple entires to be used on the same row
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/java/Main.java | 12 | ||||
| -rw-r--r-- | src/main/java/fileutils/FileDataProcessor.java | 19 |
2 files changed, 26 insertions, 5 deletions
diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 2913ff8..2342c75 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -29,8 +29,8 @@ public class Main extends ListenerAdapter{ public void initializeBot(){ fileDataProcessor = new FileDataProcessor(); adminRoleId = Long.parseLong(fileDataProcessor.getField("adminRole")); - commandManager = new CommandManager(fileDataProcessor.getField("holodexAPIKey"), adminRoleId); - jdaBuilder = JDABuilder.createDefault(fileDataProcessor.getField("discordToken")); + commandManager = new CommandManager(fileDataProcessor.getField("HOLODEXAPIKEY"), adminRoleId); + jdaBuilder = JDABuilder.createDefault(fileDataProcessor.getField("DISCORDTOKEN")); jdaBuilder.addEventListeners(commandManager); jdaBuilder.addEventListeners(this); try { @@ -49,14 +49,18 @@ public class Main extends ListenerAdapter{ try { System.out.println("Refreshing upcoming channels"); List<OrgChannelTuple> refreshChannels = fileDataProcessor.getRefreshChannels(); + List<Long> usedChannels = fileDataProcessor.getUsedChannels(); + for (Long channelId : usedChannels) { + System.out.println("Purging channel " + channelId); + jda.getTextChannelById(channelId).purgeMessages( + jda.getTextChannelById(channelId).getIterableHistory().complete()); + } if (refreshChannels.size() == 0) { System.out.println("No channels to refresh"); return; } for (OrgChannelTuple orgChannelTuple : refreshChannels) { System.out.println("Refreshing " + orgChannelTuple.getType() + " " + orgChannelTuple.getName()); - jda.getTextChannelById(orgChannelTuple.getDiscordChannelId()).purgeMessages( - jda.getTextChannelById(orgChannelTuple.getDiscordChannelId()).getIterableHistory().complete()); List<MessageEmbed> messageEmbeds = commandManager.updateUpcomingChannel(orgChannelTuple.getName(), orgChannelTuple.getType()); if (messageEmbeds.size() == 0) { continue; diff --git a/src/main/java/fileutils/FileDataProcessor.java b/src/main/java/fileutils/FileDataProcessor.java index ac260f0..34c1ce0 100644 --- a/src/main/java/fileutils/FileDataProcessor.java +++ b/src/main/java/fileutils/FileDataProcessor.java @@ -32,7 +32,6 @@ public class FileDataProcessor { System.out.println("An error occurred while reading the credential file"); } return ""; - } public List<OrgChannelTuple> getRefreshChannels(){ @@ -55,4 +54,22 @@ public class FileDataProcessor { return orgChannelTuples; } + public List<Long> getUsedChannels(){ + List<Long> usedChannels = new ArrayList<>(); + try{ + File channelFile = new File("settings//upcomingChannels.txt"); + if(channelFile.createNewFile()){ + System.out.println("upcomingChannels.txt created. Please fill it out with the organizations you want to track (refer to README)"); + } + for (String line : Files.readAllLines(Paths.get("settings//upcomingChannels.txt"))) { + String discChannelIdStr = line.split(":")[2]; + long discChannel = Long.parseLong(discChannelIdStr); + usedChannels.add(discChannel); + } + } catch (IOException e) { + System.out.println("Unable to create upcomingChannels.txt file for updating Discord Channels"); + } + return usedChannels; + } + } |
