tcldrop-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tcldrop/CVS] tcldrop/modules/irc irc.tcl


From: Philip Moore
Subject: [Tcldrop/CVS] tcldrop/modules/irc irc.tcl
Date: Fri, 28 Nov 2003 19:50:08 -0500

CVSROOT:        /cvsroot/tcldrop
Module name:    tcldrop
Branch:         
Changes by:     Philip Moore <address@hidden>   03/11/28 19:50:08

Modified files:
        modules/irc    : irc.tcl 

Log message:
        Replaced the pushmode/flushmode commands Papillion made with ones that 
work, and support $prevent-mixing and $modes-per-line settings.  =D

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/tcldrop/tcldrop/modules/irc/irc.tcl.diff?tr1=1.24&tr2=1.25&r1=text&r2=text

Patches:
Index: tcldrop/modules/irc/irc.tcl
diff -u tcldrop/modules/irc/irc.tcl:1.24 tcldrop/modules/irc/irc.tcl:1.25
--- tcldrop/modules/irc/irc.tcl:1.24    Tue Nov 25 19:54:03 2003
+++ tcldrop/modules/irc/irc.tcl Fri Nov 28 19:50:07 2003
@@ -4,7 +4,7 @@
 #              * All IRC related commands.
 #      Depends: core, server, channels.
 #
-# $Id: irc.tcl,v 1.24 2003/11/26 00:54:03 fireegl Exp $
+# $Id: irc.tcl,v 1.25 2003/11/29 00:50:07 fireegl Exp $
 #
 # Copyright (C) 2003 Tcldrop Development Team <Tcldrop-Devel>
 #
@@ -30,7 +30,7 @@
 namespace eval ::tcldrop::irc {
        # Provide the irc module:
        variable version {0.2}
-       variable rcsid {$Id: irc.tcl,v 1.24 2003/11/26 00:54:03 fireegl Exp $}
+       variable rcsid {$Id: irc.tcl,v 1.25 2003/11/29 00:50:07 fireegl Exp $}
        package provide tcldrop::irc $version
        # Initialize variables:
        # Nicks stores the non-channel specific info for each nick:
@@ -48,6 +48,9 @@
        # PushModes stores all the modes that need to be pushed to the server 
when we next hit the Tcl event loop (or when flushmode is called manually).
        variable PushModes
        array set PushModes {}
+       # Set default globals:
+       ::tcldrop::SetDefault prevent-mixing 1
+       ::tcldrop::SetDefault modes-per-line 3
        # Export all the commands that should be available to 3rd-party 
scripters:
        namespace export resetchan onchan botonchan nick2hand hand2nick 
handonchan getchanhost getchanjoin onchansplit chanlist getchanidle getchanmode 
pushmode flushmode topic botisop botishalfop botisvoice isop ishalfop wasop 
washalfop isvoice ischanban ischanexempt ischaninvite chanbans chanexempts 
chaninvites resetbans resetexempts resetinvites
 }
@@ -185,7 +188,7 @@
 }
 
 # Proc by address@hidden
-# FixMe: Untested and unmodified.
+# FixMe: Untested.
 # (Papillon) -> I do not know what you want to share with the pushmode, but 
