diff --git a/modules/modtcl.cpp b/modules/modtcl.cpp index 9b3d913c..3ef27615 100644 --- a/modules/modtcl.cpp +++ b/modules/modtcl.cpp @@ -79,6 +79,7 @@ public: interp = Tcl_CreateInterp(); Tcl_Init(interp); Tcl_CreateCommand(interp, "Binds::ProcessPubm", tcl_Bind, this, NULL); + Tcl_CreateCommand(interp, "Binds::ProcessMsgm", tcl_Bind, this, NULL); Tcl_CreateCommand(interp, "Binds::ProcessTime", tcl_Bind, this, NULL); Tcl_CreateCommand(interp, "Binds::ProcessEvnt", tcl_Bind, this, NULL); Tcl_CreateCommand(interp, "Binds::ProcessNick", tcl_Bind, this, NULL); @@ -100,6 +101,7 @@ public: Tcl_CreateCommand(interp, "GetServer", tcl_GetServer, this, NULL); Tcl_CreateCommand(interp, "GetServerOnline", tcl_GetServerOnline, this, NULL); Tcl_CreateCommand(interp, "GetModules", tcl_GetModules, this, NULL); + Tcl_CreateCommand(interp, "GetClientCount", tcl_GetClientCount, this, NULL); Tcl_CreateCommand(interp, "exit", tcl_exit, this, NULL); @@ -186,6 +188,19 @@ public: return CONTINUE; } + virtual EModRet OnPrivMsg(CNick& Nick, CString& sMessage) { + CString sMes = TclEscape(sMessage); + CString sNick = TclEscape(CString(Nick.GetNick())); + CString sHost = TclEscape(CString(Nick.GetIdent() + "@" + Nick.GetHost())); + + CString sCommand = "Binds::ProcessMsgm {" + sNick + "} {" + sHost + "} - {" + sMes + "}"; + i = Tcl_Eval(interp, sCommand.c_str()); + if (i != TCL_OK) { + PutModule(Tcl_GetStringResult(interp)); + } + return CONTINUE; + } + virtual void OnNick(const CNick& OldNick, const CString& sNewNick, const vector& vChans) { CString sOldNick = TclEscape(CString(OldNick.GetNick())); CString sNewNickTmp = TclEscape(sNewNick); @@ -380,6 +395,12 @@ private: return TCL_OK; } + static int tcl_GetClientCount STDVAR { + CModTcl *mod = static_cast(cd); + Tcl_SetResult(irp, (char *)CString(mod->m_pNetwork->GetClients().size()).c_str(), TCL_VOLATILE); + return TCL_OK; + } + static int tcl_PutIRC STDVAR { CString sMsg; CModTcl *mod = static_cast(cd); diff --git a/modules/modtcl/binds.tcl b/modules/modtcl/binds.tcl index faa688d9..f7cc6aaa 100644 --- a/modules/modtcl/binds.tcl +++ b/modules/modtcl/binds.tcl @@ -6,7 +6,7 @@ # # Binds module to process incoming messages with ZNC modtcl # -# Supported bind types: pubm/pub, time, evnt, nick, bot, dcc, kick +# Supported bind types: bot, dcc, evnt, kick, msg, msgm, nick, pub, pubm, time # evnt: prerehash,rehash,init-server,disconnect-server # @@ -19,15 +19,11 @@ namespace eval Binds { # procs proc Add {type flags cmd {procname ""}} { - if {![regexp {^(pub|pubm|nick|mode|raw|bot|time|evnt|dcc|kick)$} $type]} { + if {![regexp {^(bot|dcc|evnt|kick|msg|msgm|nick|pub|pubm|time)$} $type]} { PutModule "Tcl error: Bind type: $type not supported" return } # ToDo: Flags check from user info (IsAdmin, etc) - if {$procname == ""} { - PutModule "Tcl error: Without a proc binds are useless" - return - } # ToDo: bind hit counter if {[lsearch $Binds::List "$type $flags [list $cmd] 0 [list $procname]"] == -1} { lappend Binds::List "$type $flags [list $cmd] 0 [list $procname]" @@ -53,13 +49,29 @@ namespace eval Binds { } foreach {type flags mask hits proc} [join [binds pubm]] { regsub {^%} $mask {*} mask - if {[ModuleLoaded crypt]} {regsub {^¤} $nick {} nick} + if {[ModuleLoaded crypt]} {regsub {^\244} $nick {} nick} if {[string match -nocase $mask "$channel $text"]} { $proc $nick $user $handle $channel $text } } } + proc ProcessMsgm {nick user handle text} { + # Loop bind list and execute + foreach n [binds msg] { + if {[string match [lindex $n 2] [lindex [split $text] 0]]} { + [lindex $n 4] $nick $user $handle [lrange [join $text] 1 end] + } + } + foreach {type flags mask hits proc} [join [binds msgm]] { + regsub {^%} $mask {*} mask + if {[ModuleLoaded crypt]} {regsub {^\244} $nick {} nick} + if {[string match -nocase $mask "$text"]} { + $proc $nick $user $handle $text + } + } + } + proc ProcessTime {} { if {[clock format [clock seconds] -format "%S"] != 0} {return} set time [clock format [clock seconds] -format "%M %H %d %m %Y"] @@ -111,8 +123,12 @@ namespace eval Binds { proc ProcessKick {nick user handle channel target reason} { foreach n [binds kick] { - if {[string match [lindex $n 2 0] $channel] && [string match [lindex $n 2 1] $target]} { - [lindex $n 4] $nick $user $handle $channel $target $reason + if {[string match [lindex $n 2 0] $channel]} { + if {[llength [lindex $n 2]] <= 1 || [string match [lindex $n 2 1] $target]} { + if {[llength [lindex $n 2]] <= 2 || [string match [lindex $n 2 2] $reason]} { + [lindex $n 4] $nick $user $handle $channel $target $reason + } + } } } } @@ -132,9 +148,9 @@ namespace eval Binds { } # Provide aliases according to eggdrop specs -proc ::bind {type flags cmd {procname ""}} {Binds::Add $type $flags $cmd $procname} +proc ::bind {type flags cmd procname} {Binds::Add $type $flags $cmd $procname} proc ::unbind {type flags cmd procname} {Binds::Del $type $flags $cmd $procname} proc ::binds {{type ""}} {if {$type != ""} {set type "$type "};return [lsearch -all -inline $Binds::List "$type*"]} proc ::bindlist {{type ""}} {foreach bind $Binds::List {PutModule "$bind"}} -PutModule "modtcl script loaded: Binds v0.1" +PutModule "modtcl script loaded: Binds v0.2" diff --git a/modules/modtcl/modtcl.tcl b/modules/modtcl/modtcl.tcl index 254e43cb..fa18bdb9 100644 --- a/modules/modtcl/modtcl.tcl +++ b/modules/modtcl/modtcl.tcl @@ -32,7 +32,7 @@ proc puthelp {text {option ""}} { if {[regexp -nocase {^(?:privmsg|notice) (\S+) :(.*)} $text . target line]} { if {$target == "*modtcl"} {PutModule $line; return} if {$target == "*status"} {PutStatus $line; return} - if {[botonchan $target]} {PutUser ":$::botnick![getchanhost $::botnick] $text"} + if {[string index $target 0] != "#" || [botonchan $target]} {PutUser ":$::botnick![getchanhost $::botnick] $text"} } PutIRC $text } @@ -83,7 +83,7 @@ proc botisvoice {{channel ""}} {return [isvoice $::botnick $channel]} proc PermCheck {nick perm channel} { if {$channel == ""} {set channel [channels]} - if {[ModuleLoaded crypt]} {regsub {^¤} $nick {} nick} + if {[ModuleLoaded crypt]} {regsub {^\244} $nick {} nick} foreach c $channel { foreach u [GetChannelUsers $c] { if {[string match -nocase $nick [lindex $u 0]] && [string match *$perm* [lindex $u 3]]} {