aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/fileutils/UpcomingChannelsManager.java
blob: 4050dc2350d9c5f54603efc23d8e670da32c84ff (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
package fileutils;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

public class UpcomingChannelsManager {
    final String CONFIG_FILE_PATH = "settings//upcomingChannels.txt";
    public void addNewEntry(String type, String information, String discordChannelID){
        File f = new File(CONFIG_FILE_PATH);
        try {
            System.out.printf("Written data to upcomingChannels.txt");
            FileWriter fw = new FileWriter(f, true);
            fw.write(type + ":" + information + ":" + discordChannelID+"\n");
            fw.close();
        }
        catch(IOException e){
            System.out.println("Unable to open upcomingChannels.txt for writing");
        }
    }

    public void removeEntry(String term, long discordChannelID){
        // remove the line containing the term
        File f  = new File(CONFIG_FILE_PATH);
        try{
            List<String> lines = Files.readAllLines(Paths.get(CONFIG_FILE_PATH));
            FileWriter fw = new FileWriter(f, false);
            for(String line : lines){
                System.out.println(line);
                if(line.contains(term) && line.contains(Long.toString(discordChannelID))){
                    continue;
                }
                fw.write(line+"\n");
            }
            fw.close();
        }
        catch(IOException e){
            System.out.println("Unable to open upcomingChannels.txt for writing");
        }
        catch (ArrayIndexOutOfBoundsException e){
            System.out.println("Out of bounds Exception, is the upcomingChannels.txt formatted correctly?");
        }

    }
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage