## FluxLearn.tcl (whatis.tcl by, gisselle, modded for eggdrop 1.1.5) By Reflux
##
## to get the original whatis tcl goto,
## "ftp.sodre.net/pub/eggdrop/scripts0.9/tcl.whatis.gz"
##
## VR - fixed !learn - if an entry exists
##
## Dolphin **Fixed** $handle/$nick bug
## fixed and version change to fluxlearn 1.5 by ITPro from #oldmemphis undernet
##
## Begin Global Sets
set FL_version "1.5 (08-23-01)"; # What version of FluxLearn is this?
set whatis_file "explain.dat"; # whatis data file
set req_flags ""; # Flags to Define something
set rem_flags "o"; # Flags required to set forget something
set explain_e "!explain"; # Text to trigger explain event
set learn_e "!learn"; # Text to trigger learn event
set remove_e "!forget"; # Text to trigger forget event
set whoset_e "!whoset"; # Text to trigger whoset event
set pub_explain 1; # notify channel on explain [0/1]
set pub_learn 0; # notify channel on learn [0/1]
set pub_remove 0; # notify channel on remove [0/1]
set pub_whoset 0; # notify channel on whoset [0/1]
set bot_log 1; # Log stuff to the bot's log file [0/1]
## End of Global Sets
## Do we need a new database file? if yes, make one
if {![file exists $whatis_file]} {
set WhatisFile [open $whatis_file w]
puts $WhatisFile "$explain_e = default_setting well you obviously know how to use it..."
close $WhatisFile
}
## Begin Procs
## Retrieves the definition for an entry, or returns <not defined> if the
## entry does not exist...
proc GetEntry {entry} {
global whatis_file
set WhatisFile [open $whatis_file r]
set retval "<not defined>"
while {![eof $WhatisFile]} {
set CurEntry "[gets $WhatisFile]"
set EntryName [string tolower [lindex $CurEntry 0]]
if {$EntryName==$entry} {
set retval "[lrange $CurEntry 3 end]"
}
}
close $WhatisFile
return $retval
}
## Retrieves who set an entry, or returns <not defined> if the
## entry does not exist...
proc GetWhoEntry {entry} {
global whatis_file
set WhatisFile [open $whatis_file r]
set retval "<not defined>"
while {![eof $WhatisFile]} {
set CurEntry "[gets $WhatisFile]"
set EntryName [string tolower [lindex $CurEntry 0]]
if {$EntryName==$entry} {
set retval "[lrange $CurEntry 2 2]"
}
}
close $WhatisFile
return $retval
}
## Removes an entry from the database
proc DeleteEntry {entry} {
global whatis_file rem_flags
set WhatisFile [open $whatis_file r]
while {![eof $WhatisFile]} {
set CurLine "[gets $WhatisFile]"
if {[lindex $CurLine 0]!=$entry} {lappend WhatisList $CurLine}
}
close $WhatisFile
set WhatisFile [open $whatis_file w]
foreach CurLine $WhatisList {
if {$CurLine!=""} {puts $WhatisFile $CurLine}
}
close $WhatisFile
return 1
}
## Adds an entry to the database
proc SetEntry {entry definition} {
global whatis_file
set entry [string trim [string tolower $entry] \=]
set WhatisFile [open $whatis_file r]
while {![eof $WhatisFile]} {
set CurLine "[gets $WhatisFile]"
if {[lindex $CurLine 0]!=$entry} {
lappend WhatisList $CurLine
}
}
close $WhatisFile
set WhatisFile [open $whatis_file w]
foreach CurLine $WhatisList {
if {$CurLine!=""} {puts $WhatisFile $CurLine}
}
puts $WhatisFile "$entry = $definition"
close $WhatisFile
return 1
}
## explains an entry on the explain event
proc pubWhatis {nick host handle chan text} {
global channel explain_e learn_e remove_e whoset_e pub_explain
if {$text==""} {
putserv "NOTICE $nick :usage: $explain_e <entry>"
return 0
}
set lookup [string trim [string tolower [lindex $text 0]] ?]
if {$pub_explain == 1} {
putserv "NOTICE $chan :\002$lookup\002 == [GetEntry $lookup]"
}
if {$pub_explain == 0} {
putserv "NOTICE $nick :$lookup == [GetEntry $lookup]"
}
return 1
}
## returns whoset an entry on the whoset event
proc pubWhoset {nick host handle chan text} {
global channel explain_e learn_e remove_e whoset_e pub_whoset
if {$text==""} {
putserv "NOTICE $nick :usage: $whoset_e <entry>"
return 0
}
set lookup [string trim [string tolower [lindex $text 0]] ?]
if {$pub_whoset == 0} {
putserv "NOTICE $nick :$lookup Was set by - [GetWhoEntry $lookup]"
}
if {$pub_whoset == 1} {
putserv "NOTICE $chan :$lookup Was set by - [GetWhoEntry $lookup]"
}
return 1
}
## sets an entry on the set event
proc pubWset {nick host handle chan text} {
global req_flags channel explain_e learn_e bot_log pub_learn remove_e
set entry [string tolower [lindex $text 0]]
set def "[lrange $text 1 end]"
if {$def==""} {
putserv "NOTICE $nick :usage: $learn_e <entry> <definition>"
return 0
}
if {![matchattr $handle $req_flags]} {
putserv "NOTICE $nick :you do not have permission to define stuff"
if {$bot_log == 1 } {
putlog "$nick doesn't have $req_flags, so they couldn't define $entry"
}
return 0
}
if {[GetEntry $entry] != "<not defined>"} {
putserv "NOTICE $nick :$entry, is allready defined, use $remove_e to erase it!"
return 1
}
SetEntry $entry "$nick!$host-$chan $def"
if {$pub_learn ==1 } {
putserv "NOTICE $chan :Now: $entry == [GetEntry $entry]"
}
if {$pub_learn == 0 } {
putserv "NOTICE $nick :Now: $entry == [GetEntry $entry]"
}
return 1
}
## Removes an entry on the remove event
proc pubRemove {nick host handle chan text} {
global rem_flags channel explain_e learn_e remove_e whoset_e pub_remove bot_log
set entry [string tolower [lindex $text 0]]
if {$entry==""} {return 0}
if {![matchattr $handle $rem_flags]} {
putserv "NOTICE $nick :you do not have permission to delete stuff"
if {$bot_log==1}{
putlog "$nick doesn't have $rem_flags, so they couldn't delete $entry"
}
return 0
}
DeleteEntry $entry
if {$pub_remove == 1} {
putserv "NOTICE $chan :$nick has deleted $entry"
}
if {$pub_remove == 0} {
putserv "NOTICE $nick :you have deleted $entry"
}
return 1
}
proc pubVersion {nick host handle chan text} {
global FL_version
putserv "NOTICE $chan :I am using, FluxLearn $FL_version, By Reflux"
}
## End Proc
## Begin Binds
bind pub - "$explain_e" pubWhatis
bind pub - "$learn_e" pubWset
bind pub - "$remove_e" pubRemove
bind pub - "$whoset_e" pubWhoset
bind pub = "!fluxlearn" pubVersion
## End Binds
putlog "FluxLearn version $FL_version By Reflux -LOADED- fixed by ITpro #oldmemphis undernet"
###EOF