Search code examples
javaircchatbot

How to filter a PrintStream


Im trying to code a basic irc chatbot using PircBotX. I want to output the chat to a text file and couldn't find a way to do so. I am coding my own and can output the console to a file with lines that look something like this:

13:12:09.110 [botPool0-bot0] INFO org.pircbotx.InputParser - :jdbener!jdbener@jdbener.tmi.twitch.tv PRIVMSG #irish_00 :yay

I would like it to write it to the file like this:

13:12 < Twitch> Jdbener: yay

Here is the code i have for the writer file:

public class writer extends OutputStream {
public void write(int b) throws IOException {
     String Output = String.valueOf((char)b);
     FileWriter writer = new FileWriter("output-dirty.txt", true);
     writer.append(Output);
     writer.close();
     testbot.stringB.append(Output);
 }
 }

If you need anything else let me know and I thank you in advance for your help!


Solution

  • If the questions is how to make this :

    13:12:09.110 [botPool0-bot0] INFO org.pircbotx.InputParser - :jdbener!jdbener@jdbener.tmi.twitch.tv PRIVMSG #irish_00 :yay
    

    look like this:

    13:12 < Twitch> Jdbener: yay
    

    the you can do something like this:

     String a = "13:12:09.110 [botPool0-bot0] INFO org.pircbotx.InputParser - :jdbener!jdbener@jdbener.tmi.twitch.tv PRIVMSG #irish_00 :yay";
    
     String[] b = a.split(":");
    
     String c =   b[0] + ":" + 
                  b[1] + 
                  "<Twitch>" +
                  b[3].split("!")[0].replace(b[3].split("!")[0].charAt(0), Character.toUpperCase(b[3].split("!")[0].charAt(0))) + 
                  ": " +
                  b[b.length - 1];
    

    Testing with System.out.println(c); will output: 13:12<Twitch>Jdbener: yay

    Of course i am assuming there is some consistency with the original String. If the answer doesn't work very well then paste some more example input Strings and will update the answer.