That is exactly what I wrote.
It’s not practical to do this.
you have 1000 messages in the file. load and add one message and write the file
The time taken do do this operation is longer now
eventually you’ll end up corrupting the file or dropping messages from the file due to no locking of the file.
You won’t be able to load the file and add messages to it when trying to do this twice. Since the previous write function is still writing you file.
Even more so if this file gets to 10,000 messages and so on. you’ll end up with file corruption or missing messages.
The File somehow gets to 1GB in size.
Ok now you need to laod that 1GB file into memory, oh wait, a second message has arrived to be added to the file, now I’m loading the file Twice.
And then your bot crashes as it’s opening the file 50 times and the same time and writing it at least one, and now your whole file is corrupt.
Sure you could add some logic to load once, write x number of lines, hold the array in memory and write a copy of the array to the file.
But then you are holding 1GB of chat in memory for no reason.
This is not a very good way to do this.
Then parse the IRC message and extract only the messages you are interested in, for IRC this is most likely any message that uses the IRC COMMAND of PRIVMSG