<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forum.eggheads.org/app.php/feed/topic/17617" />

	<title>egghelp/eggheads community</title>
	<subtitle>Discussion of eggdrop bots, shell accounts and tcl scripts.</subtitle>
	<link href="https://forum.eggheads.org/index.php" />
	<updated>2010-03-01T04:36:59-04:00</updated>

	<author><name><![CDATA[egghelp/eggheads community]]></name></author>
	<id>https://forum.eggheads.org/app.php/feed/topic/17617</id>

		<entry>
		<author><name><![CDATA[arfer]]></name></author>
		<updated>2010-03-01T04:36:59-04:00</updated>

		<published>2010-03-01T04:36:59-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=92312#p92312</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=92312#p92312"/>
		<title type="html"><![CDATA[Need a !learn Script with wildcard search]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=92312#p92312"><![CDATA[
Modification to the above script (adding !facts command) plus some examples on how to use the script<br><div class="codebox"><p>Code: </p><pre><code># learn.tcl# to add a fact and definition in learn.txt# you must use -&gt; shown in the syntax below to seperate the fact from the definition# !learn fact -&gt; definition# to recall the definition for fact# firstly tries an exact match then the smallest partial match beginning with fact# !recall fact# to remove any record exactly matching fact from learn.txt# !unlearn factbind PUB - !facts pLearnFactsbind PUB - !learn pLearnLearnbind PUB - !recall pLearnRecallbind PUB - !unlearn pLearnUnlearnset vLearnVersion 2.0proc pLearnError {number nick chan {arg1 ""}} {    set prefix (\00304$nick\003)    switch -- $number {        01 {set output "Incorrect syntax, use \00312!learn fact -&gt; definition\003"}        02 {set output "A definition already exists \00312$arg1\003"}        03 {set output "Nothing found for \00312$arg1\003"}        04 {set output "The characters \00312-&gt;\003 can only be used once to seperate the fact from the definition"}        05 {set output "Incorrect syntax, use \00312!facts\003 without additional arguments"}        06 {set output "No facts currently in the database"}        default {}    }    putserv "PRIVMSG $chan :$prefix $output"    return 0}proc pLearnFacts {nick uhost hand chan text} {    global vLearnData    if {[llength [split [string trim $text]]] == 0} {        pLearnRead        if {([info exists vLearnData]) &amp;&amp; ([llength $vLearnData] &gt; 0)} {            pLearnOutput 05 $nick $chan [llength $vLearnData]        } else {pLearnError 06 $nick $chan}        unset -nocomplain -- vLearnData    } else {pLearnError 05 $nick $chan}    return 0}proc pLearnLearn {nick uhost hand chan text} {    global vLearnData    set record [regsub -all -- {[\s]{2,}} [string trim $text] { }]    if {[regexp -- {^(.+) -&gt; } $record -&gt; fact]} {        if {[regexp -all -- {-&gt;} $record] == 1} {            pLearnRead            if {[set found [pLearnSearchFull $fact]] == 0} {                pLearnWrite $record                pLearnOutput 01 $nick $chan $record            } else {pLearnError 02 $nick $chan [lindex $found 1]}            unset -nocomplain -- vLearnData        } else {pLearnError 04 $nick $chan}    } else {pLearnError 01 $nick $chan}    return 0}proc pLearnOutput {number nick chan {arg1 ""}} {    set prefix (\00303$nick\003)    switch -- $number {        01 {set output "Learnt \00312$arg1\003"}        02 {set output "Found full match \00312$arg1\003"}        03 {set output "Found partial match \00312$arg1\003"}        04 {set output "Unlearnt \00312$arg1\003"}        05 {set output "Current database size \00312$arg1\003 fact(s)"}        default {}    }    putserv "PRIVMSG $chan :$prefix $output"    return 0}proc pLearnRead {} {    global vLearnData    if {[file exists learn.txt]} {        set fp [open learn.txt r]        set vLearnData [split [read -nonewline $fp] \n]        close $fp    }    return 0}proc pLearnRecall {nick uhost hand chan text} {    global vLearnData    set fact [regsub -all -- {[\s]{2,}} [string trim $text] { }]    pLearnRead    if {[set result [pLearnSearchFull $fact]] != 0} {        pLearnOutput 02 $nick $chan [lindex $result 1]    } elseif {[set result [pLearnSearchPartial $fact]] != 0} {        pLearnOutput 03 $nick $chan $result    } else {        pLearnError 03 $nick $chan $fact    }    unset -nocomplain -- vLearnData    return 0}proc pLearnSearchFull {fact} {    global vLearnData    if {([info exists vLearnData]) &amp;&amp; ([llength $vLearnData] &gt; 0)} {        for {set position 0} {$position &lt; [llength $vLearnData]} {incr position} {            if {[string match -nocase "$fact -&gt; *" [lindex $vLearnData $position]]} {                set found [list $position [lindex $vLearnData $position]]                break            }        }    }    if {[info exists found]} {return $found} else {return 0}}proc pLearnSearchPartial {fact} {    global vLearnData    if {([info exists vLearnData]) &amp;&amp; ([llength $vLearnData] &gt; 0)} {        set vLearnData [lsort -increasing $vLearnData]        foreach record $vLearnData {            if {[string match -nocase "$fact* -&gt; *" $record]} {                set found $record                break            }        }    }    if {[info exists found]} {return $found} else {return 0}}proc pLearnUnlearn {nick uhost hand chan text} {    global vLearnData    set fact [regsub -all -- {[\s]{2,}} [string trim $text] { }]    pLearnRead    if {[set found [pLearnSearchFull $fact]] != 0} {        set vLearnData [lreplace $vLearnData [lindex $found 0] [lindex $found 0]]         set fp [open learn.txt w]        if {[llength $vLearnData] != 0} {            puts $fp [join $vLearnData \n]        }        close $fp        pLearnOutput 04 $nick $chan [lindex $found 1]    } else {pLearnError 03 $nick $chan $fact}    unset -nocomplain -- vLearnData    return 0}proc pLearnWrite {record} {    set fp [open learn.txt a]    puts $fp $record    close $fp    return 0}putlog "learn.tcl version $vLearnVersion loaded"# eof</code></pre></div><br><span style="text-decoration:underline">The command <strong class="text-strong">!facts</strong> will output the currect database size</span><br><br>&lt;@arfer&gt; !facts<br>&lt;@osmosis&gt; (<span style="color:red">arfer</span>) No facts currently in the database<br><br><span style="text-decoration:underline">The command <strong class="text-strong">!facts</strong> is used without additional arguments</span><br><br>&lt;@arfer&gt; !facts 1<br>&lt;@osmosis&gt; (<span style="color:red">arfer</span>) Incorrect syntax, use <span style="color:blue">!facts</span> without additional arguments<br><br><br><span style="text-decoration:underline">The command <strong class="text-strong">!learn fact -&gt; definition</strong> will add a fact (and its definition) to the database</span><br><br>&lt;@arfer&gt; !learn The Usual Suspects -&gt; A film with Kevin Spacey and Jeff Bridges <br>&lt;@osmosis&gt; (<span style="color:green">arfer</span>) Learnt <span style="color:blue">The Usual Suspects -&gt; A film with Kevin Spacey and Jeff Bridges</span><br><br>&lt;@arfer&gt; !facts<br>&lt;@osmosis&gt; (<span style="color:green">arfer</span>) Current database size <span style="color:blue">1</span> fact(s)<br><br><br><span style="text-decoration:underline">The same <strong class="text-strong">exact</strong> fact cannot be duplicated in the database, even with a different definition</span><br><br>&lt;@arfer&gt; !learn The Usual Suspects -&gt; whatever<br>&lt;@osmosis&gt; (<span style="color:red">arfer</span>) A definition already exists <span style="color:blue">The Usual Suspects -&gt; A film with Kevin Spacey and Jeff Bridges</span><br><br><br><span style="text-decoration:underline">The above is true irrepective of the case</span><br><br>&lt;@arfer&gt; !learn THE uSUal SUSPECts -&gt; whatever<br>&lt;@osmosis&gt; (<span style="color:red">arfer</span>) A definition already exists <span style="color:blue">The Usual Suspects -&gt; A film with Kevin Spacey and Jeff Bridges</span><br><br><br><span style="text-decoration:underline">Inexact facts, even with the same definition, would not be considered duplicates</span><br><br>&lt;@arfer&gt; !learn Usual Suspects -&gt; A film with Kevin Spacey and Jeff Bridges <br>&lt;@osmosis&gt; (<span style="color:green">arfer</span>) Learnt <span style="color:blue">Usual Suspects -&gt; A film with Kevin Spacey and Jeff Bridges</span><br><br>&lt;@arfer&gt; !facts<br>&lt;@osmosis&gt; (<span style="color:green">arfer</span>) Current database size <span style="color:blue">2</span> fact(s)<br><br><br><span style="text-decoration:underline">The command <strong class="text-strong">!learn fact -&gt; definition</strong> must be used <strong class="text-strong">exactly</strong> as shown, with the characters <strong class="text-strong">" -&gt; "</strong> seperating the fact from the definition</span><br><br>&lt;@arfer&gt; !learn K-PAX-&gt; A film with Kevin Spacey<br>&lt;@osmosis&gt; (<span style="color:red">arfer</span>) Incorrect syntax, use <span style="color:blue">!learn fact -&gt; definition</span><br><br>&lt;@arfer&gt; !learn K-PAX -&gt;A film with Kevin Spacey<br>&lt;@osmosis&gt; (<span style="color:red">arfer</span>) Incorrect syntax, use <span style="color:blue">!learn fact -&gt; definition</span><br><br>&lt;@arfer&gt; !learn K-PAX, A film with Kevin Spacey<br>&lt;@osmosis&gt; (<span style="color:red">arfer</span>) Incorrect syntax, use <span style="color:blue">!learn fact -&gt; definition</span><br><br>&lt;@arfer&gt; !learn K-PAX -&gt; A film with Kevin Spacey<br>&lt;@osmosis&gt; (<span style="color:green">arfer</span>) Learnt <span style="color:blue">K-PAX -&gt; A film with Kevin Spacey</span><br><br>&lt;@arfer&gt; !facts<br>&lt;@osmosis&gt; (<span style="color:green">arfer</span>) Current database size <span style="color:blue">3</span> fact(s)<br><br><br><span style="text-decoration:underline">The characters <strong class="text-strong">-&gt;</strong> cannot be used elsewhere in the <strong class="text-strong">!learn</strong> command, within the fact or definition</span><br><br>&lt;@arfer&gt; !learn Elephant -&gt; A large mammal -&gt; African or Asian varieties exist<br>&lt;@osmosis&gt; (<span style="color:red">arfer</span>) The characters <span style="color:blue">-&gt;</span> can only be used once to seperate the fact from the definition<br><br><br><span style="text-decoration:underline">The command <strong class="text-strong">!unlearn fact</strong> is used to remove the fact <strong class="text-strong">exactly, irrespective of case</strong></span><br><br>&lt;@arfer&gt; !unlearn usuaL<br>&lt;@osmosis&gt; (<span style="color:red">arfer</span>) Nothing found for <span style="color:blue">usuaL</span><br><br>&lt;@arfer&gt; !unlearn usuaL suspects<br>&lt;@osmosis&gt; (<span style="color:green">arfer</span>) Unlearnt <span style="color:blue">Usual Suspects -&gt; A film with Kevin Spacey and Jeff Bridges</span><br><br>&lt;@arfer&gt; !facts<br>&lt;@osmosis&gt; (<span style="color:green">arfer</span>) Current database size <span style="color:blue">2</span> fact(s)<br><br><br><span style="text-decoration:underline">The command <strong class="text-strong">!recall fact</strong> will look for an <strong class="text-strong">exact match, irrerspective of case</strong>, or if not found the smallest partial match beginning with fact</span><br><br>&lt;@arfer&gt; !recall k-PAx<br>&lt;@osmosis&gt; (<span style="color:green">arfer</span>) Found full match <span style="color:blue">K-PAX -&gt; A film with Kevin Spacey</span><br><br>&lt;@arfer&gt; !recall k<br>&lt;@osmosis&gt; (<span style="color:green">arfer</span>) Found partial match<span style="color:blue"> K-PAX -&gt; A film with Kevin Spacey</span><br><br><br><span style="text-decoration:underline">The command <strong class="text-strong">!recall fact</strong> will not find anything smaller than the specified fact</span><br><br>&lt;@arfer&gt; !recall k-PAx film<br>&lt;@osmosis&gt; (<span style="color:red">arfer</span>) Nothing found for <span style="color:blue">k-PAx film</span><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=5705">arfer</a> — Mon Mar 01, 2010 4:36 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[shixxor]]></name></author>
		<updated>2010-02-28T11:48:15-04:00</updated>

		<published>2010-02-28T11:48:15-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=92285#p92285</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=92285#p92285"/>
		<title type="html"><![CDATA[Need a !learn Script with wildcard search]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=92285#p92285"><![CDATA[
YEAH thx!!! ill try it out...<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=11119">shixxor</a> — Sun Feb 28, 2010 11:48 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[arfer]]></name></author>
		<updated>2010-03-01T02:15:22-04:00</updated>

		<published>2010-02-28T11:46:45-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=92284#p92284</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=92284#p92284"/>
		<title type="html"><![CDATA[Need a !learn Script with wildcard search]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=92284#p92284"><![CDATA[
The following script should do the trick from what limited amount of testing I've done.<br><br>I do not feel it is suitable for a very large database of definitions due to the search methods employed. For one thing I would have preferred to use lsearch for a case insensitive seach of the existing records rather than iterating through them and using string match (-nocase option is not available for lsearch with Tcl versions before 8.5, which still applies to many bot installations).<br><br>In any case, a better, more comprehensive script would use a database engine such as mysql.<br><br>To use the script below, the output channel must permit text formatting such as colors.<br><div class="codebox"><p>Code: </p><pre><code># learn.tcl# to add a fact and definition in learn.txt# you must use -&gt; shown in the syntax below to seperate the fact from the definition# !learn fact -&gt; definition# to recall the definition for fact# firstly tries an exact match then the smallest partial match beginning with fact# !recall fact# to remove any record exactly matching fact from learn.txt# !unlearn factbind PUB - !learn pLearnLearnbind PUB - !recall pLearnRecallbind PUB - !unlearn pLearnUnlearnproc pLearnError {number nick chan {arg1 ""}} {    set prefix (\00304$nick\003)    switch -- $number {        01 {set output "Incorrect syntax, use \00312!learn fact -&gt; definition\003"}        02 {set output "A definition already exists \00312$arg1\003"}        03 {set output "Nothing found for \00312$arg1\003"}        04 {set output "The characters \00312-&gt;\003 can only be used once to seperate the fact from the definition"}        default {}    }    putserv "PRIVMSG $chan :$prefix $output"    return 0}proc pLearnLearn {nick uhost hand chan text} {    global vLearnData    set record [regsub -all -- {[\s]{2,}} [string trim $text] { }]    if {[regexp -- {^(.+) -&gt; } $record -&gt; fact]} {        if {[regexp -all -- {-&gt;} $record] == 1} {            pLearnRead            if {[set found [pLearnSearchFull $fact]] == 0} {                pLearnWrite $record                pLearnOutput 01 $nick $chan $record            } else {pLearnError 02 $nick $chan [lindex $found 1]}            unset -nocomplain -- vLearnData        } else {pLearnError 04 $nick $chan}    } else {pLearnError 01 $nick $chan}    return 0}proc pLearnOutput {number nick chan {arg1 ""}} {    set prefix (\00303$nick\003)    switch -- $number {        01 {set output "Learnt \00312$arg1\003"}        02 {set output "Found full match \00312$arg1\003"}        03 {set output "Found partial match \00312$arg1\003"}        04 {set output "Unlearnt \00312$arg1\003"}        default {}    }    putserv "PRIVMSG $chan :$prefix $output"    return 0}proc pLearnRead {} {    global vLearnData    if {[file exists learn.txt]} {        set fp [open learn.txt r]        set vLearnData [split [read -nonewline $fp] \n]        close $fp    }    return 0}proc pLearnRecall {nick uhost hand chan text} {    global vLearnData    set fact [regsub -all -- {[\s]{2,}} [string trim $text] { }]    pLearnRead    if {[set result [pLearnSearchFull $fact]] != 0} {        pLearnOutput 02 $nick $chan [lindex $result 1]    } elseif {[set result [pLearnSearchPartial $fact]] != 0} {        pLearnOutput 03 $nick $chan $result    } else {        pLearnError 03 $nick $chan $fact    }    unset -nocomplain -- vLearnData    return 0}proc pLearnSearchFull {fact} {    global vLearnData    if {([info exists vLearnData]) &amp;&amp; ([llength $vLearnData] &gt; 0)} {        for {set position 0} {$position &lt; [llength $vLearnData]} {incr position} {            if {[string match -nocase "$fact -&gt; *" [lindex $vLearnData $position]]} {                set found [list $position [lindex $vLearnData $position]]                break            }        }    }    if {[info exists found]} {return $found} else {return 0}}proc pLearnSearchPartial {fact} {    global vLearnData    if {([info exists vLearnData]) &amp;&amp; ([llength $vLearnData] &gt; 0)} {        set vLearnData [lsort -increasing $vLearnData]        foreach record $vLearnData {            if {[string match -nocase "$fact* -&gt; *" $record]} {                set found $record                break            }        }    }    if {[info exists found]} {return $found} else {return 0}}proc pLearnUnlearn {nick uhost hand chan text} {    global vLearnData    set fact [regsub -all -- {[\s]{2,}} [string trim $text] { }]    pLearnRead    if {[set found [pLearnSearchFull $fact]] != 0} {        set vLearnData [lreplace $vLearnData [lindex $found 0] [lindex $found 0]]         set fp [open learn.txt w]        if {[llength $vLearnData] != 0} {            puts $fp [join $vLearnData \n]        }        close $fp        pLearnOutput 04 $nick $chan [lindex $found 1]    } else {pLearnError 03 $nick $chan $fact}    unset -nocomplain -- vLearnData    return 0}proc pLearnWrite {record} {    set fp [open learn.txt a]    puts $fp $record    close $fp    return 0}putlog "learn.tcl loaded"# eof</code></pre></div>** Edit** slight modification to code 01/03/10 6:15 GMT, to ensure that a space is needed either side of the -&gt; characters in items to learn<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=5705">arfer</a> — Sun Feb 28, 2010 11:46 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[shixxor]]></name></author>
		<updated>2010-02-26T17:47:02-04:00</updated>

		<published>2010-02-26T17:47:02-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=92259#p92259</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=92259#p92259"/>
		<title type="html"><![CDATA[Need a !learn Script with wildcard search]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=92259#p92259"><![CDATA[
Hi community,<br><br>I have had a look at all of the dictionary/learn/info scripts but I didnt found one that fits my special need.<br><br>I want an info script that helps ppl out as they call i.e. "!info test" then it posts its definition.... nothing special here but:<br><br>i need this to output the word even if its not typed completely like for example i add the word "minority report" and now i need the script to post the whole description of "minority report" when users just type "!info minor" or "!info mino"<br><br>i must also be able to put spaces into the keywords to learn like: !learn add "minority report" "A movie by steven spielberg"<br><br>It would we very very cool if u could recommend me a script that does that or if u could tell me how to modify an existing one...<br><br>Thank you very much in advance!<br><br>greetz,<br>Stefan<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=11119">shixxor</a> — Fri Feb 26, 2010 5:47 pm</p><hr />
]]></content>
	</entry>
	</feed>
