This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

advertising script

Old posts that have not been replied to for several years.
Locked
D
DarkJFMan
Halfop
Posts: 85
Joined: Mon Dec 15, 2003 3:19 pm

advertising script

Post by DarkJFMan »

Code: Select all

bind pub - "#" pub:adv
proc pub:adv {nick uhost hand chan arg} {
global logo botnick
if {[nickisreg $chan]} && {[string match $chan #hooters]} {
set ad. [ [ $nick ] ]
if {ad. [ [ $nick ] ] == 1 } { 
pustserv "NOTICE $nick :Please don't advertise
}
if {ad. [ [ $nick ] ] == 2 } {
putserv "MODE $chan +b *!*@[join [lindex [split [getchanhost $nick] "@"] 1]]"
putkick $chan $nick "Don't advertise in here."
utimer 600 [list putserv "MODE $chan -b *!*@[join [lindex [split [getchanhost $nick] "@"] 1]]"]
}
if {ad. [ [ $nick ] ] == 3 } {
putserv "MODE $chan +b *!*@[join [lindex [split [getchanhost $nick] "@"] 1]]"
putkick $chan $nick "Don't advertise in here."
utimer 1800 [list putserv "MODE $chan -b *!*@[join [lindex [split [getchanhost $nick] "@"] 1]]"]
}
unset ad . [ [ $nick ] ]
}
What this script supposed to do, is if someone is trying to use # which usualy used for chan for advertising, 1) warn in notice 2) ban for 10 min 3) ban for 30 min
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

You answered your own question. Next time read the script description.
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
D
DarkJFMan
Halfop
Posts: 85
Joined: Mon Dec 15, 2003 3:19 pm

Post by DarkJFMan »

i made the script, i just want to know if it's correct, because when i made it, it was in mirc scripting, and i changed it to tcl, i'm just asking is this the way you do it?
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

1. [getchanhost $nick] = $uhost
2. Use arrays, write in to file how many warnings did a user got.
3. instead of lots of if's use switch cos is a lot faster.
4. string match $chan #hooters ? better string equal -nocase $chan "#hooters"
Once the game is over, the king and the pawn go back in the same box.
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

Sorry DarkJFMan, I misread your post. Was fairly distracted at the time.
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
D
DarkJFMan
Halfop
Posts: 85
Joined: Mon Dec 15, 2003 3:19 pm

Post by DarkJFMan »

Code: Select all

bind pub - "#" pub:adv
proc pub:adv {nick uhost hand chan arg} {
global logo botnick
if {[nickisreg $chan]} && {[string equal -nocase $chan "#hooters"]} {
set ad. [ [ $nick ] ]
if {ad. [ [ $nick ] ] == 1 } {
pustserv "NOTICE $nick :Please don't advertise
}
if {ad. [ [ $nick ] ] == 2 } {
putserv "MODE $chan +b *!*@[join [lindex [split [$uhost] "@"] 1]]"
putkick $chan $nick "Don't advertise in here."
utimer 600 [list putserv "MODE $chan -b *!*@[join [lindex [split [$uhost] "@"] 1]]"]
}
if {ad. [ [ $nick ] ] == 3 } {
putserv "MODE $chan +b *!*@[join [lindex [split [$uhost] "@"] 1]]"
putkick $chan $nick "Don't advertise in here."
utimer 1800 [list putserv "MODE $chan -b *!*@[join [lindex [split [$uhost] "@"] 1]]"]
}
unset ad . [ [ $nick ] ]
}
That's what I got from 1 and 4, by using arrays, do you mean create a new file, and make it write in there:
DarkJFMan == 2
someguy == 1 ...
caesar wrote: 2. Use arrays, write in to file how many warnings did a user got.
3. instead of lots of if's use switch cos is a lot faster.
And i have never used switch, can you give me an example plz thank you.
D
DarkJFMan
Halfop
Posts: 85
Joined: Mon Dec 15, 2003 3:19 pm

Post by DarkJFMan »

Code: Select all

bind pub - # pub:adv
proc pub:adv {nick uhost hand chan text} {
global spam
set advnick($uhost) 0
if {[isop $nick $chan] && [isvoice $nick $chan]} {
return 0
}
elseif {[string equal -nocase $chan "#hooters"]} {
inc advnick{$uhost}
}
elseif {$advnick($uhost) == 1} {
putserv "NOTICE $nick :Please don't advertise here
}
elseif {$advnick($uhost} == 2} {
putserv "MODE $chan +b *!*@[join [lindex [split $uhost "@"] 1]]"
putkick $chan $nick "TempBan 10 min for advertising"
utimer 600 [list putserv "MODE $chan -b *!*@[join [lindex [split $uhost "@"] 1 ]]"
}
elseif {$advnick($uhost) == 3} {
putserv "MODE $chan +b *!*@[join [lindex [split $uhost "@"] 1 ]]"
putkick $chan $nick "TempBan 30 min for advertising"
utimer 1800 [list putserv "MODE $chan -b *!*@[join [lindex [split $uhost "@"] 1 ]]"
}
utimer 3600 [list unset $advnick($uhost)]
}
}
Could this work at all?
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Consult the tcl-commands.doc file for the difference betwen pub and pubm.

&& stands for AND and || stand for OR

Use switch cos is a lot faster to check if $advnick($uhost) is equal with 1, 2 or 3.
Once the game is over, the king and the pawn go back in the same box.
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

caesar wrote:Use switch cos is a lot faster to check <snip>
You've been saying this alot lately... for the record, they are pretty much equal performance wise:

Code: Select all

% proc testa {var} {
  if {$var == 0} {
    return $var
  } elseif {$var == 1} {
    return $var
  } elseif {$var == 2} {
    return $var
  } elseif {$var == 3} {
    return $var
  } 
}
% proc testb {var} {
  switch -- $var {
    "0" { return $var }
    "1" { return $var }
    "2" { return $var }
    "3" { return $var }
  }
}
% time {testa 0} 100
7 microseconds per iteration
% time {testb 0} 100
6 microseconds per iteration
% time {testa 1} 100
6 microseconds per iteration
% time {testb 1} 100
5 microseconds per iteration
% time {testa 2} 100
5 microseconds per iteration
% time {testb 2} 100
5 microseconds per iteration
% time {testa 3} 100
3 microseconds per iteration
% time {testb 3} 100
5 microseconds per iteration
The advantage switch holds over if's, is its compactness in typing out a scenario, not performance however.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

To be honest I like switch more that a bunch of if's cos it looks a lot nicer and I don't get confused where an if ends and where another starts. Also, the switch has a lot more *features* that a bunch of if's. I did a lil test on my own with the exact example you gave and here are my results.
% time {testa 0}
11 microseconds per iteration
% time {testb 0}
12 microseconds per iteration
% time {testa 1}
11 microseconds per iteration
% time {testa 1}
11 microseconds per iteration
% time {testa 1}
11 microseconds per iteration
% time {testb 0}
43 microseconds per iteration
% time {testb 0}
13 microseconds per iteration
% time {testb 0}
13 microseconds per iteration
I'll let you be the judge of this. :mrgreen:
Once the game is over, the king and the pawn go back in the same box.
D
DarkJFMan
Halfop
Posts: 85
Joined: Mon Dec 15, 2003 3:19 pm

Post by DarkJFMan »

Code: Select all

# Advertise
bind pubm - # pub:adv
proc pub:adv {nick uhost hand chan text} {
global spam
set advnick($uhost) 0
if {[isop $nick $chan] || [isvoice $nick $chan]} {
return 0
}
elseif {[string equal -nocase $chan "#hooters"]} {
incr advnick{$uhost}
}
elseif {$advnick($uhost) == 1} {
putserv "NOTICE $nick :Please don't advertise here
}
elseif {$advnick($uhost} == 2} {
putserv "MODE $chan +b *!*@[join [lindex [split $uhost "@"] 1]]"
putkick $chan $nick "TempBan 10 min for advertising"
utimer 600 [list putserv "MODE $chan -b *!*@[join [lindex [split $uhost "@"] 1 ]]"
}
elseif {$advnick($uhost) == 3} {
putserv "MODE $chan +b *!*@[join [lindex [split $uhost "@"] 1 ]]"
putkick $chan $nick "TempBan 30 min for advertising"
utimer 1800 [list putserv "MODE $chan -b *!*@[join [lindex [split $uhost "@"] 1 ]]"
}
utimer 3600 [list unset $advnick($uhost)]
}
}
I still have no idea how to make it switch, and can you please check if code is completely correct, i swtiches && with || and make it pubm. so with that should the script work fine?
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

caesar wrote:To be honest I like switch more that a bunch of if's cos it looks a lot nicer and I don't get confused where an if ends and where another starts. Also, the switch has a lot more *features* that a bunch of if's. I did a lil test on my own with the exact example you gave and here are my results.
% time {testa 0}
11 microseconds per iteration
% time {testb 0}
12 microseconds per iteration
% time {testa 1}
11 microseconds per iteration
% time {testa 1}
11 microseconds per iteration
% time {testa 1}
11 microseconds per iteration
% time {testb 0}
43 microseconds per iteration
% time {testb 0}
13 microseconds per iteration
% time {testb 0}
13 microseconds per iteration
I'll let you be the judge of this. :mrgreen:
proc testb was the one with "switch"...
and you have a 43 microseconds result for it... lol ;p

But seriously, what happened there was probably a cpu spike, where the cpu was doing work some where else at the time.

And as for switch having more features... not true.....
For example, say if you wanted to check against what $var1 was AND what $var2 was..... you could have a bunch of nested switches which would be really ugly and inefficient, or you could use the && expression within if statements, which is alot neater and proper.

Don't get me wrong, switch has it's uses, I use it.. but you have to know when it's really more convenient to do so.. This specific example may be one of those times even.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Indeed.. :oops: switch kinda suck :D

Well, yes, if you want to get just a result for 1, 2, 3 or default (nothing) then switch is good, else a bunch of if's if there are a lot of checks.
Once the game is over, the king and the pawn go back in the same box.
D
DarkJFMan
Halfop
Posts: 85
Joined: Mon Dec 15, 2003 3:19 pm

Post by DarkJFMan »

Code: Select all

 bind pubm - "*#*" pub:adv  
proc pub:adv {nick uhost hand chan arg} {  
  global logo botnick ad  
  if {![isop $nick $chan] && ![isvoice $nick $chan] && ![validuser $hand] && ([string tolower $chan] == "#hooters")} {  
    if {![info exists ad($uhost)]} {  
      set ad($uhost) 1  
    } else {  
      incr ad($uhost)  
    }  
    if {$ad($uhost) == 1} {  
      putserv "NOTICE $nick :Please don't advertise"  
    } elseif {$ad($uhost) == 2} {  
      putserv "MODE $chan +b *!*@[set bh [lindex [split $uhost @] 1]]"  
      putserv "KICK $chan $nick :Don't advertise in here."  
      utimer 600 [list putserv "MODE $chan -b *!*@$bh"]  
    } elseif {$ad($uhost) == 3} {  
      putserv "MODE $chan +b *!*@[set bh [lindex [split $uhost @] 1]]"  
      putserv "KICK $chan $nick :Don't advertise in here."  
      utimer 1800 [list putserv "MODE $chan -b *!*@$bh"]  
    }  
    utimer 3600 [list unset ad($uhost)]  
  }  
}
[01:13:15am] <DarkJFGirl> [04:15] wrong # args: should be "proc name args body"
any ideas?
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

Post by arcane »

caesar wrote:...I don't get confused where an if ends and where another starts.
well, this is no matter of if or switch - this is a matter of how you format your code :P
aVote page back online!
Check out the most popular voting script for eggdrop bots.

Join the metal tavern!
Locked