pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Advertising: Credit Counseling - Loans - mobile phones - Loans
TCL paste-bin - collaborative debugging tool View Help

Posted by leprechau on Fri 2nd Nov 19:24 (modification of post by ace view diff)
diff | download | new post

  1. ## just corrected things that seemed really glaring to me
  2. ## there is still some work to do...take a look at where i changed
  3. ## == and != lines to use string equal...you need to change the rest
  4. ## also...you don't need to split content before lappending it
  5. ## that just makes you add a list as a list element
  6. ## usually you don't want that...usually you want strings as your list
  7. ## elements...and that should clear up some of your problems...
  8. ## i also removed the strfilter junk...that is never needed...just handle
  9. ## your strings and lists correctly
  10. ##
  11. #
  12. bind pub - !define learn_it
  13. bind pub - !learn learn_learn
  14. bind pub - "!whatis" learn_explain
  15. bind pub - "!search" learn_search
  16.  
  17. bind dcc n|n sort learn_sortFile:dcc
  18. bind dcc - allwords learn_alldef:dcc
  19.  
  20. #bind time - "5 0 1 * *" learn_sortFile
  21.  
  22. set learn_whodid "*"
  23.  
  24. proc learn_alldef:dcc {hand idx text} {
  25.     global learn_db
  26.     putdcc $idx "\[ ° ° Available definitions ° ° \]"
  27.     set lista ""
  28.     set fp [open $learn_db r]
  29.     while {![eof $fp]} {lappend lista [lindex [split [gets $fp]] 1]}
  30.     close $fp
  31.     foreach {a b c d e f g h i j} [lsort -unique $lista] {putdcc $idx "   \0037$a  $b  $c  $d  $e  $f  $g  $h  $i  $j\003"}
  32.     putdcc $idx "\[ ° ° === END === ° ° \]"
  33. }
  34.  
  35. proc learn_it { nick uhost hand chan text } {
  36.   global chan_ign
  37.   if {![string length $text]} {
  38.     if {[lsearch $chan_ign $chan] < "0" } {
  39.       puthelp "NOTICE $nick :Try !define <keyword> defenition!"
  40.     }
  41.   } else {
  42.      if {[string equal [lindex [split $text] 1] "*"]} {
  43.         learn_addEntry [lindex [split $text] 1] [lindex [split $text] 0] [lrange [split $text] 2 end]
  44.         learn_flood "[lindex [split $text] 0]" $chan
  45.      } else {
  46.         learn_addEntry $nick [lindex [split $text] 0] [lrange [split $text] 1 end]
  47.         if {[lsearch $chan_ign $chan] < "0" } {
  48.           puthelp "NOTICE $nick :Defenition added"
  49.         }
  50.         learn_flood "[lindex [split $text] 0]" $chan
  51.      }
  52.    }
  53. }
  54.  
  55. proc learn_learn { nick uhost hand chan text } {
  56. global chan_ign
  57. if {[lsearch $chan_ign $chan] < "0" } {
  58.   switch -exact -- [lindex [split $text] 0] {
  59.   "add" {
  60.    if {![string length [lindex [split $text] 2]]} {
  61.     puthelp "NOTICE $nick :Try !learn add <keyword> defenition!"
  62.    } else {
  63.       learn_addEntry $nick [lindex [split $text] 1] [lrange [split $text] 2 end]
  64.       puthelp "NOTICE $nick :Defenition added"
  65.       learn_flood "[lindex [split $text] 1]" $chan
  66.      }
  67.   }
  68.   "del" {
  69.    if {[string length [lindex [split $text] 2]]} {
  70.     learn_delEntry [lindex [split $text] 1] [lindex [split $text] 2]
  71.     puthelp "NOTICE $nick :Defenition removed"
  72.     learn_flood "[lindex [split $text] 1]" $chan
  73.    } else {
  74.       learn_delEntry [lindex [split $text] 1]
  75.       puthelp "NOTICE $nick :Defenition removed"
  76.      }
  77.   }
  78.   "ins" {
  79.    if {[string length [lindex [split $text] 3]]} {
  80.     learn_insEntry [lindex [split $text] 1] [lindex [split $text] 2] [lrange [split $text] 3 end]
  81.     puthelp "NOTICE $nick :Defenition inserted"
  82.     learn_flood "[lindex [split $text] 1]" $chan
  83.    } else {puthelp "NOTICE $nick :Insert Syntax: !learn ins <keyword> num text" }
  84.   }
  85.   "put" {
  86.    if {[string length [lindex [split $text] 3]]} {
  87.     learn_putEntry [lindex [split $text] 1] [lindex [split $text] 2] [lrange [split $text] 3 end] $nick
  88.     puthelp "NOTICE $nick :Defenition inserted"
  89.     learn_flood "[lindex [split $text] 1]" $chan
  90.    } else {puthelp "NOTICE $nick :Put Syntax: !learn put <keyword> num text" }
  91.   }
  92.   "rep" {
  93.    if {[string length [lindex [split $text] 3]]} {
  94.     learn_repEntry [lindex [split $text] 1] [lindex [split $text] 2] [lrange [split $text] 3 end]
  95.     puthelp "NOTICE $nick :Defenition replaced"
  96.     learn_flood "[lindex [split $text] 1]" $chan
  97.    } else {puthelp "NOTICE $nick :Replace Syntax: !learn rep <keyword> num text" }
  98.   }
  99.   "status" {
  100.     learn_status $nick $chan
  101.     learn_flood "[lindex [split $text] 0]" $chan
  102.   }
  103.   default { puthelp "NOTICE $nick :\0037Syntax: !learn <add|del|info|ins|rep> <keyword> <num> text\003" }
  104.  }
  105. }
  106. }
  107.  
  108. proc learn_explain { nick uhost hand chan text } {
  109.   global chan_ign
  110.   if {[lsearch $chan_ign $chan] < "0" } {
  111.     global learn_db learn_whodid;if {![info exists learn_whodid]} {set learn_whodid ""}
  112.     set real_chan $chan
  113.     set nogo [split [lindex $chan_ign 0] " "]
  114.     if {![string length $text]} {
  115.       puthelp "PRIVMSG $chan :\0037Say what?: Usage: !whatis <keyword> or !whatis <keyword> > <yournick>\003"
  116.       return
  117.     }
  118.     set explain [string tolower [lindex [split $text] 0]];
  119.     set chan [string tolower $chan]
  120.     if {([string equal [lindex [split $text] 1] ">"] || [string equal [lindex [split $text] 1] ">>"]) && [string length [lindex [split $text] 2]]} {
  121.       set chan [lindex [split $text] 2]
  122.     }
  123.     set fp [open $learn_db r]
  124.     set allEntrys ""
  125.     while {![eof $fp]} {
  126.       gets $fp curEntry
  127.       if {[string equal -nocase [lindex [split $curEntry] 1] $explain]} {
  128.         lappend allEntrys $curEntry
  129.       }
  130.     }
  131.     close $fp
  132.     set count 0
  133.     if {[llength $allEntrys]==1} {
  134.         # Single line output
  135.       if {[lsearch -exact $learn_whodid [list $explain [string tolower $chan]]] != -1} {
  136.         puthelp "PRIVMSG $real_chan :\0027Hey ${nick}\002, i've already told $chan about \"$explain\"... no need to repeat (i think)"
  137.         return 0
  138.       } else {
  139.         set dump [join [lrange [split [lindex $allEntrys 0]] 2 end]]
  140.         puthelp "PRIVMSG $chan :\00311${explain}\003:\0037 ${dump}\003";incr count
  141.       }
  142.     } else {
  143.         # Chan flood protection
  144.       if {[llength $allEntrys]>17&&[string index $chan 0]=="#"&&!(([lindex [split $text] 1] == ">" || [lindex [split $text] 1] == ">>") && [lindex [split $text] 2] != "")} {
  145.         set chan $nick;
  146.         puthelp "PRIVMSG $real_chan :\00311\037${explain}?\002\003 \0037What a huge defenition... i'll tell you in private instead...\003"
  147.       }
  148.       if {[lsearch -exact $learn_whodid [list $explain [string tolower $chan]]] != -1} {
  149.         puthelp "PRIVMSG $real_chan :\002Hey ${nick}\002, i've already told you about \"$explain\"... no need to repeat (i think)"
  150.         return 0
  151.       }
  152.         # Multi line output
  153.       foreach curEntry $allEntrys {
  154.         incr count
  155.         set dump [join [lrange [split [lindex $allEntrys 0]] 2 end]]
  156.         putquick "PRIVMSG $chan :\00311${explain} \037\|\037${count}\037|\037:\003\0037 ${dump}\003"
  157.         }
  158.       }
  159.         # No ouput found and more
  160.       if {$count == 0} { puthelp "PRIVMSG $chan :\00311${explain} \037\|\037\002x\002\037\|\037: \003\0037No defenition found for word.\003" }
  161.       if {([lindex [split $text] 1] == ">" || [lindex [split $text] 1] == ">>") && [lindex [split $text] 2] != ""} {
  162.       #puthelp "NOTICE $nick :Ok, done."
  163.     }
  164.     lappend learn_whodid [list $explain [string tolower $chan]]
  165.     utimer 60 "learn_flood \"$explain\" \"$chan\""
  166.   }
  167. }
  168.  
  169. proc learn_flood {word target} {
  170.   # removes from "already told so" list
  171.   global learn_whodid
  172.   set word [string tolower $word]; set target [string tolower $target]
  173.   set lin [lsearch -exact $learn_whodid [list $word $target]]
  174.   if {$lin == -1} {
  175.     return
  176.   } else {
  177.     set learn_whodid [lreplace $learn_whodid $lin $lin]
  178.   }
  179. }
  180.  
  181. proc learn_addEntry { nick word defenition } {
  182.  global learn_db;set word [string tolower $word]
  183.  if {![file exists $learn_db]} {file mkdir [lindex [split $learn_db /] 0];set fp [open $learn_db w+]
  184.   puts $fp "Infodb."
  185.  } else {set fp [open $learn_db a]};puts $fp "$nick $word [join $defenition]";close $fp
  186. }
  187.  
  188. proc learn_delEntry { word {remnum "all"}} {
  189.  global learn_db
  190.  set word [string tolower $word]
  191.  set fp [open $learn_db r]
  192.  set allEntrys ""
  193.  set count 1
  194.  if {$remnum == "all"} {
  195.   while {![eof $fp]} {gets $fp curEntry;if {![string equal -nocase [lindex [split $curEntry] 1] $word]} {lappend allEntrys $curEntry}}
  196.  } else {
  197.   while {![eof $fp]} {
  198.    gets $fp curEntry
  199.    if {![string equal -nocase [lindex [split $curEntry] 1] $word] || ($count != $remnum && $remnum != -2)} {
  200.     if {[info exists curEntry]&&$curEntry!=""} {lappend allEntrys $curEntry}
  201.     if {[string equal -nocase [lindex [split $curEntry] 1] $word]} {incr count}
  202.    } else {incr count}
  203.   }
  204.  }
  205.  close $fp;set fp [open $learn_db w];foreach curEntry $allEntrys {puts $fp $curEntry};close $fp
  206. }
  207.  
  208. proc learn_insEntry {word num text} {
  209.  global learn_db
  210.  set word [string tolower $word]
  211.  set fp [open $learn_db r]
  212.  set allEntrys ""
  213.  set count 1
  214.  while {![eof $fp]} {
  215.   gets $fp curEntry
  216.   if {![string equal -nocase [lindex [split $curEntry] 1] $word] || ($count != $num && $num != -2)} {
  217.    if {[info exists curEntry]&&$curEntry!=""} {lappend allEntrys $curEntry}
  218.    if {[string equal -nocase [lindex [split $curEntry] 1] $word]} {incr count}
  219.   } else {incr count;lappend allEntrys "$curEntry [join $text]"}
  220.  }
  221.  close $fp;set fp [open $learn_db w];foreach curEntry $allEntrys {puts $fp $curEntry};close $fp
  222. }
  223.  
  224. proc learn_putEntry {word num text {whodid "."}} {
  225.  global learn_db
  226.  set word [string tolower $word]
  227.  set fp [open $learn_db r]
  228.  set allEntrys ""
  229.  set count 1
  230.  if {$num==1} {lappend allEntrys "$whodid $word [join $text]"}
  231.  while {![eof $fp]} {
  232.   gets $fp curEntry
  233.   if {[string equal -nocase [lindex [split $curEntry] 1] $word]} {incr count}
  234.   if {[info exists curEntry]&&$curEntry!=""} {lappend allEntrys $curEntry}
  235.   if {$count==$num&&$num!=1} {lappend allEntrys "$whodid $word [join $text]"}
  236.  }
  237.  close $fp;set fp [open $learn_db w];foreach curEntry $allEntrys {puts $fp $curEntry};close $fp
  238. }
  239.  
  240.  
  241. proc learn_repEntry {word num text} {
  242.  global learn_db
  243.  set word [string tolower $word]
  244.  set fp [open $learn_db r]
  245.  set allEntrys ""
  246.  set count 1
  247.  while {![eof $fp]} {
  248.   gets $fp curEntry
  249.   if {![string equal -nocase [lindex [split $curEntry] 1] $word] || ($count != $num && $num != -2)} {
  250.    if {[info exists curEntry]&&$curEntry!=""} {lappend allEntrys $curEntry}
  251.    if {[string equal -nocase [lindex [split $curEntry] 1] $word]} {incr count}
  252.   } else {incr count;lappend allEntrys "[lrange [split $curEntry] 0 1] [join $text]"}
  253.  }
  254.  close $fp;set fp [open $learn_db w];foreach curEntry $allEntrys {puts $fp $curEntry};close $fp
  255. }
  256.  
  257.  
  258. proc learn_status {nick chan} {
  259.   global learn_db
  260.   set fp [open $learn_db r]
  261.   set allEntrys ""
  262.   set cache ""
  263.   set count 0
  264.   set lines 0
  265.   while {![eof $fp]} {
  266.     set curEntry [gets $fp]
  267.     if {[info exists curEntry]&&$curEntry!=""} {lappend allEntrys [split $curEntry " "]}
  268.   }
  269.   close $fp
  270.   set lines [llength $allEntrys]
  271.   foreach line $allEntrys {
  272.     set word [join [lindex $line 1]]
  273.     if {![string match -nocase "*$word*" $cache]} {
  274.       append cache "$word "
  275.       incr count
  276.     }
  277.   }
  278.   puthelp "PRIVMSG $chan :\00311Status\003: \0037There's \037\002$lines\002\037 enties and \037\002$count\002\037 unique definitions in the DataBase.\003"
  279. }
  280.  
  281.  
  282. proc learn_sortFile {a c d e f} {
  283.  global learn_db
  284.  set t_count [clock clicks -milliseconds]
  285.  set fp [open $learn_db r]
  286.  set allEntrys ""
  287.  while {![eof $fp]} {
  288.   set curEntry [gets $fp]
  289.   if {[info exists curEntry]&&$curEntry!=""} {lappend allEntrys [split $curEntry " "]}
  290.  }
  291.  close $fp; set allEntrys [lsort -index 1 $allEntrys]
  292.  set fp [open $learn_db w];foreach curEntry $allEntrys {puts $fp [join $curEntry " "]};close $fp
  293.  putlog "\[!learn\]-> Auto sorted data in the database ($learn_db)->[expr double([clock clicks -milliseconds]-$t_count)/1000]s"
  294. }
  295.  
  296. proc learn_sortFile:dcc {hand idx text} {
  297.  global learn_db
  298.  set t_count [clock clicks -milliseconds]
  299.  set allEntrys ""
  300.  set fp [open $learn_db r]
  301.  while {![eof $fp]} {
  302.   set curEntry [gets $fp]
  303.   if {[info exists curEntry]&&$curEntry!=""} {lappend allEntrys $curEntry}
  304.  }
  305.  close $fp; set allEntrys [lsort -index 1 $allEntrys]
  306.  set fp [open $learn_db w];foreach curEntry $allEntrys {puts $fp $curEntry};close $fp
  307.  putdcc $idx "\[!learn\]-> Sorted data in the database ($learn_db)->[expr double([clock clicks -milliseconds]-$t_count)/1000]s"
  308. }
  309.  
  310. proc learn_search { nick uhost hand chan text } {
  311. global chan_ign
  312. if {[lsearch $chan_ign $chan] < "0" } {
  313.   global learn_db
  314.   if {![string length $text]} {
  315.     puthelp "PRIVMSG $chan :\0037Not enough arguments.\003"
  316.     return
  317.   }
  318.   set init_t [clock clicks -milliseconds]
  319.   set fp [open $learn_db r]
  320.   set matches ""
  321.   set allEntrys ""
  322.   while {![eof $fp]} {
  323.     gets $fp curEntry;
  324.     if {[info exists curEntry]&&$curEntry!=""} {
  325.       set curEntry [string tolower $curEntry]
  326.       set thisEntry [join [lrange [split $curEntry] 1 end]]
  327.       if {[string match -nocase "*${text}*" $thisEntry]} {
  328.          # putserv "PRIVMSG #meta :worked $curEntry"
  329.         if {[lsearch $allEntrys [lindex [split curEntry] 1]]==-1} {
  330.           lappend allEntrys [lindex [split $curEntry] 1]
  331.           set allEntrys [lsort -unique $allEntrys]
  332.         }
  333.       }
  334.     }
  335.   }
  336.   set init_t [expr double(([clock clicks -milliseconds] - $init_t))/1000]
  337.   if {$allEntrys==""} {
  338.     puthelp "PRIVMSG $chan :\0037\002No matches\002 for \037\002$text\002\037 in the DataBase, sorry. (Search tok: \002\037${init_t}s\037\002)\003"
  339.   } else {
  340.     if {[llength $allEntrys]>20} {
  341.       puthelp "PRIVMSG $chan :\0037\002Too many matches.\002 Please try a more complex search.\003"
  342.     } else {
  343.       puthelp "PRIVMSG $chan :\0037\002Found \037[llength $allEntrys]\037 matches.\002 Sorted: \037[join [lsort -dictionary $allEntrys] "\037, \037"]\037. (\002\037${init_t}\037s)\003"
  344.     }
  345.   }
  346. }
  347. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me
: