Explorar o código

more plugin procedures all over the place

Paul Klumpp %!s(int64=12) %!d(string=hai) anos
pai
achega
8ffbac8514
Modificáronse 1 ficheiros con 192 adicións e 113 borrados
  1. 192 113
      cims.tcl

+ 192 - 113
cims.tcl

@@ -55,6 +55,7 @@ namespace eval ::cims {
   }
 
   ############ XML CONFIGURATION PARSING FOLLOWS!! WTF! :) #########
+	variable layout
   variable mnet_networks
   variable mnet_bots
   variable mnet_channels 
@@ -82,8 +83,10 @@ namespace eval ::cims {
   variable startFrequencyInstance
   global botnet-nick
 
-
-
+	set layout(local_reply) "::cims:: Message sent to @@chan_cnt@@ channels, reaching @@user_cnt@@ unique users."
+	set layout(local_reply) "::cims:: Message sent to @@chan_cnt@@ channels, reaching @@user_cnt@@ unique users."
+	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@@"
 
   # list
   set mnet_local_config ""
@@ -421,12 +424,10 @@ proc ::cims::xmlDefaultCmd {data} {
 
 namespace eval ::cims {
   ## some internal variables for messaging and stuff :) not your business after all.
-  set mnet(version) "cims!1.014unique-users"
+  set mnet(version) "cims!1.15many_plugins"
 
   set mnet_max_history 8
 
-  set mnet(reached) "0"
-  set mnet(reached_channels) "0"
   set mnet_reached_users(dummy) "0"
   set mnet_reached_chans(dummy) "0"
   ##
@@ -473,6 +474,10 @@ proc ::cims::put_local_netmessage {network name chan rec_nickname rec_channel re
 	# validating incoming vars..
 	set chan [::cims::proper_channelname $chan]
 
+	# unescaping vars .. this is an output procedure! remember?
+	set rec_nickname [join $rec_nickname]
+	set rec_channel [join $rec_channel]
+	set rec_text [join $rec_text]
 	
 	if {$mnet_colors($network) == "none"} {
 	# if no color id was found...
@@ -599,7 +604,7 @@ proc ::cims::put_bot {botnetnick data} {
 		putlog "::cims:: put_bot: + a message delivered to $botnetnick."
 		
 		if {[string length $data] > 335} {
-			::putils::filelog "scripts/cims/cims.log" "alldata put_bot to $botnetnick: $data"
+			#::putils::filelog "scripts/cims/cims.log" "alldata put_bot to $botnetnick: $data"
 			::putils::put_bot $botnetnick $data
 		} else {
 			putbot $botnetnick $data
@@ -683,26 +688,26 @@ proc ::cims::receive_message {rec_botnick cmd rec_data} {
   variable mnet_bots
   variable mnet_histories
   global botnet-nick
-	
+
 	#putlog "rec_data string: '$rec_data'"
 
 	# escape it to be a list FIRST.. and for output later, let the list JOIN together to a string again!
-	set rec_data [split $rec_data]
-	#putlog "rec_data list: '$rec_data'"
-	
+	#set rec_data [split $rec_data]
+	putlog "rec_data list: '$rec_data'"
+
 	set tmp_network [join [lindex $rec_data 0]]
 	set tmp_name [join [lindex $rec_data 1]]
 	#putlog "tmp_net: '$tmp_network'"
 	#putlog "tmp_nam: '$tmp_name'"
-	
+
 	set network [::putils::kill_spaces $tmp_network]
 	#putlog  "network: '$network'"
 	
 	set name  [::putils::kill_spaces $tmp_name]
 	#putlog  "name: '$name'"
-	
-	set rec_nickname [::putils::kill_spaces [join [lindex $rec_data 2]]]
-	#set rec_nickname [::putils::kill_spaces clean_txt [join [lrange [split $rec_data] 4 end]]]
+
+	set rec_nickname [join [lindex $rec_data 2]]
+	#putlog "rec_nickname: '$rec_nickname'"
 
 	set rec_channel  [::putils::kill_spaces [join [lindex $rec_data 3]]]
 
@@ -710,7 +715,7 @@ proc ::cims::receive_message {rec_botnick cmd rec_data} {
 
 	set rec_text [join [lrange $rec_data 4 end]]
 	#putlog "rec_text: '$rec_text'"
-	
+
 	set allowed [::cims::allowed_netbot $network ${rec_botnick}]
 	if {$allowed == 0} {
 		return 0
@@ -727,6 +732,12 @@ proc ::cims::receive_message {rec_botnick cmd rec_data} {
 			
 	::cims::history_queue $network,$name $rec_nickname $rec_channel $rec_text
 
+	# plugin... if you want it to do other stuff with a received netbot message as well.
+	if {[info procs ::cims::message_from_netbot_to_plugin] == "::cims::message_from_netbot_to_plugin"} {
+		::cims::message_from_netbot_to_plugin $rec_botnick $network $name $rec_channel $rec_nickname $rec_text
+	}
+
+	# send message to all local channels, and count stats:
 	foreach {chan} $mnet_channels($network,$proper_botnick) {
 	
 
@@ -760,7 +771,7 @@ proc ::cims::receive_message {rec_botnick cmd rec_data} {
 #	}
 
 
-	putlog "::cims:: unique_userlist is [llength $unique_userlist] long"
+	#putlog "::cims:: unique_userlist is [llength $unique_userlist] long"
 	
 	# it is an eggdrop limitation/bug that it is not allowed to send large botnet messages via putbot. 
   # it truncates our payload after 388 chars. in fact the payload is 401 chars.
@@ -774,7 +785,7 @@ proc ::cims::receive_message {rec_botnick cmd rec_data} {
   #...
   #}
 
-  # ANSWER! SEND!
+  # ANSWER! SEND THE REPLY of counts to the originating bot.
 	::cims::put_bot $rec_botnick "mnet_answer $network $name $rec_channel $users $count_channels $unique_userlist"
 	return 0
 }
@@ -937,7 +948,7 @@ proc ::cims::allowed_channel {network name prefix nick mask chan} {
 # checks if the user is allowed, returns 1 if OK.
 # checks against the xml config of the banned ones.
 proc ::cims::allowed_user {network name prefix nick mask chan} {
-  variable mnet 
+	variable layout
   variable mnet_channels 
   variable mnet_bots 
   variable mnet_bans 
@@ -966,7 +977,9 @@ proc ::cims::allowed_user {network name prefix nick mask chan} {
 		}
 		if {$found == 1} {
 			# tell the user his ban. :)
-			::putils::put_nick $nick "::cims:: Not allowed to send messages. Reason: $reason"
+			set output [::cims::sarvar $layout(user_banned)]
+			::putils::put_nick $nick $output
+			
 			return 0
 		}
 	}
@@ -1013,13 +1026,39 @@ proc ::cims::allowed_netbot {network netbot} {
 	return 1
 }
 
+# enter variables into placeholders of that pre-defined string "layout(local_reply)"
+proc ::cims::sarvar {layout_string} {
+
+	set the_list [regexp -inline -all {@@(.+?)@@} $layout_string]
+	foreach {thing thong} $the_list {
+		#putlog "thing: $thing"
+		#putlog "thong: $thong"
+		
+		# delete upvar link, if it existed.
+		if {[info exists replacer]} {
+			unset replacer
+		}
+		# find the variable that is available in the previous context and use this now..
+		upvar $thong replacer
 
+		if {[info exists replacer]} {
+			if {"$replacer" != ""} {
+				#putlog "hum: $replacer"
+				regsub -all "$thing" $layout_string "$replacer" layout_string
+			}
+		}
+	}
+	return $layout_string
 
-proc ::cims::reply_timeout {name chan} {
-  variable mnet 
+}
+
+proc ::cims::timeout_reply_from_local_for_netbots {name chan} {
+  variable mnet
   variable mnet_reached_users 
 	variable mnet_reached_userlist
   variable mnet_reached_chans
+	variable layout
+
 	global botnet-nick
 	set proper_botnick [::cims::proper_botnick ${botnet-nick}]
 	# clean $name and $chan
@@ -1034,7 +1073,7 @@ proc ::cims::reply_timeout {name chan} {
 	set chan_cnt $mnet_reached_chans($name,$chan)
 
 	
-	# inzwischen drfte auch die antwort gekommen sein.. also jetzt mnet_reached_* auswerten nach timeout..
+	# inzwischen dürfte auch die antwort gekommen sein.. also jetzt mnet_reached_* auswerten nach timeout..
 	
 	# make stats channel-dependent 
 	#putlog "::cims:: * userlist is finally: $userlist "
@@ -1042,7 +1081,16 @@ proc ::cims::reply_timeout {name chan} {
 	
 	# Give me some reply.
 	::putils::filelog "scripts/cims/${proper_botnick}.log" "$name from $chan reached $user_cnt users: $userlist"
-	::putils::put_local_msg ${chan} "::cims:: Message sent to $chan_cnt channels, reaching $user_cnt unique users."
+
+	# enter variables into placeholders of that pre-defined string "layout(local_reply)"
+	set output [::cims::sarvar $layout(local_reply)]
+
+	# plugin before the final answer... if you want it to do other stuff as well.
+	if {[info procs ::cims::timeout_reply_from_local_for_netbots_plugin] == "::cims::timeout_reply_from_local_for_netbots_plugin"} {
+		::cims::timeout_reply_from_local_for_netbots_plugin $name $chan
+	}
+
+	::putils::put_local_msg ${chan} $output
 }
 
 
@@ -1466,21 +1514,120 @@ proc ::cims::check_spam_protection {prefix chan} {
 	return 0
 }		
 
+proc ::cims::message_to_own_channels {network freqname chan nick text} {
+  variable mnet_channels
+  variable mnet_freqs_onoff 
+  variable mnet_reached_users 
+  variable mnet_reached_userlist
+  variable mnet_reached_chans
+
+	global botnet-nick
+
+	set proper_botnick [::cims::proper_botnick ${botnet-nick}]
+	#	putlog "{botnet-nick} huar: $proper_botnick"
+
+	foreach _ownchan $mnet_channels($network,$proper_botnick) {
+			if {$_ownchan == $chan} {
+			
+			} else { 
+				# if not own channel! ...
+
+				if {[::cims::botonchannel $_ownchan] == "1"} {
+					
+					putlog "::cims:: = i am on $_ownchan"
 
-proc ::cims::messaging_public {nick mask hand chan text} {
+					# second enable/disable check
+					if {$mnet_freqs_onoff($freqname,$_ownchan) == 1} {
+					
+						# userstats local
+						set mnet_reached_users($freqname,$chan) [::cims::chanstat_users $_ownchan $mnet_reached_users($freqname,$chan)]
+						set mnet_reached_userlist($freqname,$chan) [::cims::chanstat_userlist $_ownchan $mnet_reached_userlist($freqname,$chan)]
+						
+						putlog "::cims:: * Localcounting up $_ownchan users: $mnet_reached_users($freqname,$chan)"
+	
+						# channel count local
+						incr mnet_reached_chans($freqname,$chan)
+	
+						::cims::put_local_netmessage $network $freqname $_ownchan $nick $chan $text
+					} else {
+						putlog "::cims:: + $_ownchan has disabled $freqname output"
+					}
+
+				} else {
+
+					putlog "::cims:: + Can't send a local message to '$_ownchan' since I am not there."
+
+				}
+			}
+		}
+
+}
+
+proc ::cims::message_to_netbots {network freqname chan nick text} {
+  variable mnet_bots 
+
+  global botnet-nick
+
+	set proper_botnick [::cims::proper_botnick ${botnet-nick}]
+	#	putlog "{botnet-nick} huar: $proper_botnick"
+
+	foreach _botnick $mnet_bots($network) {
+		if {$_botnick == $proper_botnick} {
+	
+		} else { # if not myself!
+
+			putlog "::cims:: send: + I am about to send a message to $_botnick for $network: $freqname: $text"
+			# safe put_bot function..
+			set data "mnet_receive"
+			lappend data $network $freqname $nick $chan $text
+			putlog "data: $data"
+			::cims::put_bot $_botnick $data
+			
+		}
+	}
+}
+
+proc ::cims::message_from_local {network freqname source nick text} {
+  variable mnet_reached_users 
+  variable mnet_reached_userlist
+  variable mnet_reached_chans
+
+	# reset stats .. because he is just freshly sending
+	set mnet_reached_users($freqname,$source) "0"
+	set mnet_reached_userlist($freqname,$source) ""
+	set mnet_reached_chans($freqname,$source) "0"
+
+	::cims::history_queue $network,$freqname $nick $source $text
+	
+	# send them first, we await a reply!
+
+	# single sends TO ALL REMOTE BOTS with their remote CHANNELS...
+	# let's see which mode for sending is used...
+	::cims::message_to_netbots $network $freqname $source $nick $text
+	
+	# SEND TO ALL OWN CHANNELS...
+	# send to all own channels, except to the channel the message originating from:
+	::cims::message_to_own_channels $network $freqname $source $nick $text
+
+	# plugin sending... if you want it to do other stuff as well.
+	if {[info procs ::cims::message_from_local_plugin] == "::cims::message_from_local_plugin"} {
+		::cims::message_from_local_plugin $network $freqname $source $nick $text
+	}
+		
+	# notice: better would be to go into the "reply" when all known bots already answered..
+	# then, if a bot is missing, but it was a known bot, just use a timeout with about 5-10 seconds..
+	# if the bot still didn't answer, then just go into "reply".
+}
+
+proc ::cims::messaging_public_from_bind {nick mask hand chan text} {
 # proc triggered by specified $prefix and calling the following (internal) one
   variable mnet 
-  variable mnet_channels 
-  variable mnet_bots 
   variable mnet_networks_by_prefix 
   variable mnet_colors
   variable mnet_freqs 
-  variable mnet_freqs_onoff 
   variable mnet_delay
   variable mnet_histories
-  variable mnet_reached_users 
-  variable mnet_reached_userlist
-  variable mnet_reached_chans
+
 
   global botnet-nick lastbind
 	
@@ -1492,20 +1639,20 @@ proc ::cims::messaging_public {nick mask hand chan text} {
 	# $mnet_networks_by_prefix($prefix) is already a list! Don't split it! But work with lindex and lrange on it! later: JOIN it to a string.
 	set my_network_entry $mnet_networks_by_prefix($prefix)
 
-	set network	[join [lindex $my_network_entry 0]]
-	set name	[join [lindex $my_network_entry 1]]
-	set help	[join [lindex $my_network_entry 2]]
-	set desc	[join [lindex $my_network_entry 3]]
-	set delay	[join [lindex $my_network_entry 4]]
+	set network		[join [lindex $my_network_entry 0]]
+	set freqname	[join [lindex $my_network_entry 1]]
+	set help			[join [lindex $my_network_entry 2]]
+	set desc			[join [lindex $my_network_entry 3]]
+	set delay			[join [lindex $my_network_entry 4]]
 
-	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.
 
 	# is user banned from sending??
-	set user_allowed [::cims::allowed_user $network $name $prefix $nick $mask $chan]
+	set user_allowed [::cims::allowed_user $network $freqname $prefix $nick $mask $chan]
 	if {$user_allowed == 0} {
 		return 0
 	}
@@ -1532,7 +1679,7 @@ proc ::cims::messaging_public {nick mask hand chan text} {
 		if {$secsleft > 0} { 
 			putlog "::cims:: The timer of $prefix for $chan is still running. The guy has to wait ($secsleft/$delay) more seconds. I tell him."
 			::putils::put_nick $nick "Sorry $nick, usage of $prefix only every $delay seconds. $secsleft seconds for $chan remaining."
-			# now BREAK "messaging_public".
+			# now BREAK "messaging_public_from_bind".
 			# NO break.. for debug :)) arf
 			return 0
 		}
@@ -1540,81 +1687,13 @@ proc ::cims::messaging_public {nick mask hand chan text} {
 		# set a timer-id to check for again, if it's allowed or not .. delay
 		set mnet_delay($prefix,$chan) [utimer $delay ::cims::dummy]
 		### end spamprotection
-		
-		## HE IS SENDING NOW!
-		
-		set mnet(reached) "0"
-		set mnet(reached_channels) "0"
-
-		# reset stats .. because he is just freshly sending
-		set mnet_reached_users($name,$chan) "0"
-		set mnet_reached_userlist($name,$chan) ""
-		set mnet_reached_chans($name,$chan) "0"
 
-		::cims::history_queue $network,$name $nick $chan $text
-		
-		# send them first, we await a reply!
-
-		set proper_botnick [::cims::proper_botnick ${botnet-nick}]
-#		putlog "{botnet-nick} huar: $proper_botnick"
-
-		# single sends TO ALL REMOTE BOTS with their remote CHANNELS...
-		# let's see which mode for sending is used...
-		foreach _botnick $mnet_bots($network) {
-			if {$_botnick == $proper_botnick} {
-		
-			} else { # if not myself!
-
-				putlog "::cims:: send: + I am about to send a message to $_botnick for $network: $name: $text"
-				# safe put_bot function..
-				::cims::put_bot $_botnick "mnet_receive $network $name $nick $chan $text"
-				
-			}
-		}
-
-		
-		# SEND TO ALL OWN CHANNELS...
-		# send to all own channels, except to the channel the message originating from:
-		foreach _ownchan $mnet_channels($network,$proper_botnick) {
-			if {$_ownchan == $chan} {
-			
-			} else { # if not own channel!
-
-				if {[::cims::botonchannel $_ownchan] == "1"} {
-					
-					putlog "::cims:: = i am on $_ownchan"
-
-					# second enable/disable check
-					if {$mnet_freqs_onoff($name,$_ownchan) == 1} {
-					
-						# userstats local
-						set mnet_reached_users($name,$chan) [::cims::chanstat_users $_ownchan $mnet_reached_users($name,$chan)]
-						set mnet_reached_userlist($name,$chan) [::cims::chanstat_userlist $_ownchan $mnet_reached_userlist($name,$chan)]
-						
-						putlog "::cims:: * Localcounting up $_ownchan users: $mnet_reached_users($name,$chan)"
-	
-						# channel count local
-						incr mnet_reached_chans($name,$chan)
-	
-						::cims::put_local_netmessage $network $name $_ownchan $nick $chan $text
-					} else {
-						putlog "::cims:: + $_ownchan has disabled $name output"
-					}
-
-				} else {
-
-					putlog "::cims:: + Can't send a local message to '$_ownchan' since I am not there."
+		## HE IS SENDING NOW!
+		::cims::message_from_local $network $freqname $chan $nick $text
 
-				}
-			}
-		}
-	
-		# wait here some more! (10 seconds with utimer)
-		utimer 5 "::cims::reply_timeout $name $chan"
+		# wait here some more! (10 seconds with utimer) - to send out a reply to the channel
+		utimer 10 "::cims::timeout_reply_from_local_for_netbots $freqname $chan"
 
-		# notice: better would be to go into the "reply" when all known bots already answered..
-		# then, if a bot is missing, but it was a known bot, just use a timeout with about 5-10 seconds..
-		# if the bot still didn't answer, then just go into "reply".
 	
 	}
 
@@ -1647,7 +1726,7 @@ proc ::cims::binds {} {
 		foreach {network name prefix help desc msgdelay} $mnet_freqs($network) {
 		
 			putlog "network: $network"
-			putlog "name: $name"
+			putlog "freqname: $name"
 			putlog "prefix: $prefix"
 			putlog "help: $help"
 			putlog "desc: $desc"
@@ -1677,7 +1756,7 @@ proc ::cims::binds {} {
 			}
 				
 			
-			bind pub - ${prefix} 		::cims::messaging_public
+			bind pub - ${prefix} 		::cims::messaging_public_from_bind
 			# $network $name $prefix $help $desc
 			bind pub - ${prefix}_enable	::cims::enable_frequency
 			bind pub - ${prefix}_disable	::cims::disable_frequency
@@ -1704,7 +1783,7 @@ proc ::cims::binds {} {
 	
 	}
 }
-bind bot - mnet_receive		::cims::receive_message	
+bind bot - mnet_receive		::cims::receive_message
 bind bot - mnet_answer		::cims::receive_answer
 bind dcc m cims_reload		::cims::dcc_configload