Permalink
Browse files

Merge pull request #168 from blackwind/master

modtcl: Add support for bind msg/msgm
  • Loading branch information...
2 parents 6bf774d + 1da11b0 commit 2f46afa4ecd5d7f48a4a196447494858a426df43 @SilverLeo SilverLeo committed Apr 18, 2012
Showing with 50 additions and 13 deletions.
  1. +21 −0 modules/modtcl.cpp
  2. +27 −11 modules/modtcl/binds.tcl
  3. +2 −2 modules/modtcl/modtcl.tcl
View
@@ -79,6 +79,7 @@ class CModTcl : public CModule {
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 @@ class CModTcl : public CModule {
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 @@ class CModTcl : public CModule {
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<CChan*>& vChans) {
CString sOldNick = TclEscape(CString(OldNick.GetNick()));
CString sNewNickTmp = TclEscape(sNewNick);
@@ -380,6 +395,12 @@ class CModTcl : public CModule {
return TCL_OK;
}
+ static int tcl_GetClientCount STDVAR {
+ CModTcl *mod = static_cast<CModTcl *>(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<CModTcl *>(cd);
View
@@ -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"
@@ -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]]} {

0 comments on commit 2f46afa

Please sign in to comment.