mirc

How do I get a list of users connected in chat in an mIRC Remote script


I feel like this has got to be obvious, but I've been searching and just can't find the answer.

I'm programming a 'bot' which connects to my twitch channel's chat. I'd like to track the number of consecutive streams watched by users. I have a command that I type at the start of each stream to signify that a new stream has started, and so, users who join should have their number of consecutive watched streams increased.

I currently use the JOIN event to increase the users consecutive streams count, but if someone is sitting in chat before the start of the stream, they don't get credit because the JOIN event happened before the flag that a new stream has started has been set.

Is there any way to get a list of the current $nick's in the chat? If so, I could hook that into the command when I start the stream and update the users who are already in chat.


Solution

  • You can use $nick(#,N) to retrieve the number of users in a channel, where # is the name of your channel and N is a number.

    You should first use $nick(#mychannel,0) to get the total amount of users in your channel and then you can loop with that number through the users list also with $nick(#,N).

    For example, you do //echo $nick(#mychannel,0) it will say 10. When you use $nick(#mychannel,1) it will return the first user in the user list.

    Simple code example:

    alias getusers {
      var %users = $nick($1,0), %n = 1
      while (%n <= %users) {
        ; print all users in the channel
        echo -ag $nick($1,%n)
        ; you can put your code here   
    
        inc %n
      }
    }
    

    Type /getusers #channelname in a channel to get a list of all users.

    Tell me if you need more help.