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.

ForEach Channel [Help] {Solved}

Help for those learning Tcl or writing their own scripts.
Post Reply
B
Branden
Halfop
Posts: 61
Joined: Sat Aug 04, 2007 8:36 pm

ForEach Channel [Help] {Solved}

Post by Branden »

How can I script something that will happen on all channels that the bot is on.


Code: Select all

bind n|n "!MassMode" MassMode


proc MassMode { nick host hand chan text } {
	set Modes [lindex [split $text] 0]
	foreach ??????? {
		putquick "MODE $chan $Modes"
	}
}

Last edited by Branden on Sat Oct 04, 2008 2:48 pm, edited 1 time in total.
t
tueb
Halfop
Posts: 76
Joined: Thu Oct 04, 2007 6:09 am
Location: #quiz.de @ irc.gamesurge.net
Contact:

Post by tueb »

hi,

this is from one of the scripts i'm using (moxquizz):

Code: Select all

## act on all channels
proc mxirc_action_everywhere {text} {
    foreach channel [channels] {
	if {[validchan $channel] && [botonchan $channel]} {
	    mxirc_action $channel $text
	}
    }
}
#Quiz.de @ irc.GameSurge.net
JavaChat
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

The example is good, though I'm a bit curious as to the "validchan" check, as all channels returned by the "channels" command are valid..

If you wish to avoid unnecessary "penalty-points", checking for ops might be a good idea however.

Code: Select all

