egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

add up lines in txt and report total lines

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
whittinghamj
Op


Joined: 21 May 2006
Posts: 103

PostPosted: Mon Feb 19, 2007 2:30 am    Post subject: add up lines in txt and report total lines Reply with quote

hi guys.

I been looking thro the forums and the archive but not sure what I would be looking for in the code.

I have a txt file with lets say 15 lines of info on it. I need a script that would open the file add the lines up close the file then report to the channel

<bot>There are 15 records in total

also i am stuck on how to stripcodes c

i have been going around and around in bllod circles for hours

here is what i am working with.

[code]
proc add {nick uhost hand chan text} {
set database [open ${::db} a+]
set timestamp [clock format [clock seconds]]
set section [lindex $text 6]
puts $database "$timestamp $section"
close $database
}
[code]

I know i have to change the line added to the database but not sure how.

Any help would be great.

Cheers

Quest[/code]
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Mon Feb 19, 2007 4:30 pm    Post subject: Reply with quote

Code:

proc getlines {nick uhost hand chan text} {
        set file [open "YOURFILE" r]
        set data [split [read $file] \n]
        close $file
        puthelp "PRIVMSG $chan :number of lines: [llength $data]"
}

Code:

proc addtimestamp {nick uhost hand chan text} {
       set file [open "YOURFILE" a]
       set timestamp [clock format [clock seconds]]
       set section [lindex $text 6]
       puts $file "$timestamp $section"
       close $file
}

Of course, the above addtimestamp thing doesn't do any kind of sanity checking on your input, nor does it do any security checking on who can run it (but you could just limit access with the bind for it..) I made 2 seperate procs because your request was unclear, and it seemed like you wanted 1 proc for counting lines, and another for adding stuff to the file.

As far as how to use the stripcode command, you have to feed it strings, what are you trying to strip? Log files? Gnenerally, you want to make a seperate binding to get the public messages and pass them through a proc with stripcodes, then write them out to a file (although, I'd probably cache the data in memory and use the various EVNT bindings to write the cache out before quit, rehash, etc. and maybe a timer to write the log periodically..
Back to top
View user's profile Send private message
whittinghamj
Op


Joined: 21 May 2006
Posts: 103

PostPosted: Mon Feb 19, 2007 7:10 pm    Post subject: Reply with quote

thank you for the help - worked perfectly and I understand regarding the unixtime. I did some reading up at work today.

I have one other question.

I have the following code to record text from a channel and save it to a file. To record !command 's being used.

Code:

proc add {nick uhost hand chan text} {
        set database [open ${::db} a+]
        set date [unixtime]
        set command [lindex $text 0 end]
        puts $database "$date $command"
        close $database
}


The db file looks like

123431234 !command something was used

What I wanted to do was findout how to replace the spaces with a " . "

So instead of it being 1234566 one two three it would be
123456 one.two.three

the text on the channel has spaces but I need those spaces converting into periods for saving to the file.

Any help would be amazing.

Thanks

also - I store the time when the command was used. How would I go about checking the time passed since the unixtime time saved in the file to the present - eg 1week 2days 52 minutes ago t!command was used.

Any help please - cheers

Jamie aka Quest
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Wed Feb 28, 2007 9:21 am    Post subject: Reply with quote

The question about replacing spaces with dots, was answered in another thread, basically just use string map:

set myvar [string map {" " "."} $input]

As far as find the duration from a time stamp, take a look at the 'duration' command Smile

duration <seconds>
Returns: the number of seconds converted into years, weeks, days, hours, minutes, and seconds. 804600 seconds is turned into 1 week 2 days 7 hours 30 minutes.
Module: core

The following assumes you grabbed your previous timestamp already, in a var called '$then'

Get the current timestamp,

set now [unixtime]

then subtract your previous timestamp,

set timesince [expr $now - $then]

and then use duration to check the time difference:

set duration [duration $timesince]

Or, in a one-liner:

set timesince [duration [expr $then - [unixtime]]]
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber