aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/Main.java12
-rw-r--r--src/main/java/fileutils/FileDataProcessor.java19
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;
+ }
+
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage