egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

check if nick is still on channel before kicking

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
simo
Revered One


Joined: 22 Mar 2015
Posts: 1027

PostPosted: Sun Jan 08, 2023 8:41 pm    Post subject: check if nick is still on channel before kicking Reply with quote

greetingz gentz,

i'm wondering how to edit this code in the kick proc to check if nick(s) are still in channel before executing the kick command(s) as we use a timer, let me post the code:

Code:


namespace eval enforceBans {

   set enforce(max) "4"

   set enforce(reason_single) "Please respect the network rules, thank you."
   set enforce(reason_multi) "Please respect the network rules, thank you."

   bind mode - "% +b" [namespace current]::enforce

   proc enforce {nick uhost hand chan mc ban} {
      variable kickList
      if {[matchaddr $ban $::botname]} { return 0 }
     
      foreach n [chanlist $chan] {
         if {![matchaddr $ban $n![getchanhost $n $chan]]} { continue }
         if {[isop $n $chan] || [ishalfop $n $chan]} { continue }
         if {[matchattr [nick2hand $n] "fnmo|fnmo" $chan]} { continue }
         lappend klist $n
      }
      if {![info exists klist]} { return 0 }

      if {![info exists kickList($chan)]} {
         set kickList($chan) $klist
         after 300 [list "[namespace current]::enforce:kick" $chan]

      } else {  lappend kickList($chan) {*}$klist  }

      return 0
   }

   proc enforce:kick {chan} {
      variable enforce
      variable kickList
      if {![botisop $chan] || ![info exists kickList($chan)]} {
         array unset kickList $chan
         return 0
      }

      set knicks [lsort -unique -dictionary $kickList($chan)]
      unset kickList($chan)

      set max $enforce(max)
      set reason [string map [list %from $chan] $enforce(reason_multi)]


      while {[set len [llength $knicks]] > 0} {
        if {$len > $max} {
          set nicks [join [lrange $knicks 0 [expr {$max - 1}]] ","]
          set knicks [lrange $knicks $max end]
        } else {
          set nicks [join $knicks ","]
          set knicks ""
        }
         after 2000 [list putnow "KICK $chan $nicks :$reason"]
      }
      return 0
   }
}




thanks in advance gentz,
Back to top
View user's profile Send private message
simo
Revered One


Joined: 22 Mar 2015
Posts: 1027

PostPosted: Mon Jan 09, 2023 4:21 pm    Post subject: Reply with quote

i gave it a try and came of with this it seems to work but im not sure if its done proper

Code:


   proc enforce:kick {chan} {
      variable enforce
      variable kickList
      variable NewKickList
      if {![botisop $chan] || ![info exists kickList($chan)]} {
         array unset kickList $chan
         return 0
      }

  foreach nickx $kickList($chan) { if {[onchan $nickx $chan]} {  set klist $nickx ;  lappend NewKickList($chan) $klist  } }
      set knicks [lsort -unique -dictionary $NewKickList($chan)]
      unset kickList($chan)
      unset NewKickList($chan)
 
      set max $enforce(max)
      set reason [string map [list %from $chan] $enforce(reason_multi)]


      while {[set len [llength $knicks]] > 0} {
        if {$len > $max} {
          set nicks [join [lrange $knicks 0 [expr {$max - 1}]] ","]
          set knicks [lrange $knicks $max end]
        } else {
          set nicks [join $knicks ","]
          set knicks ""
        }
         after 2000 [list putnow "KICK $chan $nicks :$reason"]
      }
      return 0
   }


Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1108
Location: France

PostPosted: Mon Jan 09, 2023 7:15 pm    Post subject: Reply with quote

This doesn't really solve your problem as the kick occures each 2s.
_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 826
Location: Tennessee, USA

PostPosted: Mon Jan 09, 2023 7:27 pm    Post subject: enforceBans Reply with quote

maybe...

Code:

namespace eval enforceBans {  variable enforce  ;  variable kickList

   set enforce(max) "4"

   set enforce(reason_single) "Please respect the network rules, thank you."
   set enforce(reason_multi) "Please respect the network rules, thank you."

   bind mode - "% +b" [namespace current]::enforce

