Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package require mysqltcl
- global mysqlstatus
- set port {3306}
- set host {127.0.0.1}
- set user {root}
- set password {}
- set mysql_handler [::mysql::connect -host $host -port $port -user $user -password $password]
- mysql::use $mysql_handler akyla
- ::mysql::exec $mysql_handler "SET NAMES 'cp1251'"
- ::mysql::exec $mysql_handler "SET CHARACTER SET 'cp1251'"
- ::mysql::exec $mysql_handler "SET SESSION collation_connection = 'cp1251_general_ci'"
- #mysql::close $mysql_handler
- #CREATE TABLE IF NOT EXISTS `irc_words` (
- # `id` int(10) unsigned NOT NULL auto_increment,
- # `usr` varchar(20) character set cp1251 NOT NULL,
- # `word` varchar(20) character set cp1251 NOT NULL,
- # `cnt` int(10) unsigned NOT NULL,
- # PRIMARY KEY (`id`),
- # KEY `usr` (`usr`,`word`)
- #) ENGINE=MyISAM DEFAULT CHARSET=cp1251
- bind pub - !слова pub:stat
- bind raw - PRIVMSG pub:hello
- proc pub:hello {from keyword arg} {
- global botnick mysql_handler
- set arg [split $arg]
- set chan [string tolower [lindex $arg 0]]
- set nick [lindex [split $from !] 0]
- if {$nick == $botnick || $nick == "" || [string match *.* $nick]} {return 0}
- set text [join [lrange $arg 1 end]]
- regsub -all {([\№\`\~\!\@\#\$\%\^\&\*\(\)\_\-\+\=\{\}\[\]\;\:\'\"\<\>\.\,\/\?\|\\])+} $text "" text;
- set text_arr [split $text]
- foreach i $text_arr {
- if {[string length $i] < 3 || $i == "слова"} {continue}
- if {$i == "ACTION" || $i == "QUIT" || $i == "NOTICE" } {break}
- set upd_cnt [::mysql::exec $mysql_handler "UPDATE `irc_words` SET `cnt` = `cnt`+1 WHERE `usr` = '$nick' AND `word` = '$i' LIMIT 1"]
- if {$upd_cnt < 1} {
- ::mysql::exec $mysql_handler "INSERT INTO `irc_words` (`usr`, `word`, `cnt`) VALUES ('$nick','$i', 1)"
- }
- }
- }
- proc pub:stat {nick host handle chan text} {
- global mysql_handler
- set author $nick
- if {[string length $text] >0 } {set author $text}
- set slov_zap [::mysql::sel $mysql_handler "SELECT COUNT(`word`) as cnt FROM `irc_words` WHERE `usr` = '$author' GROUP BY `usr`" -list]
- set love [join [::mysql::sel $mysql_handler "SELECT `word` FROM `irc_words` WHERE `usr` = '$author' ORDER BY `cnt` DESC LIMIT 7" -list] ", "]
- if {$slov_zap == ""} {
- putserv "PRIVMSG $chan :$author: Нет информации."
- } else {
- putserv "PRIVMSG $chan :$author: Словарный запас $slov_zap, любимые слова: $love"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement