This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Script Editing/modifying Request Please

Support & discussion of released scripts, and announcements of new releases.
Post Reply
l
lebjustice
Voice
Posts: 5
Joined: Sun Jun 17, 2007 11:20 pm

Script Editing/modifying Request Please

Post by lebjustice »

it's dlearn.tcl the thing is users have to Trigg==> ??<space><word>
i would love the trig itself to be the word so users can like trigg !word (no space)
I'll apreciate it.

Code: Select all

## Files & Backup time (note: never give the same name to the files or the script will make the bot die ##
 #Don't forget, all this files need to have +rw permissions you can do that with chmod command.

#The file to store learn data
set learn(file) "learn.dat"

#The file to backup the data
set learn(backupfile) "learn.dat.old"

#The file where the lock definitions will be stored/saved
set learn(lockfile) "learn.lock.dat"

#The temp file when you need to delete/insert something or add/delete words of lock file
set learn(tempfile) "learn.tmp"

#The time in minutes between each backup, '0' for no backup usage but you can manualy force backup to be saved.
set learn(backuptime) "480"


## Triggers ##


#To add a definition to a word --> trigger <word> <definition>
set learn(add) "!learn"

#To delete all word --> trigger <word>
set learn(forget) "!forget"

#To insert a definition to word, the definition will be added to the end --> trigger <word> <definition>
set learn(insert) "!insert"

#To delete one definition from word --> trigger <word> <n>
set learn(del) "!del"

#To lock one word, if word is locked it's impossible insert/delete that word --> trigger <word>
set learn(lock) "!lock"

#This will unlock a locked word --> trigger <word>
set learn(unlock) "!unlock"

#This is used to retrieve a definition of word --> ?? <word>
set learn(view) "??"

#The list of words in learn file
set learn(wordlist) "!learnlist"

#This is used to see the lock words
set learn(lockwords) "!locklist"

#This is the trigger to force backup to be saved
set learn(forcebackup) "!forceback"

#This is the trigger to show some misc info
set learn(misc) "!learninfo"

#The help with all triggers and other misc stuff. This will change consoant if you have or not permission to change the data.
set learn(help) "!lhelp"



## Misc ##

#The flag needed add/insert/delete one definition/delete word
set learn(flags-change) "o"

#The flag needed to lock/unlock a word and even to force backup to be saved, i recomend and it's logical
# never give less access than the flags-change
set learn(owner) "m"

#This is the method PRIVMSG/NOTICE when something changed this will work only for the nick who change
set learn(method) "NOTICE"

#This is the method PRIVMSG/NOTICE when you try to retrieve a definition, this will be sended to a target request(channel/nick)
set learn(method-def) "PRIVMSG"

#This is the exempt channels to the bot separated by commas(,)
set learn(non-channels) "#Lame,#Bots"




############# Don't change nothing below if you don't know what you are doing ###############


## BINDS ##
bind pub - $learn(add) learn_add
bind pub - $learn(forget) learn_forget
bind pub - $learn(lock) learn_lock
bind pub - $learn(unlock) learn_unlock
bind pub - $learn(insert) learn_insert
bind pub - $learn(del) learn_del
bind pub - $learn(view) learn_view
bind pub - $learn(forcebackup) learn_forceback
bind pub - $learn(lockwords) learn_lockwords
bind pub - $learn(wordlist) learn_list
bind pub - $learn(misc) learn_misc
bind pub - $learn(help) learn_help

bind msg - $learn(add) learn_add
bind msg - $learn(forget) learn_forget
bind msg - $learn(lock) learn_lock
bind msg - $learn(unlock) learn_unlock
bind msg - $learn(insert) learn_insert
bind msg - $learn(del) learn_del
bind msg - $learn(view) learn_view_msg
bind msg - $learn(forcebackup) learn_forceback
bind msg - $learn(lockwords) learn_lockwords
bind msg - $learn(wordlist) learn_list
bind msg - $learn(misc) learn_misc
bind msg - $learn(help) learn_help



