mIRC Homepage

Removing $nick from .txt file

Posted By: zigress

Removing $nick from .txt file - 16/09/15 04:13 PM

I have a list.txt file that records names of users that type !join in twitch chat.
Instead of going to the direct file to remove a specific name, I wanted to find a way to remove a user's name from the list through a command on twitch chat.
This is what I have so far. This only works if there's one person on the list.

on *:text:!remove *:#: {
if ($nick isop #) {
if (!$read(list.txt,nw,$2)) { msg $chan $2- is not in the list. | return }
else { msg $chan /me removed $2 from the list.
write -dl list.txt , $2
}
}
}
Posted By: Nillen

Re: Removing $nick from .txt file - 16/09/15 04:42 PM

That's not how -d works.
For -d to work, you need the -l as well.
For -l to work, you need to specify the number behind it.
-dl5 would remove line 5 from the textfile. To know which line you want to delete, you search for it using $read(list.txt,nw,$2) and use $readn. $readn will return the number of the line that the last $read match was found.

The correct way to use it afterwards is to /write -dl $+ $readn list.txt
Posted By: zigress

Re: Removing $nick from .txt file - 16/09/15 05:36 PM

Here's the updated code. This works, however I have one last question. If I want to include text before the user's name (i.e. A: user), how can I do that?

on *:text:!remove *:#: {
if ($nick isop #) {
if (!$read(list.txt,nw,$2)) { msg $chan $2 is not in the list. | return }
elseif ($read(list.txt,nw,$2)) { msg $chan $2 has been removed from the list.
write -dl $+ $readn list.txt }
}
}
Posted By: Nillen

Re: Removing $nick from .txt file - 16/09/15 06:54 PM

You simply /write it to the file.
I imagine you're using a on text event and writing $2 to the file. Just use $2- instead and write after $2 with it. This would be consistent throughout the file, using the NICK first and then the added text after. Consistency is key when it comes to scripts like that.

You might want to look into changing the delete feature for this though to make sure the first token "if ($gettok($read(file,nw,$2),1,32) == $2)" of the $read line is the match you're looking for.
This may or may not require you to use wildcard indicators though since your lines will have more than just $2 in it.
© 2022 mIRC Discussion Forums