here is a little something to get you started.
 bind raw - MODE ::tcldrop::irc::MODE 99
 proc ::tcldrop::irc::MODE {from key arg} {
@@ -206,7 +209,6 @@
        foreach mo [split $splitted] {
                if {$mo == {+} || $mo == {-}} {
                        set lastm $mo
-                       continue
                } elseif {$mo != {}} {
                        set mc "${lastm}$mo"
                        set victim [lindex $arg $v]
@@ -250,7 +252,7 @@
        set address [lindex $larg 3]
        #set unknown [lindex $larg 4]
        set realname [string range [join [lrange $larg 5 end]] 1 end]
-       set handle [finduser "address@hidden"]
+       set handle [finduser "address@hidden"]
        variable Nicks
        set element [string tolower $nick]
        array set nickinfo [array get Nicks $element]
@@ -1034,51 +1036,113 @@
 #      be sent out at once (combined into one line as much as possible) after
 #      the script finishes, or when 'flushmode' is called.
 #    Returns: nothing
-# Proc by address@hidden
 proc ::tcldrop::irc::pushmode {channel mode {arg {}}} {
-       if {[botonchan $channel]} {
-               putserv "MODE $channel $mode $arg"
-               # FixMe: We're returning here, because the rest of this code is 
broken (not to mention ugly)!
-               return 0
+       if {[validchan $channel] && [botonchan $channel]} {
                variable PushModes
-               set element [string tolower $channel,$mode]
-               if {[info exists PushModes($element)] } {
-                       array set modestodo $PushModes($element)
-                       if {$arg != {}} { set arg [join "$modestodo(victim) 
$arg"] }
+               set channel [string tolower $channel]
+               if {[info exists PushModes($channel)] && [set pos [lsearch 
-glob $PushModes($channel) "?[string index $mode 1] $arg"]] != -1} {
+                       # A conflicting or duplicate mode was found. So we 
replace it.
+                       lreplace $PushModes($channel) $pos $pos "$mode $arg"
+               } else {
+                       # Otherwise we just lappend to the end:
+                       lappend PushModes($channel) "$mode $arg"
                }
-               array set modestodo [list mode $mode victim $arg]
-               set PushModes($element) [array get modestodo]
                after idle [list flushmode $channel]
+               return 1
+       } else {
+               return 0
        }
 }
 
-#  flushmode <channel>
+proc ::tcldrop::irc::GroupModes {modes} {
+       set out [list]
+       # First, put modes that shouldn't be mixed into separate groups. 
($prevent-mixing)
+       if {${::prevent-mixing}} {
+               foreach m $modes {
+                       switch -- [string index $m 1] {
+                               {e} - {I} { set g 2 }
+                               {default} { set g 1 }
+                       }
+                       lappend modegroup($g) $m
+               }
+       } else {
+               set modegroup(0) $modes
+       }
+       # Process each group separately..
+       foreach g [array names modegroup] {
+               # Clear the vars from the last group:
+               set plusmodes {}
+               set minusmodes {}
+               set plusvictims [list]
+               set minusvictims [list]
+               # Process each mode..
+               foreach m $modegroup($g) {
+                       set victim [string range $m 3 end]
+                       # Separate the + and - modes:
+                       switch -- [string index $m 0] {
+                               {+} {
+                                       if {$plusmodes == {}} { set plusmodes 
{+} }
+                                       append plusmodes [string index $m 1]
+                                       if {$victim != {}} { lappend 
plusvictims $victim }
+                               }
+                               {-} {
+                                       if {$minusmodes == {}} { set minusmodes 
{-} }
+                                       append minusmodes [string index $m 1]
+                                       if {$victim != {} } { lappend 
minusvictims $victim }
+                               }
+                       }
+                       if {[string length "[string trimleft $plusmodes 
+][string trimleft $minusmodes -]"] >= ${::modes-per-line}} {
+                               # $modes-per-line limit reached..
+                               if {[llength [set victims [concat $plusvictims 
$minusvictims]]]} {
+                                       lappend out "$plusmodes$minusmodes 
[join $victims]"
+                               } else {
+                                       lappend out "$plusmodes$minusmodes"
+                               }
+                               # Clear the vars:
+                               set plusmodes {}
+                               set minusmodes {}
+                               set plusvictims [list]
+                               set minusvictims [list]
+                       }
+               }
+               # Process the leftovers from the group:
+               if {[llength [set victims [concat $plusvictims 
$minusvictims]]]} {
+                       lappend out "$plusmodes$minusmodes [join $victims]"
+               } elseif {[string length "$plusmodes$minusmodes"]} {
+                       lappend out "$plusmodes$minusmodes"
+               }
+       }
+       return $out
+}
+
+
+#  flushmode [channel]
 #    Description: forces all previously pushed channel mode changes to be
 #      sent to the server, instead of when the script is finished (just for
 #      the channel specified)
 #    Returns: nothing
-# Proc by address@hidden
-proc ::tcldrop::irc::flushmode {channel} {
-       # This needs to group together all the modes that pushmode collected 
and then send them out to the server.
-       if {![botonchan $channel]} { return }
+proc ::tcldrop::irc::flushmode {{channel {*}}} {
        variable PushModes
-       set element [string tolower $channel]
-       if {[array get PushModes $element,*] == {}} { return }
-       foreach mo [array names PushModes $element,*] {
-               array set modestodo $PushModes($mo)
-               set mod $modestodo(mode)
-               if {$modestodo(victim) != {}} {
-                       set base [string range $mod 1 end]
-                       while {[string length [string range $mod 1 end]] < 
[llength [set nlist [split $modestodo(victim)]]]} {
-                               append mod "$base"
+       # Process the modes for each channel array in PushModes:
+       foreach c [array names PushModes [string tolower $channel]] {
+               set modes [list]
+               foreach m $PushModes($c) {
+                       set victim [string trim [string range $m 3 end]]
+                       # If the mode we're going to set won't do anything, we 
continue on to the next mode..
+                       switch -- [string range $m 0 1] {
+                               {+o} { if {[isop $victim $c]} { continue } }
+                               {-o} { if {![isop $victim $c]} { continue } }
+                               {+v} { if {[isvoice $victim $c]} { continue } }
+                               {-v} { if {![isvoice $victim $c]} { continue } }
                        }
-                       putquick "MODE $channel $mod $modestodo(victim)"
-               } else {
-                       putquick "MODE $channel $mod"
+                       # Otherwise it's a mode we need to send, so lappend it 
to modes:
+                       lappend modes $m
                }
+               # GroupModes puts the modes together in an efficient way to 
send to IRC, and is aware of the $prevent-mixing and $modes-per-lines settings:
+               foreach m [GroupModes $modes] { putquick "MODE $c $m" }
        }
-       array unset PushModes $element,*
 }
+
 
 #  topic <channel>
 #    Returns: string containing the current topic of the specified channel




reply via email to

[Prev in Thread] Current Thread [Next in Thread]