## Misc ##
set learn(version) "v1.0.1"
putlog "Dekadent Learn $learn(version) by CoolMaster <coolmaster@GameOver.co.pt> <http://coolmaster.cjb.net>"
if {$learn(backuptime) > 0} {timer $learn(backuptime) learn_backup}
if {[string compare $learn(file) $learn(backupfile)] == 0} {die "Dekadent Learn, you probably have the same name to other types of file, please edit your Dekadent Learn"}
if {[string compare $learn(file) $learn(lockfile)] == 0} {die "Dekadent Learn, you probably have the same name to other types of file, please edit your Dekadent Learn"}
if {[string compare $learn(file) $learn(tempfile)] == 0} {die "Dekadent Learn, you probably have the same name to other types of file, please edit your Dekadent Learn"}
if {[string compare $learn(backupfile) $learn(lockfile)] == 0} {die "Dekadent Learn, you probably have the same name to other types of file, please edit your Dekadent Learn"}
if {[string compare $learn(backupfile) $learn(tempfile)] == 0} {die "Dekadent Learn, you probably have the same name to other types of file, please edit your Dekadent Learn"}
if {[string compare $learn(tempfile) $learn(lockfile)] == 0} {die "Dekadent Learn, you probably have the same name to other types of file, please edit your Dekadent Learn"}
if {![file exists $learn(file)]} {set fxtmp [open $learn(file) w] ; close $fxtmp}
if {![file exists $learn(lockfile)]} {set fxtmp [open $learn(lockfile) w] ; close $fxtmp}


## Procs ##


#This will check if word is locked, if is return 1 else return 2
proc check_lock {word} {
global learn
set fx [open $learn(lockfile) r]
while {![eof $fx]} {
set word_check [gets $fx]
if {[string compare $word $word_check] == 0} {close $fx ; return 1}
}
close $fx ; return 2
}



# Verify if user have access flags to use learn changes, return 1 if yes else return 2
proc check_access {hand type} {
global learn
if {[matchattr $hand $learn($type)] == 1} {return 1} else {return 2}
}


# Verify if definition allready exists, if yes will return 1 else return 2
proc check_word {word} {
global learn
set fx [open $learn(file) r]
while {![eof $fx]} {
set word_check [lindex [gets $fx] 0]
if {[string compare $word $word_check] == 0} {close $fx ; return 1}
}
close $fx ; return 2
}


# Verify if channel is not on exempt list, if is return 1 else return 2
proc isvalidchan {chan} {
global learn
set chans [string tolower [split "$learn(non-channels)" ","]]
set i 0
while {1} {
set chan_c [lindex $chans $i]
if {$chan_c == ""} {return 2} elseif {$chan_c == "$chan"} {return 1}
incr i 1
}
}


proc learn_add {nick host hand chan text} {
global learn
if {[check_access $hand flags-change] == 2} {
putserv "$learn(method) $nick :You don't have access"
return 0
}
set word [string tolower [lindex $text 0]]
set definition [lrange $text 1 end]
if {$definition == ""} {
putserv "$learn(method) $nick :Invalid syntax, use $learn(add) <word> <definition>"
return 0
}
if {[check_word $word] == 1} {
putserv "$learn(method) $nick :Definition allready exists"
return 0
}
set fx [open $learn(file) a]
puts $fx "$word $definition ¦"
close $fx
putserv "$learn(method) $nick :Added \"$word\" to database"
}


proc learn_forget {nick host hand chan text} {
global learn
if {[check_access $hand flags-change] == 2} {
putserv "$learn(method) $nick :You don't have access"
return 0
}
set word [string tolower [lindex $text 0]]
if {$word == ""} {
putserv "$learn(method) $nick :Invalid syntax, use $learn(forget) <word>"
return 0
}
if {[check_word $word] == 2} {
putserv "$learn(method) $nick :Unable to delete, definition not found"
return 0
}
if {[check_lock $word] == 1} {
putserv "$learn(method) $nick :Unable to delete, definition is locked"
return 0
}
set fx1 [open $learn(file) r]
set fx2 [open $learn(tempfile) w]
while {![eof $fx1]} {
set tmp [gets $fx1]
set word_check [lindex $tmp 0]
if {$tmp != ""} {if {[string compare $word $word_check] == 0} {continue} else {puts $fx2 $tmp}}
}
close $fx1 ; close $fx2
exec rm -f $learn(file) ; exec mv $learn(tempfile) $learn(file)
putserv "$learn(method) $nick :\"$word\" deleted from database"
}


