Mercurial > hg > egg-tcls
comparison tj.tcl @ 625:5eca657134a5
tj: Implement command to set/reset default ID for TJs.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 11 Feb 2021 10:32:51 +0200 |
parents | e7c88d4e917c |
children | 319c2e73860c |
comparison
equal
deleted
inserted
replaced
624:e7c88d4e917c | 625:5eca657134a5 |
---|---|
86 return 0 | 86 return 0 |
87 } | 87 } |
88 } | 88 } |
89 | 89 |
90 | 90 |
91 # ------------------------------------------------------------------------ | |
91 proc tj_get_id {rstr rindex rid} { | 92 proc tj_get_id {rstr rindex rid} { |
92 global tj_default_id | |
93 upvar $rindex uindex | 93 upvar $rindex uindex |
94 upvar $rid uid | 94 upvar $rid uid |
95 | 95 |
96 if {[string index $rstr 0] == "#"} { | 96 if {[string index $rstr 0] == "#"} { |
97 set uid [string range $rstr 1 end] | 97 set uid [string range $rstr 1 end] |
98 incr uindex | 98 incr uindex |
99 return 1 | 99 return 1 |
100 } else { | 100 } else { |
101 set uid $tj_default_id | |
102 return 0 | 101 return 0 |
102 } | |
103 } | |
104 | |
105 | |
106 proc tj_get_default_id {uhand} { | |
107 global tj_default_id | |
108 | |
109 set uid [getuser $uhand XTRA "tj_default_id"] | |
110 if {$uid == "" || $uid == "{}" || $uid == "*"} { | |
111 return $tj_default_id | |
112 } else { | |
113 return $uid | |
103 } | 114 } |
104 } | 115 } |
105 | 116 |
106 | 117 |
107 proc tj_ctime {ustamp} { | 118 proc tj_ctime {ustamp} { |
165 # return [utl_str_map_values [tj_qm $ufmt] [list ]] | 176 # return [utl_str_map_values [tj_qm $ufmt] [list ]] |
166 return [tj_get_tj_str $useconds] | 177 return [tj_get_tj_str $useconds] |
167 } | 178 } |
168 | 179 |
169 | 180 |
181 # ------------------------------------------------------------------------ | |
170 proc tj_display_tjs {upublic unick uchan uname uid uclock} { | 182 proc tj_display_tjs {upublic unick uchan uname uid uclock} { |
171 | 183 |
172 set nresults 0 | 184 set nresults 0 |
173 set usql "SELECT * FROM tj WHERE uuser='[utl_escape $uname]' AND utype=0 AND uid LIKE '[utl_escape $uid]'" | 185 set usql "SELECT * FROM tj WHERE uuser='[utl_escape $uname]' AND utype=0 AND uid LIKE '[utl_escape $uid]'" |
174 tj_dbh eval $usql { | 186 tj_dbh eval $usql { |
228 # Check for #id prefix | 240 # Check for #id prefix |
229 if {[tj_get_id $rarg rindex uid]} { | 241 if {[tj_get_id $rarg rindex uid]} { |
230 set rdesc "" | 242 set rdesc "" |
231 } else { | 243 } else { |
232 set rdesc $tj_default_desc | 244 set rdesc $tj_default_desc |
245 set uid [tj_get_default_id $uhand] | |
233 } | 246 } |
234 | 247 |
235 if {![utl_arg_get $rarglist rindex rarg 1]} { | 248 if {![utl_arg_get $rarglist rindex rarg 1]} { |
236 tj_msg $upublic $unick $uchan "help_set" | 249 tj_msg $upublic $unick $uchan "help_set" |
237 return 1 | 250 return 1 |
390 } | 403 } |
391 } else { | 404 } else { |
392 set uname $uhand | 405 set uname $uhand |
393 } | 406 } |
394 | 407 |
395 | |
396 set usql "SELECT COUNT(*) FROM tj WHERE uuser='[utl_escape $uname]'" | 408 set usql "SELECT COUNT(*) FROM tj WHERE uuser='[utl_escape $uname]'" |
397 if {[catch {set nitems [tj_dbh onecolumn $usql]} uerrmsg]} { | 409 if {[catch {set nitems [tj_dbh onecolumn $usql]} uerrmsg]} { |
398 tj_msg $upublic $unick $uchan "err_sql" [list $uerrmsg] | 410 tj_msg $upublic $unick $uchan "err_sql" [list $uerrmsg] |
399 tj_log "$uerrmsg on SQL:\n$usql" | 411 tj_log "$uerrmsg on SQL:\n$usql" |
400 return 1 | 412 return 1 |
432 tj_log "$uerrmsg on SQL:\n$usql" | 444 tj_log "$uerrmsg on SQL:\n$usql" |
433 return 1 | 445 return 1 |
434 } | 446 } |
435 | 447 |
436 tj_msg $upublic $unick $uchan "items_deleted" [list $uid $nitems] | 448 tj_msg $upublic $unick $uchan "items_deleted" [list $uid $nitems] |
449 | |
450 } elseif {[tj_cmd_match "default" $rcmd]} { | |
451 # !tj default #<id> | |
452 # Check for #id prefix | |
453 if {![utl_arg_get $rarglist rindex rarg 0] || ![tj_get_id $rarg rindex uid]} { | |
454 tj_msg $upublic $unick $uchan "help_default" | |
455 return 1 | |
456 } | |
457 | |
458 if {$uid == "" || $uid == "{}" || $uid == "*"} { | |
459 set uid $tj_default_id | |
460 } else { | |
461 set usql "SELECT COUNT(*) FROM tj WHERE uuser='[utl_escape $uhand]' AND uid='[utl_escape $uid]'" | |
462 if {[catch {set nids [tj_dbh onecolumn $usql]} uerrmsg]} { | |
463 tj_msg $upublic $unick $uchan "err_sql" [list $uerrmsg] | |
464 tj_log "$uerrmsg on SQL:\n$usql" | |
465 return 1 | |
466 } | |
467 | |
468 if {$nids < 1} { | |
469 tj_msg $upublic $unick $uchan "err_no_such_id" [list $uid] | |
470 return 1 | |
471 } | |
472 } | |
473 | |
474 setuser $uhand XTRA "tj_default_id" $uid | |
475 | |
476 tj_msg $upublic $unick $uchan "default_set" [list $uid] | |
477 | |
437 } elseif {[tj_cmd_match "show" $rcmd]} { | 478 } elseif {[tj_cmd_match "show" $rcmd]} { |
438 # !tj show [#<id>] <name> | 479 # !tj show [#<id>] <name> |
439 # Check for #id prefix | 480 # Check for #id prefix |
440 if {[utl_arg_get $rarglist rindex rarg 0]} { | 481 if {[utl_arg_get $rarglist rindex rarg 0]} { |
441 tj_get_id $rarg rindex uid | 482 set notdefault [tj_get_id $rarg rindex uid] |
442 } | 483 } |
443 | 484 |
444 if {![utl_arg_get $rarglist rindex rarg 0]} { | 485 if {![utl_arg_get $rarglist rindex rarg 0]} { |
445 tj_msg $upublic $unick $uchan "help_show" | 486 tj_msg $upublic $unick $uchan "help_show" |
446 return 1 | 487 return 1 |
450 if {$uname == ""} { | 491 if {$uname == ""} { |
451 tj_msg $upublic $unick $uchan "err_unknown_user" [list $rcmd] | 492 tj_msg $upublic $unick $uchan "err_unknown_user" [list $rcmd] |
452 return 1 | 493 return 1 |
453 } | 494 } |
454 | 495 |
496 if {!$notdefault} { | |
497 set uid [tj_get_default_id $uname] | |
498 } | |
499 | |
455 tj_display_tjs $upublic $unick $uchan $uname $uid $uclock | 500 tj_display_tjs $upublic $unick $uchan $uname $uid $uclock |
456 } else { | 501 } else { |
457 # !tj [#<id>] [name] | 502 # !tj [#<id>] [name] |
503 set notdefault 0 | |
458 set uname $uhand | 504 set uname $uhand |
459 set rindex 0 | 505 set rindex 0 |
460 if {[utl_arg_get $rarglist rindex rarg 0]} { | 506 if {[utl_arg_get $rarglist rindex rarg 0]} { |
461 # Check for #id prefix | 507 # Check for #id prefix |
462 tj_get_id $rarg rindex uid | 508 set notdefault [tj_get_id $rarg rindex uid] |
463 | 509 |
464 if {[utl_arg_get $rarglist rindex rarg 0]} { | 510 if {[utl_arg_get $rarglist rindex rarg 0]} { |
465 set uname [tj_correct_handle $rarg] | 511 set uname [tj_correct_handle $rarg] |
466 if {$uname == ""} { | 512 if {$uname == ""} { |
467 tj_msg $upublic $unick $uchan "err_unknown_user" [list $rcmd] | 513 tj_msg $upublic $unick $uchan "err_unknown_user" [list $rcmd] |
468 return 1 | 514 return 1 |
469 } | 515 } |
470 } | 516 } |
471 } else { | 517 } |
472 set uid $tj_default_id | 518 |
519 if {!$notdefault} { | |
520 set uid [tj_get_default_id $uname] | |
473 } | 521 } |
474 | 522 |
475 tj_display_tjs $upublic $unick $uchan $uname $uid $uclock | 523 tj_display_tjs $upublic $unick $uchan $uname $uid $uclock |
476 } | 524 } |
477 | 525 |