...
if {[botonchan $channel] && [botisop $channel]} {
...
NML_375
l
leprechau
Voice
Posts: 2
Joined: Fri Oct 03, 2008 9:56 pm
Contact:

Post by leprechau »

Are you wanting a foreach channel...or mass modes? Loops in TCL are very simple and mass modes can be done in a couple different ways. The absolute fastest mass mode is a raw mode sent in a single line. Look below for some really old code I threw together late 1990s or so, it's been tweaked a few times but not really much has changed. There are several decent example procs in there that use loops and op checks. You can also see how to send multiple mode lines to irc in a single server message. This is the fastest possible way to do mass modes via irc.

Code: Select all

## fastest raw mass deop possible + some really fast superbitch/mdop protect
## channel flags: .chanset #channel +takeover || .chanset #channel +keepit
## partyline commands: .take -> net mass deop || .massdeop -> single bot mass deop
## by leprechau@EFnet
##
## NOTE: always check for new code/updates at http://woodstock.anbcs.com/scripts/
## this is the only official location for any of my scripts
##

namespace eval ::tkeep {

	proc massraw {pm mode tgt arg} {
		foreach {1 2 3 4} $arg {
			append mlines "MODE $tgt ${pm}${mode}${mode}${mode}${mode} $1 $2 $3 $4\n"
		}
		if {[info exists mlines]} {putdccraw 0 [string length $mlines\n] $mlines\n}
	}

	proc doit {dchan dnicks dtype} {
		putlog "\[\002MASSDEOP\002\] Deopping \002[llength $dnicks]\002 non-op(s) on \002$dchan\002 using method $dtype ..."
		switch -- $dtype {
			3 {
				while {[llength $dnicks] > 1} {
					lappend tmp [lindex $dnicks [set half [expr {[llength $dnicks] / 2}]]]
					set dnicks [lreplace $dnicks $half $half]
				}
				lappend tmp [lindex $dnicks 0]; ::tkeep::massraw - o $dchan $tmp
			}
			2 {::tkeep::massraw - o $dchan [lsort -decreasing $dnicks]}
			1 {::tkeep::massraw - o $dchan [lsort -increasing $dnicks]}
			default {
				foreach x $dnicks {
					lappend mixed [lindex $dnicks [set rindex [rand [llength $dnicks]]]]
					set dnicks [lreplace $dnicks $rindex $rindex]
				}; if {[info exists mixed]} {::tkeep::massraw - o $dchan $mixed}
			}
		}
	}

	proc oplist {chan {flags {o}}} {
		foreach nick [chanlist $chan] {
			if {[isop $nick $chan] && ![matchattr [nick2hand $nick $chan] $flags|$flags $chan]} {lappend oplist $nick}
		}
		if {[info exists oplist]} {return $oplist} else {return {}}
	}

	proc massrawdeop {hand idx text} {
		if {![string length $text]} {putdcc $idx "\002Usage\002: $::lastbind <channel> ?type?"; return}
		if {![validchan [set dchan [lindex [split $text] 0]]]} {putdcc $idx "Unable to mass deop '$dchan' - invalid channel."; return}
		if {![botisop $dchan]} {putdcc $idx "Unable to mass deop '$dchan' - not opped."; return}
		if {[llength [set dnicks [::tkeep::oplist $dchan]]] < 1} {putdcc $idx "\002***\002 No action taken, noone to deop on \002$dchan\002."; return}
		if {[string length [lindex [split $text] 1]] && [string is integer [lindex [split $text] 1]]} {set dtype [lindex [split $text] 1]}
		if {(![info exists dtype]) || ($dtype > 3)} {set dtype 0}
		::tkeep::doit $dchan $dnicks $dtype
	}
	bind dcc n massdeop ::tkeep::massrawdeop

	proc netmassrawdeop {hand idx text} {
		if {![string length $text]} {putdcc $idx "\002Usage:\002 .take <channel> ?type?"; return}
		putallbots "netmassrawdeop [lindex [split $text] 0]"; ::tkeep::massrawdeop $hand $idx $text
	}
	bind dcc n take ::tkeep::netmassrawdeop

	proc botmassrawdeop {from command text} {
		foreach {chan nicks} $text {}
		if {(![validchan $chan]) || (![botisop $chan]) || ([llength $nicks] < 1)} {return}
		::tkeep::doit $chan $nicks [rand 4]
	}
	bind bot - netmassrawdeop ::tkeep::botmassrawdeop

	## out takevoer/protect flag :)
	setudef flag takeover; setudef flag keepit

	proc checkchannel {from keyword text} {
		foreach {nick uhost} [split $from !] {}
		foreach {chan modes v1 v2 v3 v4} [split $text] {}
		switch -glob -- $modes {
			+o* {
				if {[channel get $chan takeover]} {
					foreach vict {v1 v2 v3 v4} {
						if {[string equal -nocase $::botnick [set $vict]]} {
							::tkeep::doit $chan [set ops [::tkeep::oplist $chan]] [rand 4]; putallbots [list netmassrawdeop $chan $ops]; break
						}
					}
				}
				if {[channel get $chan keepit]} {
					foreach vict {v1 v2 v3 v4} {
						if {[string length [set $vict]] && ![matchattr [nick2hand [set $vict] $chan] o|o $chan]} {lappend bnicks [set $vict]}
					}
					if {[info exists bnicks]} {
						lappend bnicks $nick; ::tkeep::doit $chan $bnicks [rand 4]; putallbots [list netmassrawdeop $chan $bnicks]
					}
				}
			}
			-o* {
				if {[channel get $chan keepit] && ![matchattr [nick2hand $nick] b]} {
					## see if we need to reop anything...
					foreach vict {v1 v2 v3 v4} {
						if {[string length [set $vict]] && [matchattr [nick2hand [set $vict] $chan] o|o $chan]} {lappend reops [set $vict]}
					}; if {[info exists reops]} {::tkeep::massraw + o $chan $reops}
					## only massdeop in case of 3 or more -o
					if {[string match -nocase *ooo* $modes]} {
						::tkeep::doit $chan [set ops [concat [::tkeep::oplist $chan] $nick]] [rand 4]; putallbots [list netmassrawdeop $chan $ops]; return
					}
				}
			}
			default {return}
		}
	}
	bind raw - MODE ::tkeep::checkchannel
}
putlog "take&keep.tcl by leprechau@efnet loaded!"
leprechau@EFnet
Post Reply