proc learn_list {nick host hand chan text} {
global learn
set words "" ; set check 0
set fx [open $learn(file) r]
while {![eof $fx]} {
set tmp [lindex [gets $fx] 0]
set words "$words $tmp"
if {$tmp != ""} {set check 1}
}
close $fx
if {$check == 0} {putserv "$learn(method) $nick :The learn file is empty"} else {putserv "$learn(method) $nick :Learn words: $words"}
}


proc learn_lockwords {nick host hand chan text} {
global learn
if {[check_access $hand owner] == 2} {
putserv "$learn(method) $nick :You don't have access"
return 0
}
set words "" ; set check 0
set fx [open $learn(lockfile) r]
while {![eof $fx]} {
set tmp [gets $fx]
set words "$words $tmp"
if {$tmp != ""} {set check 1}
}
close $fx
if {$check == 0} {putserv "$learn(method) $nick :The lock file is empty"} else {putserv "$learn(method) $nick :Lock words: $words"}
}


proc learn_forceback {nick host hand chan text} {
global learn
if {[check_access $hand owner] == 2} {
putserv "$learn(method) $nick :You don't have access"
return 0
}
putlog "#$hand# forced learn backup"
learn_backup
}

proc learn_backup {} {
global learn
set fx1 [open $learn(file) r]
set fx2 [open $learn(backupfile) w]
while {![eof $fx1]} {
set tmp [gets $fx1]
if {$tmp != ""} {puts $fx2 $tmp}
}
putlog "Learn: backup saved to $learn(backupfile)"
timer $learn(backuptime) learn_backup
close $fx1 ; close $fx2
}


proc learn_view {nick host hand chan text} {
global learn
if {[isvalidchan [string tolower $chan]] == 1} {
putserv "$learn(method) $nick :I can't use learn in this channel"
return 0
}
set word [string tolower [lindex $text 0]]
if {$word == ""} {
putserv "$learn(method) $nick :Invalid syntax, use $learn(view) <word>"
return 0
}
if {[check_word $word] == 2} {
putserv "$learn(method) $nick :The word \"$word\" is unknown to me"
return 0
}
set fx [open $learn(file) r]
while {![eof $fx]} {
set tmp [gets $fx]
if {[string compare $word [lindex $tmp 0]] != 0} {continue}
set i 1
set defs [split [lrange $tmp 1 end] "¦"]
set defi ""
while {1} {
set d [lindex $defs [expr $i-1]]
if {$d == ""} {break}
putserv "$learn(method-def) $chan :$word\002\[\002$i\002\]\002\037:\037 $d"
incr i 1
}
}
close $fx
}


proc learn_view_msg {nick host hand chan text} {
global learn
if {[isvalidchan $chan] == 1} {
putserv "$learn(method) $nick :I can't use learn in this channel"
return 0
}
set word [string tolower [lindex $text 0]]
if {$word == ""} {
putserv "$learn(method) $nick :Invalid syntax, use $learn(view) <word>"
return 0
}
if {[check_word $word] == 2} {
putserv "$learn(method) $nick :The word \"$word\" is unknown to me"
return 0
}
set fx [open $learn(file) r]
while {![eof $fx]} {
set tmp [gets $fx]
if {[string compare $word [lindex $tmp 0]] != 0} {continue}
set i 1
set defs [split [lrange $tmp 1 end] "¦"]
set defi ""
while {1} {
set d [lindex $defs [expr $i-1]]
if {$d == ""} {break}
putserv "$learn(method-def) $nick :$word\002\[\002$i\002\]\002\037:\037 $d"
incr i 1
}
}
close $fx
}


proc learn_del {nick host hand chan text} {
global learn
if {[check_access $hand flags-change] == 2} {
putserv "$learn(method) $nick :You don't have access"
return 0
}
set word [string tolower [lindex $text 0]]
set n [lindex $text 1]
if {$n == ""} {
putserv "$learn(method) $nick :Invalid syntax, use $learn(del) <word> <N>"
return 0
}
if {[check_word $word] == 2} {
putserv "$learn(method) $nick :Word not found please use !learn first"
return 0
}
if {[check_lock $word] == 1} {
putserv "$learn(method) $nick :Unable to delete, word is locked"
return 0
}
set fx1 [open $learn(file) r]
set fx2 [open $learn(tempfile) w]
while {![eof $fx1]} {
set tmp [gets $fx1]
set word_check [lindex $tmp 0]
set i 0
set defs [split [lrange $tmp 1 end] "¦"]
set defi ""
while {1} {
if {[expr $i+1] == $n} {incr i 1 ; continue}
set d [lindex $defs $i]
if {$d == ""} {break}
if {$defi == ""} {set defi $d¦} else {set defi $defi$d¦}
incr i 1
}
if {$tmp != ""} {
if {[string compare $word $word_check] == 0} {puts $fx2 "$word_check $defi"} else {puts $fx2 $tmp}
}
}
close $fx1 ; close $fx2
exec rm -f $learn(file) ; exec mv $learn(tempfile) $learn(file)
putserv "$learn(method) $nick :Definition \"$n\" deleted from \"$word\" if exists"
}


