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.

setting ban on msg followed by quit

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
s
simo
Revered One
Posts: 1070
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

tnx crazycat gettin this output:
(@TCL-Tester) : Can't find spamlist for #opers
User avatar
CrazyCat
Revered One
Posts: 1216
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

You can try with the following code:

Code: Select all

bind PUB - * pub:spam
bind CTCP - ACTION ctcp:spam
bind PART - * part:spam
bind SIGN - * sign:spam


array set spamlist {}

proc pub:spam {nick uhost hand chan txt} {
   add:spam $nick [string tolower $chan]
}

proc ctcp:spam {nick uhost hand chan key txt} {
   add:spam $nick [string tolower $chan]
}

proc add:spam {nick chan} {
	if {[info exists ::spamlist($chan)]} {
		putserv "PRIVMSG $chan :spamlist exists for $chan"
		set pos [lsearch -nocase [dict keys [join $::spamlist($chan)]] $nick]
		if {$pos >= 0} {
			putserv "PRIVMSG $chan :$nick was in, removing"
			set ::spamlist($chan) [lreplace $::spamlist($chan) $pos $pos]
		}
	}
	lappend ::spamlist($chan) [list $nick [clock seconds]]
	putserv "PRIVMSG $chan :adding/updating $nick in $chan"
}

proc part:spam {nick uhost hand chan {txt ""}} {
   ban:spam $nick $uhost [string tolower $chan]
}

proc sign:spam {nick uhost hand chan txt} {
   ban:spam $nick $uhost [string tolower $chan]
}

proc ban:spam {nick uhost chan} {
   if {![info exists ::spamlist($chan)]} {
      putserv "PRIVMSG $chan :Can't find spamlist for $chan"
      return
   }
   set pos [lsearch -nocase [dict keys [join $::spamlist($chan)]] $nick]
   if {$pos > -1} {
      scan [lindex $::spamlist($chan) $pos] {%s%s} user time
      set now [clock seconds]
      if {[expr $now - $time] < 6} {
         set ::spamlist($chan) [lreplace $::spamlist($chan) $pos $pos]
         set mask [maskhost "$nick!$uhost" 3]
         pushmode $chan +b $mask
      } else {
         putserv "PRIVMSG $chan :More than 5s, doing nothing"
     }
   } else {
      putserv "PRIVMSG $chan :Can't find $nick in spamlist of $chan"
   }
}
I added a add:spam proc which is used to avoid multiple entries for a same nick in the spamlist
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Good catch on that string tolower $chan as this could have caused some issues.

Like I previously mentioned, should consider adding a nick change function and something for a bit of house keeping just in case something doesn't work as should and you end up with a big array stored in memory with a bunch of gunk.

One thing I don't understand why did you complicated the add:spam, meaning if the pos is above -1 (meaning it exists in the list) then unless you need to update the data there's no need to remove and then add it at the end. Here's something simplified:

Code: Select all

proc add:spam {nick chan} {
	set match 0
	if {[info exists ::spamlist($chan)]} {
		putserv "PRIVMSG $chan :spamlist exists for $chan"
		set pos [lsearch -nocase [dict keys [join $::spamlist($chan)]] $nick]
		if {$pos > -1} {
			putserv "PRIVMSG $chan :$nick was found in the list, skipping.."	
			incr match
		}
	}
	if {!$match} {
		putserv "PRIVMSG $chan :$nick wasn't in, adding.."
		lappend ::spamlist($chan) [list $nick [clock seconds]]
	}
}
So, swe first check if the spamlist array has records for #channel, then check if nick is found in them. If found we increment match, else will remain at default 0 value. At the end if match is 0 (meaning we don't have any records for nick) we add him in the list.
Once the game is over, the king and the pawn go back in the same box.
User avatar
CrazyCat
Revered One
Posts: 1216
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

I complicated the procedure to force the update of the last speaking action time for $nick on $chan and not skipping it.

Little example :

Code: Select all

[16:00:00] --> spammer as joined #test
[16:00:01] * spammer says hello to all
[16:00:05] <spammer> go on http://omg.spamming.net
[16:00:07] <-- spammer has quit (http://omg.spamming.net)
If you skip already existing user in spamlist, you'll have the 16:00:01 record, it won't ban when spammer quits at 16:00:07.

Your simplified version works only for spammers which don't speak until they "speak & quit". Mine will ban anyone which exit less than 6 seconds after he had spoke (this is how I understand the mirc script).

BTW, I think this script is a bad idea, polite pple as me will be banned:

Code: Select all

[16:59:57] <CrazyCat> Time to go, cya pple !
[16:59:59] <-- CrazyCat has quit (Cya)
s
simo
Revered One
Posts: 1070
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

thank you tried your last post got the same result:
17:29:54 (Greene) : testing one two three
17:29:54   Quits :   Greene   uid45646@uid-45646.highgate.irccloud.com (Quits: Left IRC)
17:29:54 (@TCL-Tester) : Can't find spamlist for #opers

17:30:27 (Burk) : testing one two three
17:30:27   Parts :   Burk   Jordon@BHYX1EUA.WGERDG6U.HVE14TFS.IP (Parts:)
17:30:27 (@TCL-Tester) : Can't find spamlist for #opers
User avatar
CrazyCat
Revered One
Posts: 1216
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

looks like add:spam is never called.

Modify the two first proc:

Code: Select all

proc pub:spam {nick uhost hand chan txt} {
   putserv "PRIVMSG $chan :get pub from $nick"
   add:spam $nick [string tolower $chan]
   putserv "PRIVMSG $chan :stored pub from $nick"
}

proc ctcp:spam {nick uhost hand chan key txt} {
   putserv "PRIVMSG $chan :get act from $nick"
   add:spam $nick [string tolower $chan]
   putserv "PRIVMSG $chan :stored act from $nick"
}
I think you have now enough debug examples to make yours own tests & debug.
s
simo
Revered One
Posts: 1070
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

seems to work proper now thanx CrazyCat and caesar much apreciated
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

@CrazyCat Ah, I see, in that case just replace it instead of removing and adding it again:

Code: Select all

proc add:spam {nick chan} {
	global spamlist
	set match 0
	set now [clock seconds]
	if {[info exists spamlist($chan)]} {
		putserv "PRIVMSG $chan :spamlist exists for $chan"
		set pos [lsearch -nocase [dict keys [join $spamlist($chan)]] $nick]
		if {$pos > -1} {
			scan [lindex $spamlist($chan) $pos] {%s%s} user time
			putserv "PRIVMSG $chan :$nick was found in the list, updating the seconds from $time to $now .."
			set spamlist($chan) [lreplace $spamlist($chan) $pos $pos [list $user $now]]
			incr match
		}
	}
	if {!$match} {
		putserv "PRIVMSG $chan :$nick wasn't in, adding.."
		lappend spamlist($chan) [list $nick $now]
	}
}
You can use the same lreplace line on the nick change function where you will have $newnick (or what variable you want to use) instead of $user :wink:
Once the game is over, the king and the pawn go back in the same box.
s
simo
Revered One
Posts: 1070
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

I think having to avoiding checking wether nick has changed perhaps its better to use *! *@host:channel to store and use that way it wont matter if they change nick
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

What if there are two distinct people with same host? :)
Once the game is over, the king and the pawn go back in the same box.
s
simo
Revered One
Posts: 1070
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

We allow 1 nick per IP on this network caesar
Last edited by simo on Sun Sep 27, 2020 4:31 pm, edited 1 time in total.
s
simo
Revered One
Posts: 1070
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

could this be modified to have it check for host instead of nick so we dont have to worry about changed nicks or adding another proc for nick ?
Post Reply