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.

how to add multiple channel support in idleop.tcl

Help for those learning Tcl or writing their own scripts.
Post Reply
p
pakistani1
Voice
Posts: 26
Joined: Wed Apr 20, 2005 11:35 pm
Location: Pakistan Zindabad
Contact:

how to add multiple channel support in idleop.tcl

Post by pakistani1 »

Code: Select all

set idle_interval "6"

set idle_time "5"

set idle_exclude_bots "1"
 
set idle_channels "#channel1 #channel2 #channel3"

bind raw - 317 idlecheck

proc idlecheck {nick int arg} {
  global idle_time idle_channels
   set nick [string tolower [lindex $arg 1]]
   set idle [string tolower [lindex $arg 2]]
   set minutesidle [expr $idle / 60]
   if {$minutesidle > $idle_time && $nick != "^pagli^" && $nick != "Pakistani1" && $nick != "n0mercy" && $nick != "Go|dLeaf" && $nick != "priya007" && $nick != "^ash^" && $nick != "PehReDaaR" && $nick != "pinky^" && $nick != "bilal" && $nick != "huzur" && $nick != "janat" } {
      foreach channel $idle_channels {
         putserv "PRIVMSG Chanserv@services.dal.net :deop $channel $nick"
	   putserv "PRIVMSG $channel :deoped  $nick from $channel (too Much Idle)"
	   putserv "privmsg $nick :deoped u from $channel (too much idle)"
      }
    }
}

proc perform_whois { } {
  global idle_channels botnick idle_exclude_bots idle_interval
    if {$idle_channels == " "} {
      set idle_temp [channels]
    } else {
    set idle_temp $idle_channels
    }
    foreach chan $idle_temp {
       foreach person [chanlist $chan] { 
         if { [isop $person $chan]} { 
           if {$idle_exclude_bots == 1} {
             if {(![matchattr [nick2hand $person $chan] b]) && ($person != $botnick) && $person != "topguard" && $person != "pr0b"} { putserv "WHOIS $person $person" }
           }
           if {$idle_exclude_bots == 0} {
              if {$person != $botnick} { putserv "WHOIS $person $person" }
           }
         } 
       } 
    }
if {![string match "*time_idle*" [timers]]} {
 timer $idle_interval perform_whois
  }
}
if {![string match "*time_idle*" [timers]]} {
 timer $idle_interval perform_whois
  }
the script works fine if only one channel is added in set idle_channels "#channel1"

but when i add multiple channels .. it tries to deop idle nicks on all the channels even if the nick is not in that channel ..

eg if nick1 is oped in #channel1 and the script is turned on in #channel1 #channel2 #channel3
the bot sends
msg chanserv@services.dal.net deop #channel1 nick1
msg chanserv@services.dal.net deop #channel2 nick1
msg chanserv@services.dal.net deop #channel3 nick1

even if nick1 is not on #channel2 and #channel3

can some one please tell me how to fix this ?
!~!~!~!~!~ ::Long Live The REpubLic ::~!~!~!
N
Nimos
Halfop
Posts: 80
Joined: Sun Apr 20, 2008 9:58 am

Post by Nimos »

Code: Select all

foreach channel $idle_channels {
         putserv "PRIVMSG Chanserv@services.dal.net :deop $channel $nick"
      putserv "PRIVMSG $channel :deoped  $nick from $channel (too Much Idle)"
      putserv "privmsg $nick :deoped u from $channel (too much idle)"
      } 
thats your problem!

use the "search thing" instead of foreach...sry I dont know the command at the moment :oops:
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

