· 9 years ago · Jun 22, 2017, 06:54 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 {([\â„–\`\~\!\@\#\$\%\^\&\*\(\)\_\-\+\=\{\}\[\]\;\:\'\"\<\>\.\,\/\?\|\\])+} $text "" text;
40 set text_arr [split $text]
41
42 foreach i $text_arr {
43 if {[string length $i] < 3 || $i == "Ñлова"} {continue}
44
45 set upd_cnt [::mysql::exec $mysql_handler "UPDATE `irc_words` SET `cnt` = `cnt`+1 WHERE `usr` = '$nick' AND `word` = '$i' LIMIT 1"]
46
47 if {$upd_cnt < 1} {
48 ::mysql::exec $mysql_handler "INSERT INTO `irc_words` (`usr`, `word`, `cnt`) VALUES ('$nick','$i', 1)"
49 }
50 }
51}
52
53proc pub:stat {nick host handle chan text} {
54 global mysql_handler
55
56 set author $nick
57 if {[string length $text] >0 } {set author $text}
58 set slov_zap [::mysql::sel $mysql_handler "SELECT COUNT(`word`) as cnt FROM `irc_words` WHERE `usr` = '$author' GROUP BY `usr`" -list]
59 set love [join [::mysql::sel $mysql_handler "SELECT `word` FROM `irc_words` WHERE `usr` = '$author' ORDER BY `cnt` DESC LIMIT 7" -list] ", "]
60
61 if {$slov_zap == ""} {
62 putserv "PRIVMSG $chan :$author: Ðет информации."
63 } else {
64 putserv "PRIVMSG $chan :$author: Словарный Ð·Ð°Ð¿Ð°Ñ $slov_zap, любимые Ñлова: $love"
65 }
66}