Advertisement
Guest User

Untitled

a guest
Jul 10th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 1.90 KB | None | 0 0
  1. bind pub - "!smart" quotes:smart
  2. bind pub - "!gossip" quotes:gossip
  3.  
  4. set g_lastsearcher ""
  5. set g_lastquoteno 0
  6. set g_lastsearch ""
  7.  
  8. proc quotes:getquote { nick type arg } {
  9.     global vote_config botnick g_lastsearcher g_lastsearch g_lastquoteno
  10.  
  11.     switch $type {
  12.         "smart" {
  13.             set fp [open "text/smart.txt" "r"]
  14.         }
  15.         "gossip" {
  16.             set fp [open "text/gossip.txt" "r"]
  17.         }
  18.     }
  19.    
  20.     set quotes [split [read $fp] "\n"]
  21.  
  22.     if {[string length $arg] > 0} {
  23.         if {[isnumber $arg]} {
  24.             set quoteno [lindex $arg 0]
  25.  
  26.             if {$quoteno > [llength $quotes]} {
  27.                 return -1
  28.             }
  29.         } else {
  30.             if {$g_lastsearcher == $nick && $g_lastsearch == $arg} {
  31.                 set quoteno [lsearch -start [expr $g_lastquoteno + 1] -glob $quotes "*$arg*"]
  32.             } else {
  33.                 # Try to find it
  34.                 # If quoteno is the last, try one more time
  35.                 set quoteno [lsearch -glob $quotes "*$arg*"]
  36.             }
  37.                
  38.             if {$quoteno == -1} {
  39.                 return -1
  40.             }
  41.         }
  42.     } else {
  43.         set quoteno [rand [llength $quotes]]
  44.     }
  45.  
  46.     close $fp
  47.  
  48.     set g_lastsearcher $nick
  49.     set g_lastsearch $arg
  50.     set g_lastquoteno $quoteno
  51.  
  52.     return "$quoteno [lindex $quotes $quoteno]"
  53. }
  54.  
  55. proc quotes:smart { nick uhost hand channel arg } {
  56.     global vote_config
  57.  
  58.     set ret [quotes:getquote $nick "smart" $arg]
  59.  
  60.     if {$ret == -1} {  
  61.         puthelp "PRIVMSG $channel :$vote_config(code1)Quote containing $vote_config(code2)${arg}$vote_config(code1) not found"
  62.     } else {
  63.         puthelp "PRIVMSG $channel :$vote_config(code1)SMART [lindex $ret 0]:$vote_config(code2) [lrange $ret 1 end]"
  64.     }
  65.  
  66. }
  67.  
  68. proc quotes:gossip { nick uhost hand channel arg } {
  69.     global vote_config
  70.  
  71.     set ret [quotes:getquote $nick "gossip" $arg]
  72.  
  73.     if {$ret == -1} {  
  74.         puthelp "PRIVMSG $channel :$vote_config(code1)Quote containing $vote_config(code2)${arg}$vote_config(code1) not found"
  75.     } else {
  76.         puthelp "PRIVMSG $channel :$vote_config(code1)GOSSIP [lindex $ret 0]:$vote_config(code2) [lrange $ret 1 end]"
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement