How do I make my script work only for some people

From Scriptwiki
Jump to: navigation, search

There are various occasions where a given script should only be usable by some specific people. Examples for this are triggers, which are used to give voice or op to users.

Here is a very basic example for such a script, which doesn't check whether the user, who triggered the event has ops:

on @*:text:!op &:#:{
  mode $chan +o $2
}

(The @-prefix requires the bot to have channel-operator status on the channel in order for this event to get triggered at all)

Using such a script is a bad idea, because it allows anyone to gain channel-operator rights. Using the help-file (/help if then else) we can find this handy operator:

isop - nickname v1 is an op on channel v2

The syntax for an if-construct, which uses this operator, is like this:

if (nick isop #channel) { echo -a nick is an op on #channel }

Lets try to add this to our first example. We cannot specify the actual nick and channel, instead of that, we have to use $nick (which stands for the nick, who triggered the event) and $chan (this is the channel where the !op-command was used):

on *:text:!op &:#:{
  ; does $nick have +o on $chan?
  if ($nick isop $chan) {
    ; op $2 on $chan
    mode $chan +o $2
  }
}

Here's an example of how it works:

[22:26:55] <evil> !op evil
[22:26:58] * Joins: good (good@charybdis.prco23.org)
[22:27:25] <@shroud> !op good
[22:27:25] * chaos sets mode: +o good

As you can see, the bot (chaos) did not react to evil's !op-request, because 'evil' didn't have ops himself. However shroud was able to use the command, because the bot noticed that he had ops on that channel.

Three other operators are also available, which can be used to check a user's permissions on a channel:

ishop - checks whether a user is a half-op (note that the +h (half-op) channel-mode is not available on QuakeNet)
isvoice - checks whether a user is a voiced user
isreg - checks whether a user is a regular user (that means that he has no special permission on the channel)

The syntax for those operators is just the same like for 'isop'.

You can also negate these operators to check whether someone doesn't have a specific right on the channel. Here is an example for this:

if ($nick !isop $chan) { echo -a $nick is not a channel-operator }

This is especially useful for some anti-spam-scripts:

on @*:text:*#*:#:{
  ; if $nick is not an op in $chan...
  if ($nick !isop $chan) {
    ; ..kick him for spamming
    kick $chan $nick Do not spam in $chan
  }
}

In this example, anyone who mentions a channel in a sentence while not having chanops would get kicked by the bot.

The next part of the tutorial will deal with mIRC's user list. Using the user list you can assign special rights to users, which are independent of their actual status on the channel. For example this might be used for giving specific users access to some commands, which should only be available to them.

There are two ways of adding a user to your user list. The first one involves using a numeric level (e.g. 20), while the second one can be used to add users with a named level (e.g. 'operator').

Each of the items in your userlist will look like this:

level:hostmask

The level describes what kind of access this user has, while the hostmask defines who has access to that level.

In order to add someone to your userlist, you should first whois him/her:

good is good@charybdis.prco23.org * the eye of the beholder
good on #help.script
good using *.quakenet.org QuakeNet IRC Server
good End of /WHOIS list.

You will then have to pick a reasonable hostmask for your userlist. This tutorial assumes that you are already familiar with hostmasks. If you're not familiar with them, you should first read some basic tutorial first.

In my case the mask *!*good@charybdis.prco23.org would be appropriate. We're going to write an event, which requires the user to have at least level 20 in order to be able to use it, so we add this to our userlist:

20:*!*good@charybdis.prco23.org

(You can also specify an optional comment after the hostmask, which might be useful for a ban-script. Read more about that in /help user list)

Now let's write the event. Instead of using '*' in the event, which matches any user, we use the more specific level '20':

on @20:text:!opme:#:{ mode $chan +o $nick }

Anyone who has the level 20 can now gain ops by using the !opme command:

[22:57:36] <evil> !opme
[22:57:41] <good> !opme
[22:57:41] * chaos sets mode: +o good

Once again 'evil' was not able to get ops, because he didnt't have the required userlevel to use the !opme command.

Instead of '20' you can also use 'operator' or any other named uservevel in the examples.

Using the /guser and /ruser commands you can add and remove users in a script.

/help /guser tells us that the syntax for /guser is like this: /guser <levels> <nick> [type]

One thing we haven't encountered so far is the [type] parameter. It specifies which mask should be used to add a user to your user list. A list of these types can be found at /help $mask:

0: *!user@host
1: *!*user@host
2: *!*@host
3: *!*user@*.host
4: *!*@*.host
5: nick!user@host
6: nick!*user@host
7: nick!*@host
8: nick!*user@*.host
9: nick!*@*.host

For example '/guser 20 good 3' would add 'good' to your userlist with level 20. The type 4 tells /guser to use the host *!*good@*.prco23.org .

When you want to remove a user from your userlist, you will either have to remove him/her manually via the Users tab in the script editor or you can use /ruser.

Once again, lets have a look at /help /ruser first:

/ruser [levels] <nick | address> [type]

[levels] specifies which levels should be removed the user. You can specify multiple levels by separating them with commas, e.g. test,operator,funcmds. <nick | address> should be replaced either with the user's nickname or his/her address. [type] is similiar to the type used in /guser.

Note that you will have to use the same address and/or type you used for adding the user, when you try to remove him.

Lets assume that your userlist contains just this user:

20:*!*good@charybdis.prco23.org

We could remove this user using the following command:

/ruser 20 *!*good@charybdis.prco23.org

However we cannot use this command, because the hostmask is obviously different:

/ruser 20 *!*@*.prco23.org

If 'good' is still online, we can also specify the nickname instead of the address:

/ruser 20 good 1

This concludes the tutorial. In addition to reading this tutorial and trying the examples you should also read the following topics in the help-files:

/help user list
/help /guser
/help /ruser
/help if then else
Contributed by BlackShroud