proc learn_insert {nick host hand chan text} {
global learn
if {[check_access $hand flags-change] == 2} {
putserv "$learn(method) $nick :You don't have access"
return 0
}
set word [string tolower [lindex $text 0]]
set definition [lrange $text 1 end]
if {$definition == ""} {
putserv "$learn(method) $nick :Invalid syntax, use $learn(insert) <word> <definition>"
return 0
}
if {[check_word $word] == 2} {
putserv "$learn(method) $nick :Word not found please use !learn first"
return 0
}
if {[check_lock $word] == 1} {
putserv "$learn(method) $nick :Unable to insert, word is locked"
return 0
}
set fx1 [open $learn(file) r]
set fx2 [open $learn(tempfile) w]
while {![eof $fx1]} {
set tmp [gets $fx1]
set word_check [lindex $tmp 0]
if {$tmp != ""} {
if {[string compare $word $word_check] == 0} {puts $fx2 "$tmp$definition ¦"} else {puts $fx2 $tmp}
}
}
close $fx1 ; close $fx2
exec rm -f $learn(file) ; exec mv $learn(tempfile) $learn(file)
putserv "$learn(method) $nick :Definition inserted at the end of word"
}

proc learn_unlock {nick host hand chan text} {
global learn
if {[check_access $hand owner] == 2} {
putserv "$learn(method) $nick :You don't have access"
return 0
}
set word [string tolower [lindex $text 0]]
if {$word == ""} {
putserv "$learn(method) $nick :Invalid syntax, use $learn(unlock) <word>"
return 0
}
if {[check_word $word] == 2} {
putserv "$learn(method) $nick :Unable to lock word, word not found"
return 0
}
if {[check_lock $word] == 2} {
putserv "$learn(method) $nick :Unable to unlock, word is not locked"
return 0
}
set fx1 [open $learn(lockfile) r]
set fx2 [open $learn(tempfile) w]
while {![eof $fx1]} {
set tmp [gets $fx1]
set word_check [lindex $tmp 0]
if {[string compare $word $word_check] == 0} {continue} else {puts $fx2 $tmp}
}
close $fx1 ; close $fx2
exec rm -f $learn(lockfile) ; exec mv $learn(tempfile) $learn(lockfile)
putserv "$learn(method) $nick :\"$word\" unlocked"
}


proc learn_lock {nick host hand chan text} {
global learn
if {[check_access $hand owner] == 2} {
putserv "$learn(method) $nick :You don't have access"
return 0
}
set word [string tolower [lindex $text 0]]
if {$word == ""} {
putserv "$learn(method) $nick :Invalid syntax, use $learn(lock) <word>"
return 0
}
if {[check_word $word] == 2} {
putserv "$learn(method) $nick :Unable to lock definition, not found"
return 0
}
if {[check_lock $word] == 1} {
putserv "$learn(method) $nick :Definition allready locked"
return 0
}
set fx [open $learn(lockfile) a]
puts $fx $word ; close $fx
putserv "$learn(method) $nick :\"$word\" locked"
}



