EnergyMech

Forum | Features | Download | Addons | Help | #emech | Links | About | Contact

Versions | News Archive | Installing | Linking | Configuration | Commands | FAQ


The time is now Monday, November 20th, 2017, 1:16pm

Create account ]   User/Pass   


Forum Index :: Generic Discussion :: Simple Quote system for emech's :P :: Reply to this topic

Author
 
deadcow
Posted :: 3:10pm, Sun, Oct 21, 2007     Subject :: Simple Quote system for emech's :P


Posts: 1
 
    its is my first code in tclscript, please forget the errors because this works :P



#!tclsh
# Quote System By deadcow@efnet
# Especialmente desenvolvido para EnergyMech.
# 1st Code em tcl, por isso perdoem os bugs ?:P


# defina aqui os admins,ex: [concat ADMIN1 ADMIN2 ADMIN3].
set admins [concat NULL admin1 admin2 admin3]
# defina o canal. (your channel :P)
set quotechan #labsec


# funcao por Hajo Gurt http://wiki.tcl.tk/14273.
proc date { {i date} } {
switch -- $i {
d&t { set f "%c" }
year { set f "%Y" }
week { set f "%W" }
day { set f "%A" }
month { set f "%B" }
time { set f "%H:%M:%S" }
date { set f "%d/%m/%y" }
date4 { set f "%Y-%m-%d" }
D4T24 { set f "%Y-%m-%d %T" }
}
return [clock format [clock seconds] -format "$f"]
}


proc qwrite {quotes} {
global currentnick quotechan
variable quotesfile
set quotesfile [open "quotes.db" a+]
puts $quotesfile "([date date] as [date time]):($currentnick):$quotes"
to_server "PRIVMSG $quotechan :Quote added by $currentnick.\n"
close $quotesfile
}

proc iquote {nquote} {
global quotechan
variable i 0
variable k 0
set quotedb [open "quotes.db" r]
if {[regexp {[0-9]} $nquote]} {
while {(![eof $quotedb])} {
set qread [gets $quotedb]
set i [incr i]
if {[expr $nquote == $i] && $qread != ""} {
to_server "PRIVMSG $quotechan :Adicionado em: [parseia $qread 1], por: [parseia $qread 2], Quote n$i: [parseia $qread 3]\n"
set k 1
}
}
} else {
to_server "PRIVMSG $quotechan :Somente numeros, por favor.\n"
set k 1
}
if {[expr $k == 0]} {
to_server "PRIVMSG $quotechan :Not Found.\n"
}
}


proc parseia {srge tipo} {
set data ""
set por ""
set fquote ""
set srge [string trim $srge]
regexp {^\((.*)\):\((.*)\):(.*)} $srge - data por fquote
if {$data == "" && [expr $tipo == 1]} {
set data "unknown"
return $data
}
if {$por == "" && [expr $tipo == 2]} {
set por "unknown"
return $por
}
if {$fquote == "" && [expr $tipo == 3]} {
set fquote $srge
return $fquote
}
if {$fquote != "" && [expr $tipo == 3]} {
return $fquote
}
if {$por != "" && [expr $tipo == 2]} {
return $por
}
if {$data != "" && [expr $tipo == 1]} {
return $data
}
}

proc admin {nicka} {
global admins
set ladms [llength $admins]
variable i 0
while {[expr $i <= $ladms]} {
set i [incr i]
if {[lindex $admins $i] == $nicka} {
return "OK"
}
}
}


proc aflood {nome} {
global african flood
set african $nome
if {$nome == $african} {
set flood [incr flood]
if {[expr $flood >= 8]} {
after 10000
set flood 0
}
}
if {$nome != $african} {
set flood 0
}
}

