Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if IRC user is a "voice" or higher [C# irc bot]

Tags:

c#

irc

I have a command that I want to restrict only to certain ranks. I'm using unreal3.2.6 IRC.

I read this: enter image description here

But I still am not sure what I can do to check the users rank.

I want to see if the user is a "Voice" or higher. What could look up a user, and what can I do to check if they are a voice or higher? What are the values for each rank in order for me to check?

I'm only trying to check the current channel, not the whole IRC server.

For example:

When a user tries to execute a command !roll (Rolls a dice) and are not a Voice or higher, nothing would happen.

if (data.Equals("!roll"))
{
    //Check if user contains (@,+,etc?) 
    if(nickname.StartsWith(@..+..etc))
    {
        roll(nickname);
    }
}
like image 231
Kyle Avatar asked Nov 18 '11 20:11

Kyle


2 Answers

Instead of querying the user with a WHOIS command, you need to query the applicable channel with the NAMES command.

From RFC 2812 - Internet Relay Chat: Client Protocol:

3.2.5 Names message

Command: NAMES

Parameters: [ <channel> *( "," <channel> ) [ <target> ] ]

By using the NAMES command, a user can list all nicknames that are visible to him. For more details on what is visible and what is not, see "Internet Relay Chat: Channel Management" [IRC-CHAN]. The <channel> parameter specifies which channel(s) to return information about. There is no error reply for bad channel names.

If no <channel> parameter is given, a list of all channels and their occupants is returned. At the end of this list, a list of users who are visible but either not on any channel or not on a visible channel are listed as being on 'channel' "*".

If the <target> parameter is specified, the request is forwarded to that server which will generate the reply.

Wildcards are allowed in the <target> parameter.

Numerics:

ERR_TOOMANYMATCHES ERR_NOSUCHSERVER
RPL_NAMREPLY RPL_ENDOFNAMES

Examples:

NAMES #twilight_zone,#42 ; Command to list visible users on #twilight_zone and #42

NAMES ; Command to list all visible channels and users

Quering a channel with the NAMES command will yield these two replies:

353 RPL_NAMREPLY

"( "=" / "*" / "@" ) <channel>
:[ "@" / "+" ] <nick> *( " " [ "@" / "+" ] <nick> )

  • "@" is used for secret channels, "*" for private channels, and "=" for others (public channels).

as well as:

366 RPL_ENDOFNAMES

"<channel> :End of NAMES list"

You can split the list of nicks on the whitespace character, and determine whether the first character of a nick is a mode identifier (+, @, etc..) or an alphanumeric character (which implies that the user has no special mode on the channel.)

The IRC standard only defines + as a voiced user and @ as a channel operator, but other servers can be known to use special characters like ~ for channel owner and & for "super" channel operators. As a general rule, you could simply check to see that the user has any channel mode (other than the default) to verify that they're voiced or better.

like image 132
Adam Maras Avatar answered Oct 31 '22 16:10

Adam Maras


Unless you're using an API that is giving you this information, IRC's protocol doesn't give you any usermods in the "ident@vhost" in a 311 reply to WHOIS. IRC bots that I've written in the past, you have to keep track of this kind of stuff yourself. Although when you send a WHOIS <nick> command, the 319 line of the response will have a list of the channels that nick is in, and a @/+/%/~ in front of the channels indicating the user modes that nick has in that channel. You can parse those but it'll increase the amount of traffic if you have to send a WHOIS everytime someone does something in the channel.

When you first join a channel, you'll get a bunch of 353 <your nick> @ <channel> :<user_list> where the <user_list> can be:

:snowcloud Chibi-Ryu CUF Nere ~thundra vatar nm449|laptop Klapo Apocalypse +Skull_Leader %KagaminBot Razaekel Kloacy &Cherry-chan @happytang MagusHrist %Frostii hexerr

You can see the + (voice), % (half-op), @ (op), ~ (owner) modifiers in front of each nick. Additionally, if you issue a WHO <channel> (depending on the server, you may need to be in the channel to get anything back), you get a line by line 352 reply: 352 <your nick> <channel> <user> <host> <server> <nick> <H|G>[*][@|+|%|~] :<hopcount> <real name>. And you can parse out the stuff after the H/G to get the user modes.

Those are the only ways you can query user modes, but while your bot sits in the channel, it will get messages like MODE <channel> +|-<v|h|a|o> <nick>. So when you see one of those, you can internally keep track of who got a +v, or a -v, etc. Then you won't need to send a command to the server everytime someone in the channel does a "!roll" (some IRC servers will kick you for flooding if you keep sending a WHOIS).

like image 39
Jon Lin Avatar answered Oct 31 '22 17:10

Jon Lin