proc learn_misc {nick host hand chan text} {
global learn
if {[check_access $hand owner] == 2} {
putserv "$learn(method) $nick :You don't have access"
return 0
}
putserv "$learn(method) $nick :\002Dekadent Learn $learn(version) misc information\002"
putserv "$learn(method) $nick :The learn file is: \"$learn(file)\", the backup file is: \"$learn(backupfile)\", the learn temp file is \"$learn(tempfile)\", the learn lock file is \"$learn(lockfile)\", the time between each backup is \"$learn(backuptime)\" minutes, the channels that learn views will not appear is/are \"$learn(non-channels)\"."
putserv "$learn(method) $nick :The flags to learn/forget/insert/delete/list words is/are \"$learn(flags-change)\", the flags to lock/unlock/list locked words/force backup is/are \"$learn(owner)\", the method to response when a nick add/insert/delete/forget.... is \"$learn(method)\" to a nick, the method to response to a view is \"$learn(method-def)\" to a channel."
}
proc learn_help {nick host hand chan text} {
global learn
putserv "$learn(method) $nick :\002*** Dekadent Learn $learn(version) help, the help will be showed if you have the access to that command. ***\002"
putserv "$learn(method) $nick :To view a word do: $learn(view) <word>"
if {[check_access $hand flags-change] == 1} {
putserv "$learn(method) $nick :To add a word do: $learn(add) <word> <definition>"
putserv "$learn(method) $nick :To forget a word do: $learn(forget) <word>"
putserv "$learn(method) $nick :To insert a definition to a word do: $learn(insert) <word> <definition>"
putserv "$learn(method) $nick :To delete a definition from one word do: $learn(del) <word> <N>"
putserv "$learn(method) $nick :To see all definied words do: $learn(wordlist)"
}
if {[check_access $hand owner] == 1} {
putserv "$learn(method) $nick :To lock a word do: $learn(lock) <word>"
putserv "$learn(method) $nick :To unlock a locked word do: $learn(unlock) <word>"
putserv "$learn(method) $nick :To list all locked words do: $learn(lockwords)"
putserv "$learn(method) $nick :To force the learn file to be backuped do: $learn(forcebackup)"
putserv "$learn(method) $nick :If word is locked the word can't be deleted or some definition be inserted to the word"
putserv "$learn(method) $nick :To see some misc information do: $learn(misc)"
}
}
Script: Dekadent Learn
Edited by Alchera: Use tags when inserting code into a post (the format bar is right in front of you).[/color]
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Sounds counterproductive, as you'd have to use a pubm bind then check each and every word, not to mention other scripts that use bang(!) chars which would then also be caught by the pubm bind.. Whats so hard about using !command <word> anyway?
l
lebjustice
Voice
Posts: 5
Joined: Sun Jun 17, 2007 11:20 pm

thanks for the fast reply but...

Post by lebjustice »

can the command be !<nospace><word> ? ex: !word
not as !<space><word> ex: ! word
l
lebjustice
Voice
Posts: 5
Joined: Sun Jun 17, 2007 11:20 pm

hey rosc2112 thanks can u help me with this?

Post by lebjustice »

I found this in the forum
how can i add !delcommand and !listcommand and make it active only in that chans i want.

Code: Select all

set cmdsfile "uicn/cmds.txt" 

if {![file exists $cmdsfile]} { 
set fileid [open $cmdsfile w] 
close $fileid 
} { 
source $cmdsfile 
} 

bind pub n !addcommand add:command 

proc add:command {n u h c a} { 
global addedcommands 
set command [lindex [split $a] 0] 
set action [join [lrange [split $a] 1 end]] 
if {[info command added:$command] == ""} { 
set addedcommands($command) $action 
proc added:$command {n u h c a} { 
global addedcommands 
puthelp "privmsg $c :\001ACTION [string map [list %nick [lindex [split $a] 0]] $addedcommands($::lastbind)]\001" 
} 
bind pub - $command added:$command 
save:command $command $action 
puthelp "notice $n :Added add:$command command." 
} { 
puthelp "notice $n :Command added:$command already exists." 
} 
} 

proc save:command {c act} { 
global cmdsfile 
set cmdlist [split [read [set f [open $cmdsfile]]] \n][close $f] 
lappend cmdlist "bind pub - $c added:$c" 
lappend cmdlist "" 
lappend cmdlist "set addedcommands($c){$act}" 
lappend cmdlist "" 
set f [open $cmdsfile w] 
foreach cmd $cmdlist { 
puts $f $cmd 
} 
puts $f [printproc added:$c] 
close $f 
} 

# user's proc from the Tcl faq forum 
proc printproc proc { 
set args {} 
foreach arg [info args $proc] { 
if {[info default $proc $arg val]} { 
lappend args [list $arg $val] 
} { 
lappend args [list $arg] 
} 
} 
list proc $proc $args [info body $proc] 
}
Post Reply