Przeglądaj źródła

templated output with proc sarvar

Paul Klumpp 12 lat temu
rodzic
commit
707c5fecfe
1 zmienionych plików z 93 dodań i 72 usunięć
  1. 93 72
      cims.tcl

+ 93 - 72
cims.tcl

@@ -90,6 +90,20 @@ namespace eval ::cims {
 	set layout(local_reply) "::cims:: Sent to @@chan_cnt@@ channels, @@user_cnt@@ unique users."
 	set layout(user_banned) "::cims:: You're not allowed to send messages. Reason: @@reason@@"
 
+	set layout(output_enabled) "::cims:: @@freqname@@ _output_ enabled for @@chan@@"
+	set layout(output_disabled) "::cims:: @@freqname@@ _output_ disabled for @@chan@@"
+	set layout(output_toggle_enabled) "::cims:: toggling @@freqname@@ _output_, now enabled for @@chan@@"
+	set layout(output_toggle_disabled) "::cims:: toggling @@freqname@@ _output_, now disabled for @@chan@@"
+
+	set layout(color_enabled) "::cims:: @@freqname@@ _coloroutput_ enabled for @@chan@@"
+	set layout(color_disabled) "::cims:: @@freqname@@ _coloroutput_ disabled for @@chan@@"
+	set layout(color_toggle_enabled) "::cims:: toggling @@freqname@@ _coloroutput_, now enabled for @@chan@@"
+	set layout(color_toggle_disabled) "::cims:: toggling @@freqname@@ _coloroutput_, now disabled for @@chan@@"
+
+	set layout(history_missing) "::cims:: no accumulated history for @@network@@ @@freqname@@"
+	set layout(history_start) "::cims:: last @@mnet_max_history@@ messages of @@network@@ @@freqname@@:"
+	set layout(history_message) "(@@x_count@@/@@list_length@@) @@msg@@"
+
   # list
   set mnet_local_config ""
   unset mnet_local_config
@@ -426,7 +440,7 @@ proc ::cims::xmlDefaultCmd {data} {
 
 namespace eval ::cims {
   ## some internal variables for messaging and stuff :) not your business after all.
-  set mnet(version) "cims!1.15many_plugins"
+  set mnet(version) "cims!1.16templated_outputs"
 
   set mnet_max_history 8
 
@@ -1041,9 +1055,9 @@ proc ::cims::sarvar {layout_string} {
 		#putlog "thong: $thong"
 		
 		# delete upvar link, if it existed.
-		if {[info exists replacer]} {
-			unset replacer
-		}
+		#if {[info exists replacer]} {
+		#	unset replacer
+		#}
 		# find the variable that is available in the previous context and use this now..
 		upvar $thong replacer
 
@@ -1103,7 +1117,7 @@ proc ::cims::timeout_reply_from_local_for_netbots {name chan} {
 ### public reachable commands
 proc ::cims::history_frequency {nick mask hand chan text} {
 # proc triggered by specified $prefix_history
-  variable mnet 
+  variable layout 
   variable mnet_channels 
   variable mnet_bots 
   variable mnet_networks_by_prefix 
@@ -1124,41 +1138,44 @@ proc ::cims::history_frequency {nick mask hand chan text} {
 	#putlog "::cims:: the prefix is $prefix"
 
 	set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
-	set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
+	set freqname [join [lindex $mnet_networks_by_prefix($prefix) 1]]
 	set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
 	set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
 
-	putlog "network: $network"
-	set allowed [::cims::allowed_channel $network $name $prefix $nick $mask $chan]
+	#putlog "network: $network"
+	set allowed [::cims::allowed_channel $network $freqname $prefix $nick $mask $chan]
 	if {$allowed == 0} {
 		return 0
 	}
 	# now generally allowed.
 	putlog "mnet_history: $com triggered by $nick in $chan"
-	if {[info exists mnet_histories($network,$name)] == 1} {
-		set list_length [llength $mnet_histories($network,$name)]
+	if {[info exists mnet_histories($network,$freqname)] == 1} {
+		set list_length [llength $mnet_histories($network,$freqname)]
 		if {$list_length >= 1} {
-			set msg "::cims:: last $mnet_max_history messages of $network $name:"
+			
+			set msg [::cims::sarvar $layout(history_start)]
 			::putils::put_nick $nick $msg
-
 		
 			set x_count 0
-			foreach {msg} $mnet_histories($network,$name) {
+			foreach {msg} $mnet_histories($network,$freqname) {
 				incr x_count
 				set backwards_x [expr $list_length - $x_count]
-				set msg [lindex $mnet_histories($network,$name) $backwards_x]
-				::putils::put_nick $nick "($x_count/$list_length) $msg"
+				set msg [lindex $mnet_histories($network,$freqname) $backwards_x]
+
+				set output [::cims::sarvar $layout(history_message)]
+				::putils::put_nick $nick $output
 		
 			}
 		} 
 	} else {
-		::putils::put_nick $nick "::cims:: no accumulated history for $network $name"
+		set output [::cims::sarvar $layout(history_missing)]
+		::putils::put_nick $nick $output
 	}
 }
 
 proc ::cims::enable_frequency {nick mask hand chan text} {
 # proc triggered by specified $prefix_enable
-  variable mnet 
+  variable layout
   variable mnet_channels 
   variable mnet_bots 
   variable mnet_networks_by_prefix 
@@ -1178,29 +1195,30 @@ proc ::cims::enable_frequency {nick mask hand chan text} {
   #putlog "::cims:: the prefix is $prefix"
 
   set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
-  set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
+  set freqname [join [lindex $mnet_networks_by_prefix($prefix) 1]]
   set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
   set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
 
   #putlog "network: $network"
-  set allowed [::cims::allowed_channel $network $name $prefix $nick $mask $chan]
+  set allowed [::cims::allowed_channel $network $freqname $prefix $nick $mask $chan]
   if {$allowed == 0} {
     return 0
   }
   # now generally allowed.
 
-  putlog "mnet_freq_status: before $mnet_freqs_onoff($name,$chan)"
-  set mnet_freqs_onoff($name,$chan) 1
-  putlog "mnet_freq_status: now $mnet_freqs_onoff($name,$chan)"
+  putlog "mnet_freq_status: before $mnet_freqs_onoff($freqname,$chan)"
+  set mnet_freqs_onoff($freqname,$chan) 1
+  putlog "mnet_freq_status: now $mnet_freqs_onoff($freqname,$chan)"
 
-  ::putils::put_local_msg $chan "::cims:: $name _output_ enabled for $chan"
+	set output [::cims::sarvar $layout(output_enabled)]
+	::putils::put_local_msg $chan $output
 
 }
 
 proc ::cims::disable_frequency {nick mask hand chan text} {
 # proc triggered by specified $prefix_enable
-  variable mnet 
-  variable mnet_channels 
+	variable layout
+	variable mnet_channels 
   variable mnet_bots 
   variable mnet_networks_by_prefix 
   variable mnet_colors
@@ -1215,32 +1233,33 @@ proc ::cims::disable_frequency {nick mask hand chan text} {
 
 	# cutting .prefix_enable down to .prefix
 	set prefix [string range $com 0 [expr [string first _ $com] -1]]
-	putlog "::cims:: the prefix is $prefix"
+	#putlog "::cims:: the prefix is $prefix"
 
 	set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
-	set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
+	set freqname [join [lindex $mnet_networks_by_prefix($prefix) 1]]
 	set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
 	set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
 
 	#putlog "network: $network"
-	set allowed [::cims::allowed_channel $network $name $prefix $nick $mask $chan]
+	set allowed [::cims::allowed_channel $network $freqname $prefix $nick $mask $chan]
 	if {$allowed == 0} {
 		return 0
 	}
 	# now generally allowed.
 
 	
-	putlog "mnet_freq_status: before $mnet_freqs_onoff($name,$chan)"
-	set mnet_freqs_onoff($name,$chan) 0
-	putlog "mnet_freq_status: now $mnet_freqs_onoff($name,$chan)"
-	
-	::putils::put_local_msg $chan "::cims:: $name _output_ disabled for $chan"
+	putlog "mnet_freq_status: before $mnet_freqs_onoff($freqname,$chan)"
+	set mnet_freqs_onoff($freqname,$chan) 0
+	putlog "mnet_freq_status: now $mnet_freqs_onoff($freqname,$chan)"
+
+	set output [::cims::sarvar $layout(output_disabled)]
+	::putils::put_local_msg $chan $output
 	
 }
 
 proc ::cims::toggle_frequency {nick mask hand chan text} {
 # proc triggered by specified $prefix_toggle
-  variable mnet 
+  variable layout 
   variable mnet_channels 
   variable mnet_bots 
   variable mnet_networks_by_prefix 
@@ -1260,27 +1279,27 @@ proc ::cims::toggle_frequency {nick mask hand chan text} {
 	# putlog "::cims:: the prefix is $prefix"
 
 	set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
-	set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
+	set freqname [join [lindex $mnet_networks_by_prefix($prefix) 1]]
 	set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
 	set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
 
-	# putlog "network: $network"
-	set allowed [::cims::allowed_channel $network $name $prefix $nick $mask $chan]
+	set allowed [::cims::allowed_channel $network $freqname $prefix $nick $mask $chan]
 	if {$allowed == 0} {
 		return 0
 	}
 	# now generally allowed.
 
-	
-	putlog "mnet_freq_status: toggle $mnet_freqs_onoff($name,$chan)"
-	if {$mnet_freqs_onoff($name,$chan) == 1} {
-		set mnet_freqs_onoff($name,$chan) 0
-		::putils::put_local_msg $chan "::cims:: toggling ${name} _output_, now disabled for ${chan}"
+	putlog "mnet_freq_status: toggle $mnet_freqs_onoff($freqname,$chan)"
+	if {$mnet_freqs_onoff($freqname,$chan) == 1} {
+		set mnet_freqs_onoff($freqname,$chan) 0
+		set output [::cims::sarvar $layout(output_toggle_disabled)]
+		::putils::put_local_msg $chan $output
 	} else {
-		set mnet_freqs_onoff($name,$chan) 1
-		::putils::put_local_msg $chan "::cims:: toggling ${name} _output_, now enabled for ${chan}"
+		set mnet_freqs_onoff($freqname,$chan) 1
+		set output [::cims::sarvar $layout(output_toggle_enabled)]
+		::putils::put_local_msg $chan $output
 	}
-	putlog "mnet_freq_status: toggle now $mnet_freqs_onoff($name,$chan)"
+	putlog "mnet_freq_status: toggle now $mnet_freqs_onoff($freqname,$chan)"
 	
 	# frequency toggled .. :)
 	
@@ -1289,7 +1308,7 @@ proc ::cims::toggle_frequency {nick mask hand chan text} {
 #::cims::enable_color
 proc ::cims::enable_color {nick mask hand chan text} {
 # proc triggered by specified $prefix_enable
-  variable mnet 
+  variable layout 
   variable mnet_channels 
   variable mnet_bots 
   variable mnet_networks_by_prefix 
@@ -1307,12 +1326,12 @@ proc ::cims::enable_color {nick mask hand chan text} {
 	#putlog "::cims:: the prefix is $prefix"
 
 	set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
-	set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
+	set freqname [join [lindex $mnet_networks_by_prefix($prefix) 1]]
 	set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
 	set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
 
 	#putlog "network: $network"
-	set allowed [::cims::allowed_channel $network $name $prefix $nick $mask $chan]
+	set allowed [::cims::allowed_channel $network $freqname $prefix $nick $mask $chan]
 	if {$allowed == 0} {
 		return 0
 	}
@@ -1321,17 +1340,18 @@ proc ::cims::enable_color {nick mask hand chan text} {
 		return 0
 	}
 
-	putlog "mnet_color_status: before $mnet_colors_onoff($name,$chan)"
-	set mnet_colors_onoff($name,$chan) 1
-	putlog "mnet_color_status: now $mnet_colors_onoff($name,$chan)"
-	
-	::putils::put_local_msg $chan "::cims:: $name _coloroutput_ enabled for $chan"
+	putlog "mnet_color_status: before $mnet_colors_onoff($freqname,$chan)"
+	set mnet_colors_onoff($freqname,$chan) 1
+	putlog "mnet_color_status: now $mnet_colors_onoff($freqname,$chan)"
+
+	set output [::cims::sarvar $layout(color_enabled)]
+	::putils::put_local_msg $chan $output
 }
 
 #::cims::disable_color
 proc ::cims::disable_color {nick mask hand chan text} {
 # proc triggered by specified $prefix_enable
-  variable mnet
+  variable layout
   variable mnet_channels 
   variable mnet_bots 
   variable mnet_networks_by_prefix
@@ -1349,12 +1369,12 @@ proc ::cims::disable_color {nick mask hand chan text} {
 	#putlog "::cims:: the prefix is $prefix"
 
 	set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
-	set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
+	set freqname [join [lindex $mnet_networks_by_prefix($prefix) 1]]
 	set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
 	set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
 
 	#putlog "network: $network"
-	set allowed [::cims::allowed_channel $network $name $prefix $nick $mask $chan]
+	set allowed [::cims::allowed_channel $network $freqname $prefix $nick $mask $chan]
 	if {$allowed == 0} {
 		return 0
 	}
@@ -1363,18 +1383,18 @@ proc ::cims::disable_color {nick mask hand chan text} {
 		return 0
 	}
 
-	putlog "mnet_color_status: before $mnet_colors_onoff($name,$chan)"
-	set mnet_colors_onoff($name,$chan) 0
-	putlog "mnet_color_status: now $mnet_colors_onoff($name,$chan)"
+	putlog "mnet_color_status: before $mnet_colors_onoff($freqname,$chan)"
+	set mnet_colors_onoff($freqname,$chan) 0
+	putlog "mnet_color_status: now $mnet_colors_onoff($freqname,$chan)"
 	
-	::putils::put_local_msg $chan "::cims:: $name _coloroutput_ disabled for $chan"
+	set output [::cims::sarvar $layout(color_disabled)]
+	::putils::put_local_msg $chan $output
 }
 
-
 #::cims::toggle_color
 proc ::cims::toggle_color {nick mask hand chan text} {
 # proc triggered by specified $prefix_toggle
-  variable mnet
+  variable layout
   variable mnet_channels
   variable mnet_bots 
   variable mnet_networks_by_prefix
@@ -1393,12 +1413,12 @@ proc ::cims::toggle_color {nick mask hand chan text} {
 	# putlog "::cims:: the prefix is $prefix"
 
 	set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
-	set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
+	set freqname [join [lindex $mnet_networks_by_prefix($prefix) 1]]
 	set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
 	set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
 
 	# putlog "network: $network"
-	set allowed [::cims::allowed_channel $network $name $prefix $nick $mask $chan]
+	set allowed [::cims::allowed_channel $network $freqname $prefix $nick $mask $chan]
 	if {$allowed == 0} {
 		return 0
 	}
@@ -1406,17 +1426,18 @@ proc ::cims::toggle_color {nick mask hand chan text} {
 	if {$mnet_colors_optional($network) != 1} {
 		return 0
 	}
-
 	
-	putlog "mnet_color_status: toggle $mnet_colors_onoff($name,$chan)"
-	if {$mnet_colors_onoff($name,$chan) == 1} {
-		set mnet_colors_onoff($name,$chan) 0
-		::putils::put_local_msg $chan "::cims:: toggling ${name} _coloroutput_, now disabled for ${chan}"
+	putlog "mnet_color_status: toggle $mnet_colors_onoff($freqname,$chan)"
+	if {$mnet_colors_onoff($freqname,$chan) == 1} {
+		set mnet_colors_onoff($freqname,$chan) 0
+		set output [::cims::sarvar $layout(color_toggle_disabled)]
+		::putils::put_local_msg $chan $output
 	} else {
-		set mnet_colors_onoff($name,$chan) 1
-		::putils::put_local_msg $chan "::cims:: toggling ${name} _coloroutput_, now enabled for ${chan}"
+		set mnet_colors_onoff($freqname,$chan) 1
+		set output [::cims::sarvar $layout(color_toggle_enabled)]
+		::putils::put_local_msg $chan $output 
 	}
-	putlog "mnet_color_status: toggle now $mnet_colors_onoff($name,$chan)"
+	putlog "mnet_color_status: toggle now $mnet_colors_onoff($freqname,$chan)"
 	
 	# color for a channel toggled .. :)