· 9 years ago · Jun 22, 2017, 07:08 PM
1package require mysqltcl
2global mysqlstatus
3
4set port {3306}
5set host {127.0.0.1}
6set user {root}
7set password {}
8
9set mysql_handler [::mysql::connect -host $host -port $port -user $user -password $password]
10
11mysql::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
28bind pub - !Ñлова pub:stat
29bind raw - PRIVMSG pub:hello
30
31proc 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 {([\x00\x01\x02\x03\â„–\`\~\!\@\#\$\%\^\&\*\(\)\_\-\+\=\{\}\[\]\;\:\'\"\<\>\.\,\/\?\|\\])+} $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 nick_cnt [::mysql::sel $mysql_handler "SELECT `usr` FROM `irc_words` WHERE `usr` = '$i' LIMIT 1"]
47 if {$nick_cnt == 1} {continue}
48
49 set upd_cnt [::mysql::exec $mysql_handler "UPDATE `irc_words` SET `cnt` = `cnt`+1 WHERE `usr` = '$nick' AND `word` = '$i' LIMIT 1"]
50
51 if {$upd_cnt < 1} {
52 ::mysql::exec $mysql_handler "INSERT INTO `irc_words` (`usr`, `word`, `cnt`) VALUES ('$nick','$i', 1)"
53 }
54 }
55}
56
57proc pub:stat {nick host handle chan text} {
58 global mysql_handler
59
60 set author $nick
61 if {[string length $text] >0 } {set author $text}
62 set slov_zap [::mysql::sel $mysql_handler "SELECT COUNT(`word`) as cnt FROM `irc_words` WHERE `usr` = '$author' GROUP BY `usr`" -list]
63 set love [join [::mysql::sel $mysql_handler "SELECT `word` FROM `irc_words` WHERE `usr` = '$author' ORDER BY `cnt` DESC LIMIT 7" -list] ", "]
64
65 if {$slov_zap == ""} {
66 putserv "PRIVMSG $chan :$author: Ðет информации."
67 } else {
68 putserv "PRIVMSG $chan :$author: Словарный Ð·Ð°Ð¿Ð°Ñ $slov_zap, любимые Ñлова: $love"
69 }
70}