<?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/5427" />

	<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>2003-09-02T21:59:53-04:00</updated>

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

		<entry>
		<author><name><![CDATA[strikelight]]></name></author>
		<updated>2003-09-02T21:59:53-04:00</updated>

		<published>2003-09-02T21:59:53-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26287#p26287</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26287#p26287"/>
		<title type="html"><![CDATA[Working with INI Files]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26287#p26287"><![CDATA[
<blockquote class="uncited"><div>Is that code fine without return's etc?  I think this may be a problem.</div></blockquote>  This question has already been covered in your previous thread found <a href="http://forum.egghelp.org/viewtopic.php?t=5437" class="postlink">here</a>.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2005">strikelight</a> — Tue Sep 02, 2003 9:59 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Darkj]]></name></author>
		<updated>2003-09-02T21:11:05-04:00</updated>

		<published>2003-09-02T21:11:05-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26285#p26285</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26285#p26285"/>
		<title type="html"><![CDATA[Working with INI Files]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26285#p26285"><![CDATA[
<div class="codebox"><p>Code: </p><pre><code>proc parseIni {file} {    array set arr {}    set f [open $file]    while {[gets $f l]&gt;-1} {       set l [string trim $l]       if {[string match {\[*\]} $l]} {          set e [string range $l 1 end-1]      } elseif {[info exists e]&amp;&amp;[string match *?=?* $l]} {          regexp {^([^=]+)=(.+)$} $l a a b          lappend arr($e) [string trim $a] [string trim $b]       }   }    close $f    array get arr } </code></pre></div>Is that code fine without return's etc?  I think this may be a problem.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=3459">Darkj</a> — Tue Sep 02, 2003 9:11 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2003-08-31T21:19:44-04:00</updated>

		<published>2003-08-31T21:19:44-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26103#p26103</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26103#p26103"/>
		<title type="html"><![CDATA[Working with INI Files]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26103#p26103"><![CDATA[
<blockquote class="uncited"><div>That worked perfectly, well, except the auto counter.</div></blockquote>Do you mean the grammatical errors in the line announcing the number of bots online or the fact that my code didn't subtract the bot(s) you're filtering out?<br><br>Here's some code to make the grammar easier:<div class="codebox"><p>Code: </p><pre><code># plural proc...proc plur {num {add s} {add2 ""}} {expr {$num!=1?$add:$add2}}# test...foreach i {0 1 32} {puts "There[plur $i " are" "'s"] currently $i bot[plur $i] online."}# result:There are currently 0 bots online.There's currently 1 bot online.There are currently 32 bots online.</code></pre></div>I'm glad you appreciate my suggestions <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2878">user</a> — Sun Aug 31, 2003 9:19 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Darkj]]></name></author>
		<updated>2003-08-31T21:12:41-04:00</updated>

		<published>2003-08-31T21:12:41-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26102#p26102</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26102#p26102"/>
		<title type="html"><![CDATA[Working with INI Files]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26102#p26102"><![CDATA[
That worked perfectly, well, except the auto counter, but I fixed it up a bit.  Thanks for the help user, just glad someone stuck with me even though it was prolly like talkin to a brick wall.<br><br>Anyways, thanks alot.<br><br>-Darkj<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=3459">Darkj</a> — Sun Aug 31, 2003 9:12 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2003-08-31T20:30:41-04:00</updated>

		<published>2003-08-31T20:30:41-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26101#p26101</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26101#p26101"/>
		<title type="html"><![CDATA[Working with INI Files]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26101#p26101"><![CDATA[
<blockquote class="uncited"><div>Basically I've changed the way I'm doing this<br><br>I'm pulling it out of the INI file and dumping in a tmp file, to make for easy formatting, then the bottom of the script is just outputting the file.<br><br>This bot is only used between 15-20 people on a private network, so I'm not too concerned with cpu etc.</div></blockquote>But 'append'ing/'lappend'ing to a variable would be much easier...and the 3 examples I showed you earlier would just need color codes to be added to produce the exact same output. (saving alot of precious vertical space on your screen while debugging the code ,P)<br><div class="codebox"><p>Code: </p><pre><code>bind pub n !test testproc test {nick uhost hand chan arg} {set defaults {charname none location none action none}array set a [parseIni your.ini]# plural ending (bot(s)) based on the number :Pputserv "PRIVMSG $chan :There are currently [array size a] bot[expr {[array size a]!=1?"s":""}] logged in."foreach bot [lsort -dict [array names a]] {   array set b [concat $defaults $a($bot)]   putserv "PRIVMSG $chan :$bot: ($b(charname)) $b(location) ($b(action))"}}</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2878">user</a> — Sun Aug 31, 2003 8:30 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Darkj]]></name></author>
		<updated>2003-08-31T20:22:11-04:00</updated>

		<published>2003-08-31T20:22:11-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26100#p26100</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26100#p26100"/>
		<title type="html"><![CDATA[Working with INI Files]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26100#p26100"><![CDATA[
Basically I've changed the way I'm doing this<br><br>I'm pulling it out of the INI file and dumping in a tmp file, to make for easy formatting, then the bottom of the script is just outputting the file.<br><br>This bot is only used between 15-20 people on a private network, so I'm not too concerned with cpu etc.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=3459">Darkj</a> — Sun Aug 31, 2003 8:22 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2003-08-31T20:20:07-04:00</updated>

		<published>2003-08-31T20:20:07-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26099#p26099</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26099#p26099"/>
		<title type="html"><![CDATA[Working with INI Files]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26099#p26099"><![CDATA[
get rid of the <div class="codebox"><p>Code: </p><pre><code>if {![string len $line]} continue</code></pre></div> too as you don't need it (like I said before)<br><br>But why are you still insisting on writing/reading the file?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2878">user</a> — Sun Aug 31, 2003 8:20 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Darkj]]></name></author>
		<updated>2003-08-31T20:01:32-04:00</updated>

		<published>2003-08-31T20:01:32-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26098#p26098</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26098#p26098"/>
		<title type="html"><![CDATA[Working with INI Files]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26098#p26098"><![CDATA[
i took that if {$displayname == $nowhere} statement out too<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=3459">Darkj</a> — Sun Aug 31, 2003 8:01 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Darkj]]></name></author>
		<updated>2003-08-31T20:00:32-04:00</updated>

		<published>2003-08-31T20:00:32-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26097#p26097</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26097#p26097"/>
		<title type="html"><![CDATA[Working with INI Files]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26097#p26097"><![CDATA[
<div class="codebox"><p>Code: </p><pre><code>  set fs [open bots.tmp r]   while {[gets $fs line]&gt;-1} {       if {![string len $line]} continue;       set displayname [lindex $line 0]       set botcharname [lindex $line 1]       set botloc [lindex $line 2]       set botact [lrange $line 3 end]       if {$displayname == ""} {         close $fs         return 0       }       putserv "PRIVMSG $mainchanbots :\002$displayname\:\002 \(\0032$botcharname\003\) \0034$botloc\003 \(\0036$botact\003\)"       }     close $fs   }    return 0}</code></pre></div>Hows that?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=3459">Darkj</a> — Sun Aug 31, 2003 8:00 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2003-08-31T19:49:27-04:00</updated>

		<published>2003-08-31T19:49:27-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26096#p26096</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26096#p26096"/>
		<title type="html"><![CDATA[Working with INI Files]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26096#p26096"><![CDATA[
<blockquote class="uncited"><div>How do I fix that so It doesn't leave the file open?</div></blockquote>By closing it before you return <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_razz.gif" width="15" height="15" alt=":P" title="Razz"><br><br>Here's a better while loop (doing the !eof check and reading in one call:<div class="codebox"><p>Code: </p><pre><code>while {[gets $fs line]&gt;-1} {  if {![string len $line]} continue  # this makes it ignore empty lines and just skip to the next  # but you don't need that as you create the file and don't write any  # empty lines to it :)    # insert the rest of your code here}</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2878">user</a> — Sun Aug 31, 2003 7:49 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Darkj]]></name></author>
		<updated>2003-08-31T19:46:30-04:00</updated>

		<published>2003-08-31T19:46:30-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26094#p26094</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26094#p26094"/>
		<title type="html"><![CDATA[Working with INI Files]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26094#p26094"><![CDATA[
<div class="codebox"><p>Code: </p><pre><code>  set fs [open bots.tmp r]     while {![eof $fs]} {      if {![gets $fs line]} {        return 0      } elseif {[lindex $line 2] != $nowhere} {        set displayname [lindex $line 0]        set botcharname [lindex $line 1]        set botloc [lindex $line 2]        set botact [lrange $line 3 end] </code></pre></div>How do I fix that so It doesn't leave the file open?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=3459">Darkj</a> — Sun Aug 31, 2003 7:46 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2003-08-31T19:36:46-04:00</updated>

		<published>2003-08-31T19:36:46-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26093#p26093</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26093#p26093"/>
		<title type="html"><![CDATA[Working with INI Files]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26093#p26093"><![CDATA[
<blockquote class="uncited"><div>Actually, I've kind of gone a different route now, and worked a little with the ini_read and ini_write functions.  Here is my working code now.<br><br>...<br><br>See any typos or mess ups, would be great to know, but this code works exactly the way I want it</div></blockquote>Here's your code with comments added:<div class="codebox"><p>Code: </p><pre><code>proc list_bots {nick uhost hand chan args} {   global nowhere mainchanbots inifilebots# i took the liberty to rewrite this 'if' a bit..just to make it easier to read (the result is the same)  if {$chan != $mainchanbots} {return 0}  set i 0   foreach {name value} [parseIni bots.ini] {     set check [ini_read bots.ini ${name} location]     set displayname [ini_read $inifilebots ${name} display]     set botcharname [ini_read $inifilebots ${name} charname]     set botloc [ini_read $inifilebots ${name} location]     set botact [ini_read $inifilebots ${name} action] # you should open the file outside the foreach loop and close it after the end..no point hammering the poor file that way :P# but why are you writing it to a file in the first place? why not keep the lines in a variable?    set fs [open bots.tmp a+]# this 'string match' should be replaced by a 'string equal' I guess.# Although I don't get the point of ignoring one bot..why is it in the file if you don't want to know about it? And why go through all that hard work in the previous lines just to end up ditching the data gathered?    if {![string match $check $nowhere]} {# here you write it as a string, but you later treat it as a list (using 'lindex' on it when reading it back in)      puts $fs "$displayname $botcharname $botloc $botact"       incr i     }     close $fs   }# the number of bots can be determined without this counter if you use one of the examples from my previous post  if {$i &lt;= 0} {     putserv "PRIVMSG $mainchanbots :\&lt;\0032There are currently\003\0034\002 0 \002\003\0032bots logged in.\003\&gt;"   }   if {$i &gt; 0} {     putserv "PRIVMSG $mainchanbots :\&lt;\0032There are currently\003\0034\002 $i \002\003\0032bot\(s\) logged in.\003\&gt;"   }# using a timer to delete the file doesn't make sense to me...why are you doing it?  utimer 5 deletefile  set fs [open bots.tmp r]     while {![eof $fs]} {      if {![gets $fs line]} {# danger danger! :P by returning at this point you end up leaving the file channel open and eventually your interpreter will hang because of too many open files       return 0# you did this check when creating the file     } elseif {[lindex $line 2] != $nowhere} {# using 'lindex' on a string for the next 4 lines (will cause errors if your data contains special chars like [ and {)       set displayname [lindex $line 0]        set botcharname [lindex $line 1]        set botloc [lindex $line 2]        set botact [lrange $line 3 end] # a little late to do this check now? :P       if {$displayname == ""} {          close $fs          return 0        }         putserv "PRIVMSG $mainchanbots :\002$displayname\:\002 \(\0032$botcharname\003\) \0034$botloc\003 \(\0036$botact\003\)"       }     }   close $fs   return 0}</code></pre></div>I imagine one of my previous examples would gain a very similar result with HUGE cpu savings and no possible errors, so you should consider at least trying one of them <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2878">user</a> — Sun Aug 31, 2003 7:36 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Darkj]]></name></author>
		<updated>2003-08-31T19:15:25-04:00</updated>

		<published>2003-08-31T19:15:25-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26092#p26092</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26092#p26092"/>
		<title type="html"><![CDATA[Working with INI Files]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26092#p26092"><![CDATA[
Actually, I've kind of gone a different route now, and worked a little with the ini_read and ini_write functions.  Here is my working code now.<br><div class="codebox"><p>Code: </p><pre><code>proc list_bots {nick uhost hand chan args} {  global nowhere mainchanbots inifilebots  if {$chan == $mainchanbots} {  set i 0  foreach {name value} [parseIni bots.ini] {     set check [ini_read bots.ini ${name} location]    set displayname [ini_read $inifilebots ${name} display]    set botcharname [ini_read $inifilebots ${name} charname]    set botloc [ini_read $inifilebots ${name} location]    set botact [ini_read $inifilebots ${name} action]    set fs [open bots.tmp a+]    if {![string match $check $nowhere]} {      puts $fs "$displayname $botcharname $botloc $botact"      incr i    }    close $fs  }  if {$i &lt;= 0} {    putserv "PRIVMSG $mainchanbots :\&lt;\0032There are currently\003\0034\002 0 \002\003\0032bots logged in.\003\&gt;"  }  if {$i &gt; 0} {    putserv "PRIVMSG $mainchanbots :\&lt;\0032There are currently\003\0034\002 $i \002\003\0032bot\(s\) logged in.\003\&gt;"  }  utimer 5 deletefile  set fs [open bots.tmp r]    while {![eof $fs]} {     if {![gets $fs line]} {       return 0     } elseif {[lindex $line 2] != $nowhere} {       set displayname [lindex $line 0]       set botcharname [lindex $line 1]       set botloc [lindex $line 2]       set botact [lrange $line 3 end]       if {$displayname == ""} {         close $fs         return 0       }        putserv "PRIVMSG $mainchanbots :\002$displayname\:\002 \(\0032$botcharname\003\) \0034$botloc\003 \(\0036$botact\003\)"       }    }   close $fs  return 0  }}</code></pre></div>See any typos or mess ups, would be great to know, but this code works exactly the way I want it<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=3459">Darkj</a> — Sun Aug 31, 2003 7:15 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2003-08-31T18:38:30-04:00</updated>

		<published>2003-08-31T18:38:30-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26089#p26089</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26089#p26089"/>
		<title type="html"><![CDATA[Working with INI Files]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26089#p26089"><![CDATA[
<blockquote class="uncited"><div>As for my debugging, it doesn't look like an array is going to work for me with the way the INI file is designed</div></blockquote>How about this then?<div class="codebox"><p>Code: </p><pre><code>foreach {name attr} [parseIni your.ini] {array set a $attrputserv "PRIVMSG #chan :$name: ($a(charname)) $a(location) ($a(action))"}</code></pre></div>or if you want them sorted, use an array at the first level too, and sort the names like this:<div class="codebox"><p>Code: </p><pre><code>array set a [parseIni your.ini]foreach bot [lsort -dict [array names a]] {array set b $a($bot)putserv "PRIVMSG #chan :$bot: ($b(charname)) $b(location) ($b(action))"}</code></pre></div>If you can't be certain all the attributes exists for every bot, here's a way to provide default values:<div class="codebox"><p>Code: </p><pre><code>set defaults {charname nonelocation noneaction none}array set a [parseIni your.ini]foreach bot [lsort -dict [array names a]] {array set b [concat $defaults $a($bot)]putserv "PRIVMSG #chan :$bot: ($b(charname)) $b(location) ($b(action))"}</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2878">user</a> — Sun Aug 31, 2003 6:38 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Darkj]]></name></author>
		<updated>2003-08-31T13:30:28-04:00</updated>

		<published>2003-08-31T13:30:28-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26059#p26059</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26059#p26059"/>
		<title type="html"><![CDATA[Working with INI Files]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26059#p26059"><![CDATA[
Well, actually, I asked how to output an INI file (as seen above) to IRC, i just prefered the format of 2 bots per line, whether it still be 10 bots listed.<br><br>As for my debugging, it doesn't look like an array is going to work for me with the way the INI file is designed<br><br>My ideal method is:<br><br>[BotName]<br>charname=charname<br>location=location<br>action=action<br><br>the [BotName] being the actual bots name on IRC, char name is the character name in game.  But in order for an array to work it looks like, is it needs some general same thing to look for.  Which is where I'm stuck, I just wanted a simple list script, didn't realize it was gonna get this complicated.<br><br>EDIT:  In order to use ini_write properly, the [] sections need to be different names.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=3459">Darkj</a> — Sun Aug 31, 2003 1:30 pm</p><hr />
]]></content>
	</entry>
	</feed>
