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

	<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>2007-06-24T07:08:36-04:00</updated>

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

		<entry>
		<author><name><![CDATA[awyeah]]></name></author>
		<updated>2007-06-24T07:08:36-04:00</updated>

		<published>2007-06-24T07:08:36-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=73863#p73863</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=73863#p73863"/>
		<title type="html"><![CDATA[Deleting a line from a file - problem with special chars]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=73863#p73863"><![CDATA[
Thanks for the help. I was able to solve the problem, using string match instead of lsearch.<br><br>The only thing to be done was to split the input argument and to use lindex for string equal with the nick:chan variable.<br><br>For the second part to delete a line, lists have to be used. So I converted the match into a string, and then split the list and also split the match when using lsearch.<br><br>Basically the filter was causing the problem, which I was able to solve using the split, join and string tolower commands.<br><br>The code to one of the working procs:<br><div class="codebox"><p>Code: </p><pre><code>proc aov:delete {nick uhost hand chan arg} { global aov sov set arg [split $arg] set chan [string tolower $chan] if {$arg == ""} { putserv "PRIVMSG $chan :Usage: !delaov &lt;nick&gt;"; return 0 }  set fp [open $sov r+]  set data [read -nonewline $fp]  close $fp  set sovlist [split $data "\n"]  set fp [open $aov r+]  set data [read -nonewline $fp]  close $fp  set aovlist [split $data "\n"]  #check if user has access level sov or founder  if {[matchattr $hand mn|mn $chan]} { set founder:ok 1 }  foreach person $sovlist {   if {[string equal -nocase "$nick:$chan" $person]} {    set sov:ok 1; break    }  }  foreach person $aovlist {   if {[string equal -nocase "$nick:$chan" $person]} {    set aov:ok 1; break    }  }  #if access level not sov or founder stop  if {![info exists founder:ok] || ![info exists sov:ok] || ![info exists aov:ok]} {   putserv "NOTICE $nick :You do not have access to modify the AOv list of $chan."   return 0  }  #check if access level is aov  foreach person $aovlist {   if {[string equal -nocase "$nick:$chan" $person]} {    set aov:user 1; break    }  }  #user has aov access  if {[info exists aov:user]} {   #if argument contains same nick as user   if {[string equal -nocase "[lindex $arg 0]:$chan" $nick:$chan]} {    #del nick from aov list    set user [string tolower [lindex $arg 0]]:$chan    set i [lsearch -exact [split [string tolower $aovlist]] [split $user]]    set fd [open $aov w+]    puts -nonewline $fd [join [lreplace $aovlist $i $i] "\n"]    close $fd    putserv "PRIVMSG $chan :[lindex $arg 0] has been successfully removed from the AOv list of $chan."    utimer 2 [list aov:on:del [lindex $arg 0] $chan]    return 0   } else {    putserv "NOTICE $nick :You do not have access to modify the AOv list of $chan."    return 0    }  }  #check if user is in sov or founder  foreach person $sovlist {   if {[string equal -nocase "$nick:$chan" $person]} {    set sov:found 1; break    }  }  #if user has sov or founder access level  if {[info exists sov:found] || [matchattr $hand mn|mn $chan]} {  #check if aov is in list or not   foreach person $aovlist {    if {[string equal -nocase "[lindex $arg 0]:$chan" $person]} {    set aov:found 1; break    }   }  #if aov is not in list stop  if {![info exists aov:found]} {   putserv "PRIVMSG $chan :[lindex $arg 0] was not found in the AOv list of $chan."   return 0  #if aov is in list then delete  } else {   set user [string tolower [lindex $arg 0]]:$chan   set i [lsearch -exact [split [string tolower $aovlist]] [split $user]]   set fd [open $aov w+]   puts -nonewline $fd [join [lreplace $aovlist $i $i] "\n"]   close $fd   putserv "PRIVMSG $chan :[lindex $arg 0] has been successfully removed from the AOv list of $chan."   utimer 2 [list aov:on:del [lindex $arg 0] $chan]   return 0  } }}</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=4875">awyeah</a> — Sun Jun 24, 2007 7:08 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[awyeah]]></name></author>
		<updated>2007-06-17T03:59:28-04:00</updated>

		<published>2007-06-17T03:59:28-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=73613#p73613</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=73613#p73613"/>
		<title type="html"><![CDATA[Deleting a line from a file - problem with special chars]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=73613#p73613"><![CDATA[
But here I am not using string match, I am using lsearch. So u mean instead of lsearch I should use string match/equal with a foreach loop?<br><br>Something like this is it?<div class="codebox"><p>Code: </p><pre><code>set arg [split $arg]set fp [open $sov r+] set data [read -nonewline $fp] close $fp set list [split [string map {\\ \\\\ [ \\\[ ] \\\] \{ \\\{ \} \\\}} [string tolower $data]]]foreach person $list {if {[string match -nocase *$person* [lindex $arg 0]:$chan]} { set matchfound 1; break }}###OR###set arg [split $arg]set fp [open $sov r+] set data [read -nonewline $fp] close $fp set list [split [string map {\\ \\\\ [ \\\[ ] \\\] \{ \\\{ \} \\\}} [string tolower $data]]]if {[string match -nocase *[lindex $arg 0]:$chan* $list]} { #do stuff}</code></pre></div>Okay, I'll give it a go, thanks!<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=4875">awyeah</a> — Sun Jun 17, 2007 3:59 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Sir_Fz]]></name></author>
		<updated>2007-06-16T21:07:33-04:00</updated>

		<published>2007-06-16T21:07:33-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=73603#p73603</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=73603#p73603"/>
		<title type="html"><![CDATA[Deleting a line from a file - problem with special chars]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=73603#p73603"><![CDATA[
You have problem with using strings and lists. You're creating a list called $list and then you apply [string tolower] over it - bad idea. How about:<div class="codebox"><p>Code: </p><pre><code>set list [split [string map {\\ \\\\ [ \\\[ ] \\\] \{ \\\{ \} \\\}} [string tolower $data]]]</code></pre></div>and now you have a list of lower-case elements.<br><br>Hint: Apply the string match over the elements you want to use in the &lt;match&gt; and not over the string that you're matching from. (i.e. string match &lt;match&gt; &lt;match-string&gt;) apply the string map on &lt;match&gt;.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=3085">Sir_Fz</a> — Sat Jun 16, 2007 9:07 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[awyeah]]></name></author>
		<updated>2007-06-16T16:19:53-04:00</updated>

		<published>2007-06-16T16:19:53-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=73596#p73596</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=73596#p73596"/>
		<title type="html"><![CDATA[Deleting a line from a file - problem with special chars]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=73596#p73596"><![CDATA[
1) First I used split on $arg to convert it into a list.<br>2) Then and the user i want to add, delete or even match in the database (list), i convert that into a string either by using split or just even by string tolower (when im using lsearch with the option -exact to match the element in the list -- so should be in the same case).<br><br>But it still doesn't seem to work. When I try to delete a nick with a special character, say [, ] etc it will just delete all the users in the database and generate and empty text file.<br><br>I think maybe there is a problem maybe with my proc which is deleting the users from the database then maybe (aov:del). Can anyone have a look and tell me where the problem might be maybe, or is it still the special characters? I've used join and split as instructed and even user a filter before for special characters (string map, regsub). Thanks!<br><br>Here is the code:<div class="codebox"><p>Code: </p><pre><code>proc aov:add {nick uhost hand chan arg} { global aov sov set arg [split $arg] if {$arg != ""} {  set fp [open $sov r+]  set data [read -nonewline $fp]  close $fp  set list [split $data "\n"]  if {[lsearch -exact [split [string tolower $list]] [string tolower [lindex $arg 0]:$chan]] != -1} {   putserv "PRIVMSG $chan :You are already a SOv on \002[string tolower $chan]\002. You cannot add yourself to the AOv list of \002[string tolower $chan]\002."   return 0  }  if {([lsearch -exact [split [string tolower $list]] [string tolower $nick:$chan]] != -1) || [matchattr $hand mn|mn $chan]} {   set user [string tolower [lindex $arg 0]:$chan]   set fp [open $aov r+]   set data [read -nonewline $fp]   close $fp   set list2 [split $data "\n"]   if {[lsearch -exact [split [string tolower $list2]] $user] == -1} {    set file [open $aov a+]    puts $file $user    close $file    putserv "PRIVMSG $chan :\002[lindex [split $arg] 0]\002 has been successfully added to the AOv list of \002[string tolower $chan]\002."    utimer 3 [list aov:on:add [lindex [split $arg] 0] $chan]    return 0   } else {     putserv "PRIVMSG $chan :\002[lindex [split $arg] 0]\002 already exists on the AOv list of \002[string tolower $chan]\002."     return 0     }   } else {      putserv "PRIVMSG $chan :You do not have access to modify the AOv list of \002[string tolower $chan]\002."; return 0      }   }}proc aov:delete {nick uhost hand chan arg} { global aov sov set arg [split $arg] if {$arg != ""} {  set fp [open $sov r+]  set data [read -nonewline $fp]  close $fp  set list [split $data "\n"]  set fp [open $aov r+]  set data [read -nonewline $fp]  close $fp  set list2 [split $data "\n"]  if {([lsearch -exact [split [string tolower $list]] [string tolower $nick:$chan]] != -1) || ([lsearch -exact [split [string tolower $list2]] [string tolower $nick:$chan]] != -1) || [matchattr $hand mn|mn $chan]} {   set user [string tolower [lindex $arg 0]:$chan]   set fd [open $aov w+]   if {[set i [lsearch -exact [split [string tolower $list2]] $user]] != -1} {     set fd [open $aov w+]     puts -nonewline $fd [join [lreplace $list2 $i $i] \n]     close $fd     putserv "PRIVMSG $chan :\002[lindex [split $arg] 0]\002 has been successfully removed from the AOv list of \002[string tolower $chan]\002."     utimer 3 [list aov:on:del [lindex $arg 0] $chan]   } else {     putserv "PRIVMSG $chan :\002[lindex [split $arg] 0]\002 was not found in the AOv list of \002[string tolower $chan]\002."     return 0     }   } else {     putserv "PRIVMSG $chan :You do not have access to modify the AOv list of \002[string tolower $chan]\002."    }  }}</code></pre></div>Tried this also:<div class="codebox"><p>Code: </p><pre><code>set arg [split $arg]set user [join [string tolower [lindex $arg 0]:$chan]]###OR###set user [join [lindex $arg 0]:$chan]Since I think when using lsearch $list should be split, but the *pattern* can be a string, as I checked in the tcl manual, hence [join] and [string tolower] both produce a string.</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=4875">awyeah</a> — Sat Jun 16, 2007 4:19 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[awyeah]]></name></author>
		<updated>2007-06-16T05:42:46-04:00</updated>

		<published>2007-06-16T05:42:46-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=73586#p73586</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=73586#p73586"/>
		<title type="html"><![CDATA[Deleting a line from a file - problem with special chars]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=73586#p73586"><![CDATA[
So all the elements in the database are deleted due to the special character thing? It's not cause of a faulty coding in the delete proc? Hmm okay, i'll look about split and join, thanks!<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=4875">awyeah</a> — Sat Jun 16, 2007 5:42 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[rosc2112]]></name></author>
		<updated>2007-06-15T22:06:45-04:00</updated>

		<published>2007-06-15T22:06:45-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=73577#p73577</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=73577#p73577"/>
		<title type="html"><![CDATA[Deleting a line from a file - problem with special chars]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=73577#p73577"><![CDATA[
Get rid of the string map kludge stuff and use [split] and [join] properly like you should. There is a file that explains how to make scripts tcl-special-char safe, check around the forum or google it.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=7395">rosc2112</a> — Fri Jun 15, 2007 10:06 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[awyeah]]></name></author>
		<updated>2007-06-15T07:02:40-04:00</updated>

		<published>2007-06-15T07:02:40-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=73564#p73564</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=73564#p73564"/>
		<title type="html"><![CDATA[Deleting a line from a file - problem with special chars]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=73564#p73564"><![CDATA[
Here is a script I coded recently, but I'm having problems for nicks with special characters. When I delete a nick with a special character:<br><br>1) It says nick not found in the database (text file)<br>2) The database file containing all the nicks becomes empty.<br><br>I need these two errors to be fixed if possible, for the script to work fine. Can anyone help me to rectify these errors if possible?<br><br>Here is the testing I did:<blockquote class="uncited"><div>&lt;awyeah&gt; .aovadd AhB<br>&lt;adapter&gt; AhB has been successfully added to the AOv list.<br>* adapter sets mode: +v-k AhB Added.to.AOv.list<br><br>&lt;awyeah&gt; .aovdel AhB<br>&lt;adapter&gt; AhB has been successfully removed from the AOv list.<br>* adapter sets mode: -vk AhB Removed.from.AOv.list</div></blockquote><blockquote class="uncited"><div>&lt;awyeah&gt; .aovadd [Nadia]<br>* adapter sets mode: +v-k [Nadia] Added.to.AOv.list<br><br>&lt;awyeah&gt; .aovdel [Nadia]<br>&lt;adapter&gt; [Nadia] was not found in the AOv list.<br><br>&lt;awyeah&gt; .aovlist<br>-adapter- AOv list for #pak<br>-adapter- 1 -   \[Nadia\] (<a href="mailto:aov@pak.dal.net">aov@pak.dal.net</a>)<br>-adapter- End of list.<br><br>Text file contains this entry:<br>[Nadia]:#pak</div></blockquote><blockquote class="uncited"><div>adapter- AOv list for #pak<br>-adapter- 1 -   \[Nadia\] (<a href="mailto:aov@klsex.dal.net">aov@klsex.dal.net</a>)<br>-adapter- 2 -   \[DeV-Kl\] (<a href="mailto:aov@klsex.dal.net">aov@klsex.dal.net</a>)<br>-adapter- End of list.<br><br>&lt;awyeah&gt; .delaov [Nadia]<br>&lt;adapter&gt; [Nadia] was not found in the AOv list of #pak.<br><br>&lt;awyeah&gt; .listaov<br>-adapter- AOv list for #pak<br>-adapter- End of list.</div></blockquote>Is my code okay and proper for deleting a specified nick from the database file? Also and suggestions on how to fix the script, so it deletes nicks with special characters from the database file??<br><br>Here is my code:<div class="codebox"><p>Code: </p><pre><code>proc aov:add {nick uhost hand chan arg} { global aov sov set arg [string map {\\ \\\\ [ \\\[ ] \\\] \{ \\\{ \} \\\}} $arg] if {$arg != ""} {  set fp [open $sov r+]  set data [read -nonewline $fp]  close $fp  set list [split [string map {\\ \\\\ [ \\\[ ] \\\] \{ \\\{ \} \\\}} $data]]  if {[lsearch -exact [string tolower $list] [string tolower [lindex $arg 0]]:[string tolower $chan]] != -1} {   putserv "PRIVMSG $chan :You are already a SOv on [string tolower $chan]. You cannot add yourself to the AOv list of [string tolower $chan]."   return 0  }  if {([lsearch -exact [string tolower $list] [string tolower $nick]:[string tolower $chan]] != -1) || [matchattr $hand mn|mn $chan]} {   set user [lindex $arg 0]:[string tolower $chan]   set fp [open $aov r+]   set data [read -nonewline $fp]   close $fp   set list2 [split [string map {\\ \\\\ [ \\\[ ] \\\] \{ \\\{ \} \\\}} $data]]   if {[lsearch -exact [string tolower $list2] [string tolower $user]] == -1} {    set file [open $aov a+]    puts $file $user    close $file    putserv "PRIVMSG $chan :[lindex $arg 0] has been successfully added to the AOv list of [string tolower $chan]."    utimer 3 [list aov:on:add [lindex $arg 0] $chan]    return 0   } else {     putserv "PRIVMSG $chan :[lindex $arg 0] already exists on the AOv list of [string tolower $chan]."     return 0     }   } else {      putserv "PRIVMSG $chan :You do not have access to modify the AOv list of [string tolower $chan]."; return 0      }   }}proc aov:delete {nick uhost hand chan arg} { global aov sov set arg [string map {\\ \\\\ [ \\\[ ] \\\] \{ \\\{ \} \\\}} $arg] if {[info exists list3]} { unset list3 } if {$arg != ""} {  set fp [open $sov r+]  set data [read -nonewline $fp]  close $fp  set list [split [string map {\\ \\\\ [ \\\[ ] \\\] \{ \\\{ \} \\\}} $data]]  set fp [open $aov r+]  set data [read -nonewline $fp]  close $fp  set list2 [split [string map {\\ \\\\ [ \\\[ ] \\\] \{ \\\{ \} \\\}} $data]]  if {([lsearch -exact [string tolower $list] [string tolower $nick]:[string tolower $chan]] != -1) || ([lsearch -exact [string tolower $list2] [string tolower $nick]:[string tolower $chan]] != -1) || [matchattr $hand mn|mn $chan]} {   set user [lindex $arg 0]:[string tolower $chan]   set fp [open $aov r+]   set data [read -nonewline $fp]   close $fp   set list3 [split [string map {\\ \\\\ [ \\\[ ] \\\] \{ \\\{ \} \\\}} $data]]   set fd [open $aov w+]   if {[set i [lsearch -exact [string tolower $list3] [string tolower $user]]] != -1} {     set fd [open $aov w+]     puts -nonewline $fd [join [lreplace $list3 $i $i] \n]     close $fd     putserv "PRIVMSG $chan :[lindex $arg 0] has been successfully removed from the AOv list of [string tolower $chan]."     utimer 3 [list aov:on:del [lindex $arg 0] $chan]   } else {     putserv "PRIVMSG $chan :[lindex $arg 0] was not found in the AOv list of [string tolower $chan]."     return 0     }   } else {     putserv "PRIVMSG $chan :You do not have access to modify the AOv list of [string tolower $chan]."    }   if {[info exists list3]} { close $fd; unset list3; return 0 }  }}</code></pre></div>Also a similar problem here, when I try to delete more than 1 line from the text file, the whole file gets erased. This is the code for deleting more than 1 line from the database:<br><div class="codebox"><p>Code: </p><pre><code>proc sov:wipe {nick uhost hand chan arg} { global aov sov  set fp [open $sov r+]  set data [read -nonewline $fp]  close $fp  set list [split [string map {\\ \\\\ [ \\\[ ] \\\] \{ \\\{ \} \\\}} $data]]  if {[matchattr $hand mn|mn $chan]} {  set fd [open $sov w+]  set list3 [list]   foreach user $list {    if {[set i [lsearch -exact [string tolower $list] [string tolower $user]]] != -1} {     set list3 [lreplace $list3 $i $i]     }   }   puts -nonewline $fd [join $list3 "\n"]   putserv "PRIVMSG $chan :The SOv list of [string tolower $chan] has been wiped successfully."   close $fd  }  set fp [open $aov r+]  set data [read -nonewline $fp]  close $fp  set list2 [split [string map {\\ \\\\ [ \\\[ ] \\\] \{ \\\{ \} \\\}} $data]]  if {([lsearch -exact [string tolower $list] [string tolower $nick]:[string tolower $chan]] != -1) || ([lsearch -exact [string tolower $list2] [string tolower $nick]:[string tolower $chan]] != -1)} {   putserv "PRIVMSG $chan :You do not have access to wipe the SOv list of [string tolower $chan]."   return 0   }}</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=4875">awyeah</a> — Fri Jun 15, 2007 7:02 am</p><hr />
]]></content>
	</entry>
	</feed>
