bind pub - +bnc bnc_add
proc bnc_add { nick uhost hand chan text } {
set bfile [open bnc.txt r]
set data [read $bfile]
close $bfile
foreach user [split $data "\n"] {
if { $nick == [lindex [split $user "|"] 0] } {
putserv "PRIVMSG $nick :$nick, вы уже оставляли заявку."
return
}
}
set bfile [open bnc.txt a]
puts -nonewline $bfile "$nick|[lindex [split $uhost "@"] 0]"
close $bfile
putserv "PRIVMSG $nick :$nick, ваша заявка на добавление бнц принята."
}
bind pub o|o !заявки bnc_view
proc bnc_view {nick uhost hand chan text } {
global lastbind
switch [lindex [split $text] 0] {
"list" {
set bfile [open bnc.txt r]
set data [read $bfile]
close $bfile
set blist [list]
foreach user [split $data "\n"] {
if {$user != ""} {
lappend blist "$user, "
}
}
if {$blist != ""} {
putserv "PRIVMSG $chan :$nick, список осталенных заявок Ник|Идент:"
putserv "PRIVMSG $chan :[string trim [join $blist] " ,"]."
} else {
putserv "PRIVMSG $chan :$nick, никто не оставил заявок."
}
}
"del" {
set bfile [open bnc.txt "r"]
set data [read $bfile]
close $bfile
putlog $data
set delline [expr [lindex [split $text] 1] - 1]
putlog $delline|[llength [split $data "\n"]]
if {[lindex [split $text] 1] < 1 || [lindex [split $text] 1] > [llength [split $data "\n"]] || ![isnumber $delline]} {
putserv "PRIVMSG $chan :$nick, не верно указан номер заявки."
return
}
set lines [split $data "\n"]
proc K {x y} { set x }
set lines [lreplace [K $lines [set lines {}]] $delline $delline]
set bfile [open bnc.txt "w"]
puts -nonewline $bfile [join $lines "\n"]
close $bfile
putserv "PRIVMSG $chan :$nick, заявка №[expr $delline + 1] удалена."
}
default {
putserv "PRIVMSG $chan :$nick, используй $lastbind list или $lastbind del."
}
}
}