Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. package require mysqltcl
  2. global mysqlstatus
  3.  
  4. set port {3306}
  5. set host {127.0.0.1}
  6. set user {root}
  7. set password {}
  8.  
  9. set mysql_handler [::mysql::connect -host $host -port $port -user $user -password $password]
  10.  
  11. mysql::use $mysql_handler akyla
  12.  
  13. ::mysql::exec $mysql_handler "SET NAMES 'cp1251'"
  14. ::mysql::exec $mysql_handler "SET CHARACTER SET 'cp1251'"
  15. ::mysql::exec $mysql_handler "SET SESSION collation_connection = 'cp1251_general_ci'"
  16.  
  17. #mysql::close $mysql_handler
  18.  
  19. #CREATE TABLE IF NOT EXISTS `irc_words` (
  20. # `id` int(10) unsigned NOT NULL auto_increment,
  21. # `usr` varchar(20) character set cp1251 NOT NULL,
  22. # `word` varchar(20) character set cp1251 NOT NULL,
  23. # `cnt` int(10) unsigned NOT NULL,
  24. # PRIMARY KEY (`id`),
  25. # KEY `usr` (`usr`,`word`)
  26. #) ENGINE=MyISAM DEFAULT CHARSET=cp1251
  27.  
  28. bind pub - !слова pub:stat
  29. bind raw - PRIVMSG pub:hello
  30.  
  31. proc pub:hello {from keyword arg} {
  32. global botnick mysql_handler
  33. set arg [split $arg]
  34. set chan [string tolower [lindex $arg 0]]
  35. set nick [lindex [split $from !] 0]
  36. if {$nick == $botnick || $nick == "" || [string match *.* $nick]} {return 0}
  37.  
  38. set text [join [lrange $arg 1 end]]
  39. regsub -all {([\№\`\~\!\@\#\$\%\^\&\*\(\)\_\-\+\=\{\}\[\]\;\:\'\"\<\>\.\,\/\?\|\\])+} $text "" text;
  40. set text_arr [split $text]
  41.  
  42. foreach i $text_arr {
  43. if {[string length $i] < 3 || $i == "слова"} {continue}
  44. if {$i == "ACTION" || $i == "QUIT" || $i == "NOTICE" } {break}
  45.  
  46. set upd_cnt [::mysql::exec $mysql_handler "UPDATE `irc_words` SET `cnt` = `cnt`+1 WHERE `usr` = '$nick' AND `word` = '$i' LIMIT 1"]
  47.  
  48. if {$upd_cnt < 1} {
  49. ::mysql::exec $mysql_handler "INSERT INTO `irc_words` (`usr`, `word`, `cnt`) VALUES ('$nick','$i', 1)"
  50. }
  51. }
  52. }
  53.  
  54. proc pub:stat {nick host handle chan text} {
  55. global mysql_handler
  56.  
  57. set author $nick
  58. if {[string length $text] >0 } {set author $text}
  59. set slov_zap [::mysql::sel $mysql_handler "SELECT COUNT(`word`) as cnt FROM `irc_words` WHERE `usr` = '$author' GROUP BY `usr`" -list]
  60. set love [join [::mysql::sel $mysql_handler "SELECT `word` FROM `irc_words` WHERE `usr` = '$author' ORDER BY `cnt` DESC LIMIT 7" -list] ", "]
  61.  
  62. if {$slov_zap == ""} {
  63. putserv "PRIVMSG $chan :$author: Нет информации."
  64. } else {
  65. putserv "PRIVMSG $chan :$author: Словарный запас $slov_zap, любимые слова: $love"
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement