mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jul 2013
Posts: 24
E
Ameglian cow
OP Offline
Ameglian cow
E
Joined: Jul 2013
Posts: 24
Hi..I'm trying to learn scripting and I know a lot is trial and error, so..this is my little script that bans through either X or a channel mode ban..depending on if X is op'd in the channel. However..I know there should be a halt in there somewhere to stop the script if X is present and op'd but I can't seem to figure out where to put it. The script itself does work..but for some reason (perhaps lag between giving the command and X receiving it) it bans via the channel mode first and then if X is present, the X ban kicks in and replaces the channel mode ban almost immediately. Anyway..this is my working, yet very crude attempt..

on *:JOIN:#<channel>: {
if *sample.host* iswm $address {
/msg x ban $chan $nick 2400 100 Not Welcome here! | /ban $chan $nick | /kick $chan $nick Not Welcome Here!
}
}

I should mention that it's not necessary to check if X is op'd, mainly because if it isn't, the channel mode kicks in anyway. But where would I put the halt to stop the script if it does ban through X first?

Last edited by EasyObserver; 28/12/14 06:53 AM.
Joined: Aug 2013
Posts: 81
I
Babel fish
Offline
Babel fish
I
Joined: Aug 2013
Posts: 81
I think you're thinking about this the wrong way. Indeed, you should be checking whether X is opped or not (which can be done with the isop operator), and make use of if/else statements to determine whether to ban one way or the other, rather than trying either to halt after X bans, or letting X fail to ban and having the /ban command kick in instead:

Code:
on !@*:JOIN:#<channel>:{
  if (*sample.host* iswm $address) {
    if (X isop #) msg X ban # $nick 2400 100 Not Welcome Here!
    else { 
      ban # $nick
      kick # $nick Not Welcome Here!
    }
  }
}


Added @ prefix.

Last edited by Iire; 29/12/14 02:03 AM.
Joined: Jul 2013
Posts: 24
E
Ameglian cow
OP Offline
Ameglian cow
E
Joined: Jul 2013
Posts: 24
Hi and thanks very much lire, much appreciated. Could you tell me please what the significance of the ! symbol is in the first line? I had tried using elseif but I guess I got that all screwed up because I couldn't get it to work. What is the difference between else and elseif? Also...if the script were to be run in all channels I have ops in, I realize I would just not add a channel name, however, would I still use just the # symbol in the script or $chan, or do they both basically represent the same thing? This script will be used for several bans (condensing several small ban scripts) so each ban would be in () and seperated by || . Is there a limit to how many bans a script like this can handle comfortably? Thanks again for your fix, I appreciate it. I hope I'm not asking too many questions, but like I said in my original message, I'm trying to learn.

Joined: Mar 2014
Posts: 215
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Mar 2014
Posts: 215
Originally Posted By: EasyObserver
Hi and thanks very much lire, much appreciated. Could you tell me please what the significance of the ! symbol is in the first line? I had tried using elseif but I guess I got that all screwed up because I couldn't get it to work. What is the difference between else and elseif? Also...if the script were to be run in all channels I have ops in, I realize I would just not add a channel name, however, would I still use just the # symbol in the script or $chan, or do they both basically represent the same thing? This script will be used for several bans (condensing several small ban scripts) so each ban would be in () and seperated by || . Is there a limit to how many bans a script like this can handle comfortably? Thanks again for your fix, I appreciate it. I hope I'm not asking too many questions, but like I said in my original message, I'm trying to learn.

the ! symbol indicates opposite, or other. in this case, the first event parameter is for the nickname. * means any username, @ means OP, and ! means the opposite. !@* means any username that is not op.
note: usually you are never op when you join a channel, X (or the network bot) ops a privileged user when they join. but whatever floats your boat

elseif is just like an if statement, you need something to check for it to be an elseif. an else is for doing (code) if nothing else in the bracket is triggered. ex.
Code:
if ($read(me.txt,2name)) { halt }
elseif ($read(me.txt,name2)) { stuff | halt } 
else { stuff1 }
if this finds 2name in me.txt, it does the first if statement and does not proceed with the elseif and else statements. if it finds name2 in the file but not 2name, it does the elseif statement and ignores the else statement. if both return false/not triggered, it does the else statement.

You can add pretty much as many banned addresses to if statements since mIRC only uses about 20 MB of ram (based off my task manager window with 20 channels open, 7 active channels handling a whole bunch of messaged and joins/parts.) so adding more statements shouldn't be a problem. I do see an easier way, though, instead of going through copying and pasting the if statement with different hosts. Try having a text file, let's say bannedhosts.txt. You would have your if statement structured like
Code:
  if ($address iswm $read(bannedhosts.txt)) {
(iswm could be substituted with isin) and your file would look like
Code:
address1
address2
address3
etc. If you don't want to have to edit the file, you could just /write bannedhosts.txt (newaddress) so it automatically keeps the format for you.

please tell me if i'm wrong on any of this. i'm a bit rusty

Last edited by judge2020; 29/12/14 03:16 AM. Reason: edited, you're not going crazy seeing this change

#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball
Joined: Aug 2013
Posts: 81
I
Babel fish
Offline
Babel fish
I
Joined: Aug 2013
Posts: 81
Originally Posted By: EasyObserver
Could you tell me please what the significance of the ! symbol is in the first line?

! does usually negate whatever follows, but in this case, the ! prefix prevents the script from running if you(r bot) (whoever has the script) are the one who causes it to trigger... so that on the off chance that you(r bot) somehow has a blacklisted address, it won't try to ban itself.

Originally Posted By: EasyObserver
I had tried using elseif but I guess I got that all screwed up because I couldn't get it to work. What is the difference between else and elseif?

The primary difference between elseif and else is that elseif requires some sort of condition to work. Else statements can be used to mark the last resort of a "conditional ladder", let's call it, and essentially means "if none of the other conditions above in this conditional ladder were true, and there are no other possible conditions to check, then do this". The reason I used else rather than elseif in the code above is because when the first condition (if (X isop #)) fails, then there are no more conditions that need to be checked, but you still want the script to perform an action, so as a "last resort", it performs a /ban and /kick.


Originally Posted By: EasyObserver
however, would I still use just the # symbol in the script or $chan, or do they both basically represent the same thing?

Yes, # is just a shorthand for $chan (but not $chan(), which takes arguments... but that's not important right now)

Originally Posted By: EasyObserver
This script will be used for several bans (condensing several small ban scripts) so each ban would be in () and seperated by || . Is there a limit to how many bans a script like this can handle comfortably?

I don't think there is necessarily a limit for the scripting engine, however, like judge2020 mentions, this, for you, can quickly become a terrible way to manage the address blacklist. Instead, you should store the addresses separately in some kind of database/list (such as a text file, but the users list could also work well), and check against that [database/list] within the script... For example:

... I will provide an example script here soon but first I need to figure out why something (related to the users list) isn't working ...

(Btw, I've added the @ prefix to my previous example script, which allows the script to run only if you(r bot) is opped in the channel it triggers in...)

Joined: Jul 2013
Posts: 24
E
Ameglian cow
OP Offline
Ameglian cow
E
Joined: Jul 2013
Posts: 24
Hi judge2020, I do like the idea of having the script read a list, however, when I add this line...

if ($address isin $read(bannedhosts.txt)) {

the script does not seem to read or react to it. I did create a txt file using the same name, and I did write a couple addresses to it so that I could trial it, but to no avail.


Last edited by EasyObserver; 29/12/14 04:20 AM.
Joined: Jul 2013
Posts: 24
E
Ameglian cow
OP Offline
Ameglian cow
E
Joined: Jul 2013
Posts: 24
hi lire..thanks again.
The script you provided works fine for me. I just have to add each address seperately, which is no problem really, I wasn't expecting anything fancy, just wanted to know how things worked, but I do appreciate the time and effort you're putting into it. Thanks very much


Link Copied to Clipboard