blob: 34c1ce0b2c22c4b275e712315d4861ae5900d6ad (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
package fileutils;
import common.OrgChannelTuple;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
public class FileDataProcessor {
public static String getField(String parameter){
try {
Object obj = new JSONParser().parse(new FileReader("settings//config.json"));
JSONObject jo = (JSONObject) obj;
return (String) jo.get(parameter);
}
catch(FileNotFoundException e){
System.out.println("Credential file could not be found. Please create it at settings//config.json");
}
catch(ParseException ex){
System.out.println("Ensure that your credential file is valid JSON");
}
catch(IOException ex){
System.out.println("An error occurred while reading the credential file");
}
return "";
}
public List<OrgChannelTuple> getRefreshChannels(){
List<OrgChannelTuple> orgChannelTuples = 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 type = line.split(":")[0];
String name = line.split(":")[1];
String channelIdStr = line.split(":")[2];
long channelId = Long.parseLong(channelIdStr);
orgChannelTuples.add(new OrgChannelTuple(type, name, channelId));
}
} catch (IOException e) {
System.out.println("Unable to create upcomingChannels.txt file for updating Discord Channels");
}
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;
}
}
|