quoteserv.tcl (14187B)
1 blocktnd quoteserv 2 blocktnd qshelp 3 4 source quoteserv.help 5 6 llbind - evnt - alive quoteserv.connect 7 8 proc quoteserv.connect {arg} { 9 puts stdout [format "there are %s quoteserv blocks" [set blocks [tnda get "openconf/[ndcenc quoteserv]/blocks"]]] 10 for {set i 1} {$i < ($blocks + 1)} {incr i} { 11 if {[string tolower [lindex [tnda get [format "openconf/%s/hdr%s" [ndcenc quoteserv] $i]] 0]] != [string tolower $arg]} {continue} 12 after 1000 [list quoteserv.oneintro [tnda get [format "openconf/%s/hdr%s" [ndcenc quoteserv] $i]] [tnda get [format "openconf/%s/n%s" [ndcenc quoteserv] $i]]] 13 } 14 } 15 16 proc quoteserv.find6sid {n s {hunting 0}} { 17 # we're trying to get the sid of the server named $s 18 # if hunting, we're looking for the first splat match 19 set servs [tnda get "servers/$n"] 20 foreach {.k dv} $servs { 21 set k [string toupper [ndadec ${.k}]] 22 # name description uplink sid - we only need two 23 dictassign $dv name sname 24 if {$hunting} { 25 if {[string match [string tolower $s] [string tolower $sname]] == 1} {return $k} 26 } { 27 if {[string tolower $s] == [string tolower $sname]} {return $k} 28 } 29 } 30 return "" 31 } 32 33 proc quoteserv.oneintro {headline block} { 34 set net [lindex $headline 0] 35 set nsock $::sock($net) 36 setctx $net 37 dictassign $block logchan logchan nick nick ident ident host host modes modes realname realname operflags rehashprivs idcommand nspass \ 38 nickserv nickserv nsserv nsserv 39 tnda set "quoteserv/[curctx net]/operflags" $rehashprivs 40 tnda set "quoteserv/[curctx net]/logchan" $logchan 41 #tnda set "quoteserv/[curctx net]/nspass" $nspass 42 setctx $net 43 % sendUid $nick $ident $host $host [set ourid [% getfreeuid]] [expr {($realname == "") ? "* Quote Service *" : $realname}] $modes 44 tnda set "quoteserv/[curctx net]/ourid" $ourid 45 # llbind $nsock pub - ".metadata" [list quoteserv.pmetadata $net] 46 # llbind $nsock pub - ".rehash" [list quoteserv.crehash $net] 47 if {[string length $nspass] != 0 && [string length $nickserv] != 0} { 48 # only works if nettype is ts6! 49 if {[string first [quoteserv.find6sid $net $nsserv] [% nick2uid $nickserv]] == 0} { 50 % privmsg $ourid $nickserv $nspass 51 } { 52 % privmsg $ourid $logchan [gettext quoteserv.impostornickserv $nickserv [nick2uid $nickserv] $nsserv [quoteserv.find6sid $net $nsserv]] 53 } 54 } 55 after 650 % putjoin $ourid $logchan 56 after 700 [list % putmode $ourid $logchan "+ao" [format "%s %s" [% intclient2uid $ourid] [% intclient2uid $ourid]]] 57 # llbind $nsock msg [tnda get "quoteserv/[curctx net]/ourid"] "metadata" [list quoteserv.metadata $net] 58 # llbind $nsock msg [tnda get "quoteserv/[curctx net]/ourid"] "rehash" [list quoteserv.rehash $net] 59 # llbind $nsock pub - "gettext" [list quoteserv.gettext $net] 60 # puts stdout "llbind $nsock msg [tnda get "quoteserv/[curctx net]/ourid"] metadata [list quoteserv.metdata $net]" 61 puts stdout [format "Connected for %s: %s %s %s" $net $nick $ident $host] 62 llbind $nsock pub - "!quote" [list quoteservdo $net] 63 llbind $nsock evnt - privmsg [list qs.pmdo $net] 64 puts stdout $::nd 65 foreach {chan is} [nda get "quoteserv/[curctx net]/regchan"] { 66 puts stdout "to join $chan on [curctx]" 67 if {1!=$is} {continue} 68 quoteservjoin [ndadec $chan] 0 69 # % putjoin [tnda get "quoteserv/[curctx net]/ourid"] [::base64::decode [string map {[ /} $chan]] [nda get "regchan/$chan/ts"] 70 # tnda set "channels/$chan/ts" [nda get "regchan/$chan/$::netname([curctx sock])/ts"] 71 } 72 } 73 74 proc qs.pmdo {n i t m} { 75 set whoarewe [tnda get "intclient/$n/$t"] 76 puts stdout "whoarewe $t on [curctx]" 77 if {$whoarewe != [tnda get "quoteserv/[curctx net]/ourid"]} {return} 78 quoteservdo $n $i 0 $m 79 } 80 81 proc quoteservjoin {chan {setting 1}} { 82 set ndacname [string map {/ [} [::base64::encode [string tolower $chan]]] 83 puts stdout "to join $chan on [curctx]" 84 % putjoin [tnda get "quoteserv/[curctx net]/ourid"] $chan 85 % putmode [tnda get "quoteserv/[curctx net]/ourid"] $chan "+ao" \ 86 [format "%s %s" [% intclient2uid [tnda get "quoteserv/[curctx net]/ourid"]]\ 87 [% intclient2uid [tnda get "quoteserv/[curctx net]/ourid"]]] 88 if {$setting} {nda set "quoteserv/[curctx net]/regchan/$ndacname" 1} 89 } 90 91 proc quoteservpart {chan {who "the script"} {msg isunused}} { 92 set ndacname [string map {/ [} [::base64::encode [string tolower $chan]]] 93 % putpart [tnda get "quoteserv/[curctx net]/ourid"] $chan [gettext quoteserv.left $who] 94 nda set "quoteserv/[curctx net]/regchan/$ndacname" 0 95 nda unset "quoteserv/[curctx net]/regchan/$ndacname" 96 } 97 98 proc quoteservenabled {chan} { 99 set ndacname [string map {/ [} [::base64::encode [string tolower $chan]]] 100 if {[nda get "quoteserv/[curctx net]/regchan/$ndacname"] == 1} {return 1} {return 0} 101 } 102 103 104 if 0 { 105 here's the program with the gettext 106 107 quoteserv.impostornickserv ^C14>^C5>^C4>^C NickServ specified in config file (nick %s, UID %s, intended server %s, whose SID is "%s" - check links if blank) i$ 108 quoteserv.results ^C14>^C3>^C9>^C Quotes: Found results numbered %s 109 quoteserv.noresults ^C14>^C5>^C4>^C Quotes: Found NO results for your search. 110 quoteserv.qheader ^C14>^C2>^C12>^C Quote number %s, by %s: 111 quoteserv.quote ^C14>^C2>^C12>^C %s 112 quoteserv.added ^C14>^C3>^C9>^C Added quote number %s to database. 113 quoteserv.usevalidint ^C14>^C5>^C4>^C Please use a valid integer, without the #. 114 quoteserv.enopriv ^C14>^C5>^C4>^C You do not have the required privileges to execute the command queued (requires flags +%s in ChanServ, or oper permissions %$ 115 quoteserv.removed ^C14>^C3>^C9>^C Removed quote number %s (by %s) from database. 116 quoteserv.removedcontents ^C14>^C2>^C12>^C Removed quote was: %s 117 quoteserv.disabled >>> Sorry, I'm disabled for %s. 118 } 119 120 proc quoteservdo {n from chan m} { 121 setctx $n 122 set ndacname [string map {/ [} [::base64::encode [string tolower $chan]]] 123 if {![quoteservenabled $chan] && $chan != 0} {return} 124 # Q isn't in channel, no need to check quotes 125 set subcmd [lindex [split $m " "] 0] 126 set para [lrange [split $m " "] 1 end] 127 set opara [lrange [split $m " "] 1 end] 128 if {$chan == 0} { 129 set chan [string tolower [lindex $opara 0]] 130 set targ $from 131 set ndacname [string map {/ [} [::base64::encode [string tolower [lindex $opara 0]]]] 132 set para [lrange $para 1 end] 133 if {![quoteservenabled [lindex $opara 0]]} { 134 set disabled 1 135 } { set disabled 0} 136 } else { 137 set targ $chan 138 set disabled 0 139 } 140 puts stdout $subcmd 141 switch -nocase -glob -- $subcmd { 142 "se*" { 143 if {$disabled} { 144 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.disabled $chan] 145 return 146 } 147 set ptn [format "*%s*" [join $para " "]] 148 set qts [quotesearch $chan $ptn] 149 if {[llength $qts] != 0} { 150 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.results #[join $qts ", #"]] 151 } { 152 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.noresults] 153 } 154 } 155 "vi*1*ma*" { 156 if {$disabled} { 157 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.disabled $chan] 158 return 159 } 160 set ptn [format "*%s*" [join $para " "]] 161 set qts [quotesearch $chan $ptn] 162 if {[llength $qts]} { 163 set qtn [lindex $qts 0] 164 set qt [nda get "quoteserv/[curctx net]/quotes/$ndacname/q$qtn"] 165 set qb [nda get "quoteserv/[curctx net]/quotes/$ndacname/u$qtn"] 166 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.qheader $qtn $qb] 167 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.quote $qt] 168 } { 169 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.noresults] 170 } 171 } 172 "ad*" { 173 if {$disabled} { 174 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.disabled $chan] 175 return 176 } 177 set qt [join $para " "] 178 set qtn [expr {([llength [nda get "quoteserv/[curctx net]/quotes/$ndacname"]]/6)+1}] 179 nda set "quoteserv/[curctx net]/quotes/$ndacname/q$qtn" $qt 180 nda set "quoteserv/[curctx net]/quotes/$ndacname/u$qtn" [format "(%s) %s!%s@%s" [tnda get "login/[curctx net]/$from"] [% uid2nick $from] [% uid2ident $from] [% uid2host $from]] 181 nda set "quoteserv/[curctx net]/quotes/$ndacname/a$qtn" [string tolower [tnda get "login/[curctx net]/$from"]] 182 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.added $qtn] 183 } 184 "gad*" { 185 set qt [join $para " "] 186 set qtn [expr {([llength [nda get "quoteserv/[curctx net]/quotes/$ndacname"]]/6)+3}] 187 if {![operHasPrivilege [curctx net] $from [tnda get "quoteserv/[curctx net]/operflags"]]} { 188 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.enopriv [tnda get "quoteserv/[curctx net]/operflags"]] 189 } { 190 nda set "quoteserv/[curctx net]/gquotes/q$qtn" $qt 191 nda set "quoteserv/[curctx net]/gquotes/u$qtn" [format "(%s) %s!%s@%s" [tnda get "login/[curctx net]/$from"] [% uid2nick $from] [% uid2ident $from] [% uid2host $from]] 192 nda set "quoteserv/[curctx net]/gquotes/a$qtn" [tnda get "login/[curctx net]/$from"] 193 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.added $qtn] 194 } 195 } 196 "de*" { 197 if {$disabled} { 198 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.disabled $chan] 199 return 200 } 201 set qtn [lindex $para 0] 202 if {![string is integer $qtn]} { 203 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.usevalidint] 204 } 205 if {[ismodebutnot $chan $from v] || [operHasPrivilege [curctx net] $from [tnda get "quoteserv/[curctx net]/operflags"]] || [string tolower [uid2hand $from]] == [nda get "quoteserv/[curctx net]/quotes/$ndacname/a$qtn"]} { 206 set qt [nda get "quoteserv/[curctx net]/quotes/$ndacname/q$qtn"] 207 set qb [nda get "quoteserv/[curctx net]/quotes/$ndacname/u$qtn"] 208 set qa [nda get "quoteserv/[curctx net]/quotes/$ndacname/a$qtn"] 209 nda unset "quoteserv/[curctx net]/quotes/$ndacname/q$qtn" 210 nda unset "quoteserv/[curctx net]/quotes/$ndacname/u$qtn" 211 nda unset "quoteserv/[curctx net]/quotes/$ndacname/a$qtn" 212 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.removed $qtn $qb] 213 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.removedcontents $qt] 214 } { 215 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.enopriv [tnda get "quoteserv/[curctx net]/operflags"]] 216 } 217 } 218 "gde*" { 219 set qtn [lindex $para 0] 220 if {![string is integer $qtn]} {% privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.usevalidint]} 221 if {[operHasPrivilege [curctx net] $from [tnda get "quoteserv/[curctx net]/operflags"]]} { 222 nda unset "quoteserv/[curctx net]/gquotes/q$qtn" "" 223 nda unset "quoteserv/[curctx net]/gquotes/u$qtn" "" 224 nda unset "quoteserv/[curctx net]/gquotes/a$qtn" "" 225 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ "\[\002Quotes\002\] Blanked quote number #$qtn in database." 226 } { 227 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.enopriv [tnda get "quoteserv/[curctx net]/operflags"]] 228 } 229 } 230 "jo*" { 231 set tochan $chan 232 if {[ismodebutnot $tochan $from v] || [operHasPrivilege [curctx net] $from [tnda get "quoteserv/[curctx net]/operflags"]]} { 233 quoteservjoin $tochan 234 } { 235 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.enopriv [tnda get "quoteserv/[curctx net]/operflags"]] 236 } 237 } 238 "goa*" - "pa*" - "le*" { 239 if {$disabled} { 240 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.disabled $chan] 241 return 242 } 243 set tochan [lindex $para 0] 244 if {[ismodebutnot $tochan $from v] || [operHasPrivilege [curctx net] $from [tnda get "quoteserv/[curctx net]/operflags"]]} { 245 quoteservpart $tochan [format "(%s) %s!%s@%s" [tnda get "login/[curctx net]/$from"] [% uid2nick $from] [% uid2ident $from] [% uid2host $from]] 246 } { 247 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.enopriv [tnda get "quoteserv/[curctx net]/operflags"]] 248 } 249 } 250 "vi*" { 251 if {$disabled} { 252 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.disabled $chan] 253 return 254 } 255 set qtn [lindex $para 0] 256 if {![string is integer $qtn]} {% privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.usevalidint]} 257 set qt [nda get "quoteserv/[curctx net]/quotes/$ndacname/q$qtn"] 258 set qb [nda get "quoteserv/[curctx net]/quotes/$ndacname/u$qtn"] 259 if {$qt != ""} { 260 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.qheader $qtn $qb] 261 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.quote $qt] 262 } { 263 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.noresults] 264 } 265 } 266 "gvi*" { 267 set qtn [lindex $para 0] 268 if {![string is integer $qtn]} {% privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.usevalidint]} 269 set qt [nda get "quoteserv/[curctx net]/gquotes/q$qtn"] 270 set qb [nda get "quoteserv/[curctx net]/gquotes/u$qtn"] 271 if {$qt != ""} { 272 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.qheader $qtn $qb] 273 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.quote $qt] 274 } { 275 % privmsg [tnda get "quoteserv/[curctx net]/ourid"] $targ [gettext quoteserv.noresults] 276 } 277 } 278 "he*" { 279 # set helpfile { ---- Quotes Help ---- 280 #!quote search - Search for quotes matching 281 #!quote view1stmatch - Search for quotes matching and view first matching quote. 282 #!quote view - View quote 283 #!quote add - Add quote. 284 #!quote del - Delete quote. Requires halfops or above. 285 #End of help for Q.} 286 set helplist [tnda get "openconf/[ndcenc qshelp]/n1"] 287 dictassign $helplist main helpfile 288 foreach {helpline} $helpfile { 289 % notice [tnda get "quoteserv/[curctx net]/ourid"] $from $helpline 290 } 291 } 292 } 293 } 294 295 proc requestq {n i m} { 296 } 297 298 proc quotesearch {chan pattern} { 299 set ndacname [string map {/ [} [::base64::encode [string tolower $chan]]] 300 set ret [list] 301 foreach {qnum qvalue} [nda get "quoteserv/[curctx net]/quotes/$ndacname"] { 302 if {[string index $qnum 0] != "q"} {continue} 303 if {[string match -nocase $pattern $qvalue]} {lappend ret [string range $qnum 1 end]} 304 } 305 return $ret 306 }