1
# Copyright (C) 2004-2011 See the AUTHORS file for details.
3
# This program is free software; you can redistribute it and/or modify it
4
# under the terms of the GNU General Public License version 2 as published
5
# by the Free Software Foundation.
7
# Binds module to process incoming messages with ZNC modtcl
9
# Supported bind types: pubm/pub, time, evnt, nick, bot, dcc, kick
10
# evnt: prerehash,rehash,init-server,disconnect-server
13
namespace eval Binds {
16
if {![info exists Binds::List]} {
21
proc Add {type flags cmd {procname ""}} {
22
if {![regexp {^(pub|pubm|nick|mode|raw|bot|time|evnt|dcc|kick)$} $type]} {
23
PutModule "Tcl error: Bind type: $type not supported"
26
# ToDo: Flags check from user info (IsAdmin, etc)
27
if {$procname == ""} {
28
PutModule "Tcl error: Without a proc binds are useless"
31
# ToDo: bind hit counter
32
if {[lsearch $Binds::List "$type $flags [list $cmd] 0 [list $procname]"] == -1} {
33
lappend Binds::List "$type $flags [list $cmd] 0 [list $procname]"
38
proc Del {type flags cmd procname} {
39
if {[set match [lsearch [binds] "$type $flags $cmd 0 $procname"]] != -1 || [set match [lsearch [binds] "$type $flags {${cmd}} 0 $procname"]] != -1} {
40
set Binds::List [lreplace $Binds::List $match $match]
43
error "Tcl error: no such binding"
47
proc ProcessPubm {nick user handle channel text} {
48
# Loop bind list and execute
49
foreach n [binds pub] {
50
if {[string match [lindex $n 2] [lindex [split $text] 0]]} {
51
[lindex $n 4] $nick $user $handle $channel [lrange [join $text] 1 end]
54
foreach {type flags mask hits proc} [join [binds pubm]] {
55
regsub {^%} $mask {*} mask
56
if {[ModuleLoaded crypt]} {regsub {^�} $nick {} nick}
57
if {[string match -nocase $mask "$channel $text"]} {
58
$proc $nick $user $handle $channel $text
64
if {[clock format [clock seconds] -format "%S"] != 0} {return}
65
set time [clock format [clock seconds] -format "%M %H %d %m %Y"]
66
foreach {mi ho da mo ye} $time {}
67
# Loop bind list and execute
68
foreach n [binds time] {
69
if {[string match [lindex $n 2] $time]} {
70
[lindex $n 4] $mi $ho $da $mo $ye
75
proc ProcessEvnt {event} {
76
foreach n [binds evnt] {
77
if {[string match [lindex $n 2] $event]} {
83
set ::botnick [GetCurNick]
84
set ::server [GetServer]
85
set ::server-online [expr [GetServerOnline] / 1000]
95
proc ProcessBot {from-bot cmd text} {
96
foreach n [binds bot] {
97
if {[string match [lindex $n 2] $cmd]} {
98
[lindex $n 4] ${from-bot} $cmd $text
103
proc ProcessNick {nick user handle channel newnick} {
104
if {$nick == $::botnick} {set ::botnick $newnick}
105
foreach n [binds nick] {
106
if {[string match [lindex $n 2] $newnick]} {
107
[lindex $n 4] $nick $user $handle $channel $newnick
112
proc ProcessKick {nick user handle channel target reason} {
113
foreach n [binds kick] {
114
if {[string match [lindex $n 2 0] $channel] && [string match [lindex $n 2 1] $target]} {
115
[lindex $n 4] $nick $user $handle $channel $target $reason
120
proc ProcessDcc {handle idx text} {
122
foreach n [binds dcc] {
123
if {[string match -nocase [lindex $n 2] [string range [lindex $text 0] 1 end]]} {
124
[lindex $n 4] $handle $idx [lrange $text 1 end]
129
PutModule "Error, dcc trigger '[string range [lindex $text 0] 1 end]' doesnt exist"
134
# Provide aliases according to eggdrop specs
135
proc ::bind {type flags cmd {procname ""}} {Binds::Add $type $flags $cmd $procname}
136
proc ::unbind {type flags cmd procname} {Binds::Del $type $flags $cmd $procname}
137
proc ::binds {{type ""}} {if {$type != ""} {set type "$type "};return [lsearch -all -inline $Binds::List "$type*"]}
138
proc ::bindlist {{type ""}} {foreach bind $Binds::List {PutModule "$bind"}}
140
PutModule "modtcl script loaded: Binds v0.1"