@Nimos, you are close (we need the foreach, it isn't replaced at all).. but since you can't be correct, why do you even post? To raise your post count?

Code: Select all

if {[lsearch -exact [chanlist $channel] $nick] != -1} {
A simple check like this in the appropriate place is what is needed. This will return a 1 (since nicks cannot repeat) if our nick is in the channel list, or a -1 if it is not. Simply checking that it isn't -1 does it.

@pakistani1, this should fix it. Also allows you to use .chanset #youchan +idletime
Also cleaned up your injection of nicks into the evaluation statements. You can now add/remove nicks without having to 'code' them in.

Code: Select all

#--- begin  config ---#

# how often to check idletime
set idle_interval "6"

# max idletime allowed
set idle_time "5"

# exclude other bots from deop?
set idle_exclude_bots "1"

# nicks exempt from deop
set idle_exempt_nicks "^pagli^ Pakistani1 n0mercy Go|dLeaf priya007 ^ash^ PehReDaaR pinky^ bilal huzur janat"

# nicks exempt from whois
set whois_exempt_nicks "topguard pr0b"

# enter the name of the channel service bot here
set idle_servicebot "Chanserv@services.dal.net"

# enter your idle message given here
set idle_message_chan "deoped %nick from %channel (Too Much Idle!)"
set idle_message_nick "deoped you from %channel (Inactive Op with too much idle)"

#--- end of config ---#

bind raw - 317 idlecheck

setudef flag idlechan

proc idlecheck {nick int arg} {
	global idle_time
	set nick [lindex [split $arg] 1]
	set minutesidle [expr {[lindex [split $arg] 2] / 60}]
	if {($minutesidle > $idle_time) && ([lsearch -nocase -exact [split $::idle_exempt_nicks] $nick] == -1)} {
		foreach channel [channels] {
			if {[lsearch -exact [channel info $channel] +idlechan] != -1} {
				# this fixes the problem with chanserv deop messages
				# given when that nick isn't even in the channel
				if {[lsearch -nocase -exact [chanlist $channel] $nick] != -1} {
					# this allows us to use dynamic messages containing
					# variable references which will be replaced
					set idle_mchan [string map {% $} $::idle_message_chan]
					set idle_mnick [string map {% $} $::idle_message_nick] 
					putserv "PRIVMSG $::idle_servicebot :deop $channel $nick"
					putserv "PRIVMSG $channel :$idle_mchan"
					putserv "PRIVMSG $nick :$idle_mnick"
				}
			}
		}
	}
}

proc perform_whois { } {
	global idle_exclude_bots idle_interval
	foreach chan [channels] {
		if {[lsearch -exact [channel info $chan] +idlechan] != -1} {
			foreach person [chanlist $chan] {
				if {[isop $person $chan]} {
					if {$idle_exclude_bots != 0} {
						if {![matchattr [nick2hand $person $chan] b] && ([lsearch -nocase -exact [split $::whois_exempt_nicks] $person] == -1)} {
							putserv "WHOIS $person $person" 
						}
					} else {
						if {![isbotnick $person] && ([lsearch -exact [split $::whois_exempt_nicks] $person] == -1)} { putserv "WHOIS $person $person" }
					}
				}
			}
		}
	}
	if {![string match "*time_idle*" [timers]]} {
		timer $idle_interval perform_whois
	}
}

if {![string match "*time_idle*" [timers]]} {
	timer $idle_interval perform_whois
} 
Edit: edited to correct problem noted below, forgot to :: those global variables.. DOH!
Also neated up a ton of stuff.. enjoyz :wink:
Last edited by speechles on Wed Jun 11, 2008 10:29 am, edited 20 times in total.
p
pakistani1
Voice
Posts: 26
Joined: Wed Apr 20, 2005 11:35 pm
Location: Pakistan Zindabad
Contact:

Post by pakistani1 »

thanku for ur help speechles
here is the error that i got after i used the above script

can't read "whois_exempt_nicks": no such variable
!~!~!~!~!~ ::Long Live The REpubLic ::~!~!~!
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Try the edited code above, heh. Forgot to globalize those variable calls, in other words used $ instead of $:: ..
p
pakistani1
Voice
Posts: 26
Joined: Wed Apr 20, 2005 11:35 pm
Location: Pakistan Zindabad
Contact:

Post by pakistani1 »

the problem persists .. the bot gives the command to deop the idle nick on all the channels the script is turned on..
plus it is now not ignoring the idle_exempt_nicks it deopes the nicks present in the idle_exempt_nicks nick list ...
!~!~!~!~!~ ::Long Live The REpubLic ::~!~!~!
Post Reply