proc read_quote {str} {
global quotechan
variable quotou ""
variable i 0
variable y 0
variable x 0
variable nfd 1
variable msg ".."
set quotenum {}
set quotenum2 {}
set quotenum3 {}
set quotedb [open "quotes.db" r]

# TEXTO SEARCH
if {[regexp {[a-zA-Z\}\]\{\[\<\>\^\$\&\!\@\#\']} $str]} {
while {(![eof $quotedb])} {
set qread [gets $quotedb]
set i [incr i]
if {[string match *[string trim $str]* $qread]} {
if {[expr $y <= 80]} {
lappend quotenum $i
} elseif {[expr $y >= 80] && [expr $y <= 150 ]} {
lappend quotenum2 $i
} elseif {[expr $y >= 150] && [expr $y <= 220]} {
lappend quotenum3 $i
}
set y [incr y]
}
}
if {[expr [llength $quotenum] != 0]} {
to_server "PRIVMSG $quotechan :$y ocorrencias -> [join $quotenum ", "]..\n"
}
if {[expr [llength $quotenum2] != 0]} {
to_server "PRIVMSG $quotechan :..[join $quotenum2 ", "]\n"
}
if {[expr [llength $quotenum3] != 0]} {
to_server "PRIVMSG $quotechan :..[join $quotenum3 ", "]\n"
}
if {[expr [llength $quotenum] == 0]} {
to_server "PRIVMSG $quotechan :Not Found.\n"
}

}

# NUMERIC SEARCH
if {[regexp {[0-9\+\-\*\/]} $str] && ![regexp {[a-zA-Z\}\]\{\[\<\>\^\$\&\!\@\#\']} $str]} {
while {(![eof $quotedb])} {
set qread [gets $quotedb]
set i [incr i]
set calcu [expr $str]
if {[expr $i == $str] && $qread != ""} {
to_server "PRIVMSG $quotechan :Quote n$calcu: [parseia $qread 3]\n"
set nfd 0
}
}
if {[expr $nfd != 0]} {
to_server "PRIVMSG $quotechan :Not Found.\n"
}
}

# NULL RANDOM
if {$str == ""} {
set leu [read $quotedb]
set leu [split $leu "\n"]
set tamanho [expr [llength $leu] -1]
regexp {^(\d+)\.} [expr 1 + rand() * $tamanho] - randi
if {[expr $randi != 0]} {
set quotou [parseia [lindex [linsert $leu 0 ""] $randi] 3]
} else {
set randi [incr $randi]
}
to_server "PRIVMSG $quotechan :Quote n$randi: $quotou\n"
}
}

proc qdelete {qdel} {
global quotechan
set fread [open "quotes.db" r]
set bread [open "quotes.bkp" w]
variable n 0
variable retorno 2
set dcon {}
while {(![eof $fread])} {
set capt [gets $fread]
set n [incr n]
lappend dcon $n
if {[expr $n == $qdel] || $capt == ""} {
continue
} else {
puts $bread "$capt"
}
}
set tamanho [llength $dcon]
if {[expr $tamanho <= $qdel] || [expr $qdel == 0]} {
to_server "PRIVMSG $quotechan :Not Found.\n"
} else {
to_server "PRIVMSG $quotechan :Quote $qdel deleted.\n"
}
close $bread
close $fread
exec mv quotes.bkp quotes.db
}

proc quote {from rest} {
global quotechan currentnick flood tempo
variable fera
variable qnum

set agora [clock format [clock seconds] -format %H]

if {![regexp {^#[a-zA-Z0-9]+ :!(.*?)quote(.*?)} $rest]} {
if {[expr $agora >= $tempo]} {
set tempo [expr $agora + 1]
read_quote ""
}
if {[expr $agora == 00]} {
set tempo [expr $agora + 1]
}
}

if {[regexp -- {^([a-zA-Z0-9\#]+) :!addquote (.*?)} $rest - canal fera] && $canal == $quotechan} {
if {[admin $currentnick] == "OK"} {
qwrite [string trim $fera]
}
}
if {[regexp -- {^([a-zA-Z0-9\#]+) :!delquote (.*?)} $rest - canal deleta] && $canal == $quotechan} {
if {[admin $currentnick] == "OK"} {
qdelete [string trim $deleta]
}
}
if {[regexp -- {^([a-zA-Z0-9\#]+) :!quote(.*?)} $rest - canal qnum] && $canal == $quotechan} {
aflood $currentnick
if {[expr $flood <= 8]} {
read_quote [string trim $qnum]
}
}
if {[regexp -- {^([a-zA-Z0-9\#]+) :!iquote(.*?)} $rest - canal qnum] && $canal == $quotechan} {
aflood $currentnick
if {[expr $flood <= 8]} {
iquote [string trim $qnum]
}
}
}
variable tempo [expr [clock format [clock seconds] -format %H] + 1]
variable flood 0
variable african ""

hook parse PRIVMSG quote


 

Copyright © 2000-2005 Proton,  All rights reserved. Last edited August 16th, 2005.
HTML 4.01 CSS