scriptingmirc

How to send a random line of text to a user followed by permanent ignore in mIRC


Below is an example of my mirc script that triggers on channel JOIN...

on 1:JOIN:#:/timer 1 10 /msg $nick Welcome | /timer 1 20 If you like the game please vote on the main page | /timer 1 30 Thanks for visiting and enjoy your stay ignore $nick

I want to randomise the replies from a text file stored locally, how exactly do I do this? I am quite new to mIRC and am just learning and have been testing used $rand but failed miserably.

I'd like to have say 10 options for EACH sequential reply. So first message to the user has 10 variations, so does the second and so forth. For the sake of efficiency I would then like to ignore the user permanently once they have had all messages. So any time they next come online and join the channel they will not receive the messages ever again. I guess maybe this would require an .ini to store the users id?


Solution

  • Not entirely sure why you want to have everything on one line, even as that may be from lack of knowledge on the subject. For readability, you can replace the event execution line with brackets:

    on 1:JOIN:#: {
        timer 1 10 msg $nick Welcome 
        timer 1 20 If you like the game please vote on the main page 
        timer 1 30 Thanks for visiting and enjoy your stay
        ignore $nick
    }
    

    Of course, there are still some problems with the above example. /msg isn't used, thus the next timers won't do anything, and /ignore won't prevent the event from triggering. I'll address that in a bit.

    On top of that, you don't ignore the nick because your last line(shown here: /timer 1 30 Thanks for visiting and enjoy your stay ignore $nick) doesn't separate out ignore $nick from the rest of the execution line, thus it simply treats it as part of the sentence. To do that, you'd need to give it another pipe character(shown here: /timer 1 10 /msg $nick Welcome | /timer 1 20 If you like the game please vote on the main page | /timer 1 30 Thanks for visiting and enjoy your stay | ignore $nick, or like the above with my bracket example).

    Now, onto the main question itself; a call to the $read identifier, with just the file name and no extra parameters will cause it to read a random line from that file. So, with that in mind you could do the following:

    on 1:JOIN:#: {
        timer 1 10 msg $nick $read(welcome.txt)
        timer 1 20 msg $nick $read(vote.txt) 
        timer 1 30 msg $nick $read(closing.txt)
        ignore $nick
    }
    

    Note that calls to read any file is local to the mIRC app data folder. Meaning that welcome.txt is expected to exist at $mircdir. If you want to load it from elsewhere, either specify the absolute path, or use $scriptdir $+ filename.extension, and be sure have the script itself exists in a specific directory, such as scripts\script_name\script.mrc.

    To make sure the user never receives the message again, you will need to keep track of users. To do this, we can just use $read again, as when used with certain parameters, if $read doesn't find what we're looking for, it will return $null. Ignoring the user will not prevent the user from triggering the join event.

    $read's s parameter, supplied as the second parameter, searches for a line beginning with the third parameter; if that line exists, it returns the line. Otherwise, it returns $null.

    After that, we simply /write to the file. /write can take a variety of options, but none are relevant as we only need to append a line to the file(the first parameter), which is in this case is $nick(the second parameter).

    on 1:JOIN:#: {
        if ($read(ignored_nicks.txt, s, $nick) == $null) {
            timer 1 10 msg $nick $read(welcome.txt)
            timer 1 20 msg $nick $read(vote.txt) 
            timer 1 30 msg $nick $read(closing.txt)
            write ignored_nicks.txt $nick
        }
    }
    

    Of note, when an event uses the bracket format, we don't need to supply the forward slash(/) for each command. Only when executing a command from mirc's input box do you need the first slash. The pipe(|) doesn't need a slash, though I add it myself out of good practice, to make it obvious its a command(example: /somecommand blah | /someothercommand blah).

    Lastly, if you are going to add more replies, that changes my answer a slight, but as there are only 3, there is no need to complicate it further for the moment.