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

	<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>2017-05-04T14:59:34-04:00</updated>

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

		<entry>
		<author><name><![CDATA[willyw]]></name></author>
		<updated>2017-05-04T14:59:34-04:00</updated>

		<published>2017-05-04T14:59:34-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=106246#p106246</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=106246#p106246"/>
		<title type="html"><![CDATA[Deleted File Keeps Coming Back]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=106246#p106246"><![CDATA[
<blockquote class="uncited"><div>...<br>It's like the contents of the deleted file are still in the bot's memory, </div></blockquote>Exactly.<br><blockquote class="uncited"><div>even after a restart. </div></blockquote>Or ...  stored in a file and read back into memory, on restart?    <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br><br><br>Ok... let's see...<br><br>See that line, second from the end of the script?<div class="codebox"><p>Code: </p><pre><code>statistics::load</code></pre></div>that line runs a procedure named<br>load<br>found in your script's namespace named "statistics" , every time this script is loaded.   That means : every start up, every rehash and every restart<br><br>So let's go see what that proc does.<br><br>Found this?   :   proc statistics::load {} {<br>see those lines like :<br>set file [open $storage r]<br>and<br>close $file  <br>?<br>That's open and closing a file, and there are lines in between that read that file, and store it in an array named <br>data<br><br>The variable name "data" is used throughout the script ... looks like that is where all the stats are stored.<br><br>Now we know how and why the stats are loaded into memory.  <br>They come from a file where they are stored, and it is read in on every start up, or rehash, or  .restart<br>Make sense so far?<br><br>Next, let's look at:<div class="codebox"><p>Code: </p><pre><code>bind EVNT  -|-  save              [namespace current]::save</code></pre></div>( go here : <a href="http://www.eggheads.org/support/egghtml/1.6.21/tcl-commands.html" class="postlink">http://www.eggheads.org/support/egghtml ... mands.html</a><br>and text search to find<br>bind evnt<br>and read about what the <br>save<br>event is, and when it is triggered.   )<br><br>Next, find that proc that is called by the bind EVNT<br>Find this:<br>proc statistics::save {args} {<br><br>That's going through everything in the array named "data" and saving it to a file.<br>Apparently this happens every time the userfile is saved.   I'm not sure, but I seem to recall that happens automatically every 10 minutes, and also on normal exits of the bot...  like if you used .restart  or  .die  .<br><br>Can you picture now, what is happening?<br>It's simply coming right behind your cron job that deletes the file, and re-creating it.... just like you described.<br><br>I see you have already worked with <br>bind cron<br>in your experiments with restart, so you are familiar with it.<br>If you set a bind cron to trigger at the same time as your cron job that deletes the file, and in this bind cron you have it <br>unset data<br>wouldn't you now have:  no longer any file that is storing the stats, and no stats in memory?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=10420">willyw</a> — Thu May 04, 2017 2:59 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Landslyde]]></name></author>
		<updated>2017-05-04T06:23:29-04:00</updated>

		<published>2017-05-04T06:23:29-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=106243#p106243</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=106243#p106243"/>
		<title type="html"><![CDATA[Deleted File Keeps Coming Back]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=106243#p106243"><![CDATA[
My cron job:<div class="codebox"><p>Code: </p><pre><code>00 03 * * * rm  /home/shianne/eggdrop/scripts/dbase/statistics</code></pre></div>This works fine.<br><br>Here's the restart.tcl. This works fine. <div class="codebox"><p>Code: </p><pre><code>## this equals 04:00 am CSTbind cron - {00 03 * * *} restart:cron proc restart:cron {min hour day month weekday} {    restart}</code></pre></div>The bot restarts at the same time the file is deleted. And when she co,es back, the statistic data from the deleted file is still there. This is very frustrating. Very.<br><blockquote class="uncited"><div>What do you mean by, "showing" ? <br>For example: The bot posts the data to a channel at specific times? </div></blockquote>You manually call up the data, at any time, using commands.<br><blockquote class="uncited"><div>After deletion, and immediately after a restart, is there data in this file? </div></blockquote>Yes. It's like the contents of the deleted file are still in the bot's memory, even after a restart. And mysteriously, the file is back. Just as if it had never been deleted.<br><blockquote class="uncited"><div>Without seeing the complete script, I'll guess that there is code in it that upon rehash and/or restart - checks to see if file exists, and if not then it creates it. If it has data in it, then it creates it just before the .restart. </div></blockquote><div class="codebox"><p>Code: </p><pre><code># Statistics.tcl (C) 2004 perpleXa#  type ".chanset &lt;chan&gt; +stat" on the partyline to ativate the script for a specific channel.#  commands: $stat &lt;nick&gt; - shows information about you or a nick. (works only for other nicks when you are op on a channel)#            $top10 &lt;smilies|words|lines|letters&gt; - shows the top10 chatters, default option is words#            $top20 &lt;smilies|words|lines|letters&gt; - same as $top10 but with places 11-20namespace eval statistics {# Storage file  variable storage {scripts/dbase/statistics}# Kill unused entries after x days  variable killafter 30# Command trigger  variable trigger {.}# smiley regex (only touch this, if you really know, what you are doing!)  variable smileyregex {(:|8|;|=)(-|o)?(&gt;|&lt;|D|O|o|\)|\(|\]|\[|P|p|\||\\|/)}  bind PUB   -|-  ${trigger}stats   [namespace current]::spew  bind PUB   -|-  ${trigger}top10   [namespace current]::toplist  bind PUB   -|-  ${trigger}top20   [namespace current]::toplist  bind PUBM  -|-  *                 [namespace current]::monitor  bind CTCP  -|-  ACTION            [namespace current]::ctcp  bind EVNT  -|-  save              [namespace current]::save  bind TIME  -|-  {00 * * * *}      [namespace current]::cleanupdb  setudef flag stat  namespace export spew top10 toplist save load monitor}proc statistics::ctcp {nickname hostname handle target keyword arguments} {  if {[validchan $target]} {    monitor $nickname $hostname $handle $target $arguments  }  return 0}proc statistics::monitor {nickname hostname handle channel arguments} {  variable data  variable smileyregex  if {$nickname == "maricar"} { return 0 }  if {$nickname == "Stryker"} { return 0 }  if {$nickname == "Cyell"} { return 0 }  if {([isbotnick $nickname]) || (![channel get $channel stat])} {    return 0  }  set hostname [maskhost *!$hostname]  regsub -all -- {\002|\003[\d]{0,2}(,[\d]{0,2})?|\006|\007|\017|\026|\037|\n|\t} $arguments {} arguments  set added(words) [regexp -all -- {\S+} $arguments]  set added(letters) [regexp -all -- {\S} $arguments]  if {[string length $smileyregex] &gt;= 1} {    set added(smilies) [regexp -all -- $smileyregex $arguments]  } else {    set added(smilies) 0  }  if {(![info exists data($channel,$hostname)])} {    set data($channel,$hostname) "0 0 0 0 0 NULL"  }  regexp -- {^(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\S+)$} $data($channel,$hostname) -&gt; lastseen lines words letters smilies lastnick  incr lines 1  incr words $added(words)  incr letters $added(letters)  incr smilies $added(smilies)  set data($channel,$hostname) "[unixtime] $lines $words $letters $smilies $nickname"}proc statistics::spew {nickname hostname handle channel arguments} {  variable data  if {(![channel get $channel stat])} {    return 0  }  if {([string length $arguments] &gt;= 1)} {    set target [lindex [clean $arguments] 0]  } else {    set target $nickname  }  if {![onchan $target $channel]} {    putserv "PRIVMSG $channel :\[Statistics - Unknown user \002$target\002\]"    return 0  }  set targethost [maskhost *![getchanhost $target $channel]]  if {[info exists data($channel,$targethost)]} {    regexp -- {^(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\S+)$} $data($channel,$targethost) -&gt; lastseen lines words letters smilies lastnick    set wpl [round [expr ($words / $lines.)]]    set spl [round [expr ($smilies / $lines.)]]    set lpw [round [expr ($letters / $words.)]]    putserv "PRIVMSG $channel :\[Statistics - \002$target\002 has written \002$lines\002 lines, \002$words\002 ($wpl per line) words and \002$letters\002 ($lpw per word) letters, containing \002$smilies\002 ($spl per line) smilies\]"  } else {    putserv "PRIVMSG $channel :\[Statistics - No valuable information available for \002$target\002\]"  }}proc statistics::top {channel number {type ""}} {  variable data  set statistics {}  switch $type {    {lines} {set index 1}    {letters} {set index 3}    {smilies} {set index 4}    {default} {set index 2 ; set type "words"}  }  foreach {user stats} [array get data $channel,*] {    set stats [clean $stats]    lappend statistics "[lindex [clean $stats] 5] [lindex $stats $index]"  }  set statistics [lrange [lsort -integer -decreasing -index 1 [lsort -unique -index 0 [lsort -integer -increasing -index 1 $statistics]]] [expr $number - 10] [expr $number - 1]]  if {$statistics == ""} {    return "\[Top$number $type - No valuable information available for \002$channel\002\]"  }  set output "\[Top$number $type -"  for {set i 0} {$i &lt; [llength $statistics]} {incr i 1} {    set item [lindex $statistics $i]    append output "\x20[expr $i+$number-9]: \002[join [lindex [clean $item] 0] { }]\002 ([lindex $item 1])"  }  append output "\]"  return $output}proc statistics::toplist {nickname hostname handle channel arguments} {  global lastbind  if {(![channel get $channel stat])} {    return 0  }  set arguments [clean $arguments]  set key [lindex $arguments 0]  if {![regexp -- {^.*?([0-9]+)$} $lastbind -&gt; number]} {    return 0  }  if {![regexp -nocase -- {^(words|letters|smilies|lines|)$} $key]} {    putserv "PRIVMSG $channel :\[Statistics - Unknown option: \002$key\002, valid options are \002letters\002, \002lines\002, \002smilies\002 and \002words\002\]"    return 0  }  putserv "PRIVMSG $channel :[top $channel $number [string tolower $key]]"}proc statistics::cleanupdb {args} {  variable killafter  variable data  set killed 0  foreach {item} [array names data] {    set lastseen [lindex [clean $data($item)] 0]    set expire [expr 60 * 60 * 24 * $killafter]    if {[expr [unixtime] - $lastseen] &gt;= $expire} {      incr killed      unset data($item)    }  }  return $killed}proc statistics::load {} {  variable data  variable storage  regexp -- {^(\S+/)?.*$} $storage -&gt; directory  if {[string length $directory] &gt;= 1} {    if {![file isdirectory $directory]} {      file mkdir $directory    }  }  if {![file exists $storage]} {    return 0  }  if {[array exists data]} {    array unset data  }  set file [open $storage r]  while {![eof $file]} {    gets $file line    if {[regexp -nocase -- {^channel:(\S+)\sid:(\S+)\svalue:(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\S+)$} $line -&gt; channel hostname lastseen lines words letters smilies lastnick]} {      set data($channel,$hostname) "$lastseen $lines $words $letters $smilies $lastnick"    }  }  close $file}proc statistics::save {args} {  variable data  variable storage  set file [open $storage w]  foreach chan_user [array names data] {    regexp {^(\S+),(\S+)$} $chan_user -&gt; channel user    puts $file "channel:$channel id:$user value:$data($chan_user)"  }  close $file}proc statistics::clean {i} {  regsub -all -- \\\\ $i \\\\\\\\ i  regsub -all -- \\\[ $i \\\\\[ i  regsub -all -- \\\] $i \\\\\] i  regsub -all -- \\\} $i \\\\\} i  regsub -all -- \\\{ $i \\\\\{ i  return $i}proc statistics::round {num} {  if {![string match "*.*" $num]} {    return $num\.0  }  if {![regexp -- {^(\d+?)\.(\d+)$} $num -&gt; primary secondary]} {    error "syntax error in expression '$num'"  }  set secondary [expr round([string index $secondary 0].[string range $secondary 1 end])]  return [expr {($secondary == 10) ? ($primary+1.0) : "$primary.$secondary"}]}statistics::loadputlog "Script loaded: Statistics by perpleXa"</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12386">Landslyde</a> — Thu May 04, 2017 6:23 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[willyw]]></name></author>
		<updated>2017-05-04T04:36:47-04:00</updated>

		<published>2017-05-04T04:36:47-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=106242#p106242</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=106242#p106242"/>
		<title type="html"><![CDATA[Re: Deleted File Keeps Coming Back]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=106242#p106242"><![CDATA[
<blockquote class="uncited"><div>....<br>it keeps showing the old data as if it was never deleted. </div></blockquote>What do you mean by, "showing" ?<br>For example: The bot posts the data to a channel at specific times?<br><blockquote class="uncited"><div>...<br> And if I restart it, the deleted file is back! </div></blockquote>After deletion, and immediately after a restart, is there data in this file?  <br><blockquote class="uncited"><div>...<br>Any ideas? Anyone?</div></blockquote>Without seeing the complete script, I'll guess that there is code in it that upon rehash and/or restart - checks to see if file exists, and if not then it creates it.   If it has data in it, then it creates it just before the .restart.<br><br><br>I suggest that you post the complete script.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=10420">willyw</a> — Thu May 04, 2017 4:36 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Landslyde]]></name></author>
		<updated>2017-05-04T03:33:03-04:00</updated>

		<published>2017-05-04T03:33:03-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=106241#p106241</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=106241#p106241"/>
		<title type="html"><![CDATA[Deleted File Keeps Coming Back]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=106241#p106241"><![CDATA[
One of my bots (1.6.21) uses a statistics script that generates a file, tracking how much the users yack on the channel. I have a cron job that deletes this file daily (verified deletion). But, even though the file gets deleted, it keeps showing the old data as if it was never deleted. <br><br>My Cron:<div class="codebox"><p>Code: </p><pre><code>00 03 * * * rm  /home/shianne/eggdrop/scripts/dbase/statistics</code></pre></div>What can I do to make my bot clear out the stats of this deleted file<strong class="text-strong"> statistics</strong>? I've tried rehashing to no avail. And if I restart it, the deleted file is back! <br><br>This is silly stuff, something so simple as this, but I can't make it work. Any ideas? Anyone?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12386">Landslyde</a> — Thu May 04, 2017 3:33 am</p><hr />
]]></content>
	</entry>
	</feed>