   proc enforce {nick uhost hand chan mc ban} {
      variable kickList
      if {[matchaddr $ban $::botname]} { return 0 }
     
      foreach n [chanlist $chan] {
         if {![matchaddr $ban $n![getchanhost $n $chan]]} { continue }
         if {[isop $n $chan] || [ishalfop $n $chan]} { continue }
         if {[matchattr [nick2hand $n] "fnmo|fnmo" $chan]} { continue }
         lappend klist $n
      }
      if {![info exists klist]} { return 0 }

      if {![info exists kickList($chan)]} {
         set kickList($chan) $klist

         after 2300 [list "[namespace current]::enforce:kick" $chan]

      } else {  lappend kickList($chan) {*}$klist  }

      return 0
   }

   proc enforce:kick {chan} {
      variable enforce
      variable kickList
      if {![botisop $chan] || ![info exists kickList($chan)]} {

         if {[info exists kickList($chan)]} {  unset kickList($chan)  }

         return 0
      }


      foreach k [lsort -unique -dictionary $kickList($chan)] {
         if {[onchan $k $chan]} {  lappend knicks $k  }
      }
      unset kickList($chan)

      if {![info exists knicks]} {  return 0  }


      set max $enforce(max)
      set reason [string map [list %from $chan] $enforce(reason_multi)]


      while {[set len [llength $knicks]] > 0} {
        if {$len > $max} {
          set nicks [join [lrange $knicks 0 [expr {$max - 1}]] ","]
          set knicks [lrange $knicks $max end]
        } else {
          set nicks [join $knicks ","]
          set knicks ""
        }


        putnow "KICK $chan $nicks :$reason"

      }
      return 0
   }
}


_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Back to top
View user's profile Send private message Visit poster's website
simo
Revered One


Joined: 22 Mar 2015
Posts: 1027

PostPosted: Tue Jan 10, 2023 2:54 am    Post subject: Reply with quote

thanks for the reply CrazyCat and SpiKe^^

yes i overlooked the duplicate timers to kick thanks for correcting CrazyCat

i tried your posted code and it didnt seem to Trigger SpiKe^^ and i didnt get any errors
Back to top
View user's profile Send private message
simo
Revered One


Joined: 22 Mar 2015
Posts: 1027

PostPosted: Tue Jan 10, 2023 3:02 am    Post subject: Reply with quote

i tried editing it to this :


Code:


      foreach k "[lsort -unique -dictionary $kickList($chan)]" {
         if {[onchan $k $chan]} {  lappend knicks $k  }
      }



it seems to have fixed it but not sure if i edited it proper tho
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 826
Location: Tennessee, USA

PostPosted: Tue Jan 10, 2023 4:32 am    Post subject: Reply with quote

No, it was "proper" as I posted it originally.
_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Back to top
View user's profile Send private message Visit poster's website
simo
Revered One


Joined: 22 Mar 2015
Posts: 1027

PostPosted: Tue Jan 10, 2023 5:59 am    Post subject: Reply with quote

Using the original one you posted didn't seem to trigger SpiKe i will try again later when im on pc and report again hopefully thanks SpiKe
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3767
Location: Mint Factory

PostPosted: Tue Jan 10, 2023 12:49 pm    Post subject: Reply with quote

If for whatever reason lsort doesn't work for you then try with dict, here's an example:
Code:

foreach ele $myList {dict set tmp $ele myList}
set unique [dict keys $tmp]

I would switch back to the original 'enforce:kick' and use a helper function instead:
Code:

proc filter:kick {chan} {
   if {![botisop $chan] || ![info exists kickList($chan)]} return
   foreach ele $kickList($chan) {dict set tmp $ele kickList($chan)}
   set kickList($chan) [dict keys $tmp]
   enforce:kick $chan
}

and call filter:kick in the after line instead of the enforce:kick.
_________________
Once the game is over, the king and the pawn go back in the same box.
Back to top
View user's profile Send private message
simo
Revered One


Joined: 22 Mar 2015
Posts: 1027

PostPosted: Tue Jan 10, 2023 3:47 pm    Post subject: Reply with quote

thanks for your reply caesar ive tried your suggestion as well and for some reason it doesnt seem to trigger and i didnt get any error in PL
Back to top
View user's profile Send private message
simo
Revered One


Joined: 22 Mar 2015
Posts: 1027

PostPosted: Tue Jan 10, 2023 4:43 pm    Post subject: Reply with quote

ive tested again and original code seems to work fine now SpiKe^^ thanks much apreciated
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber