This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

counting stored lines in db

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
p
pipo
Voice
Posts: 16
Joined: Sat Nov 18, 2006 2:51 pm

counting stored lines in db

Post by pipo »

Im looking for a little script that will count how many lines there are stored in my txt database . My db is called db.txt

someting like: !count
outputs: found ## lines in db

Thanks in advance
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Code: Select all

bind pub - !count proc:count
proc proc:count {nick host hand chan text} {
    set linecount 0
    set input [open /my/path/to/db.txt r]
    set lines [split [read $input] \n]
    catch {close $input}
    foreach line $lines {
         incr linecount
    }
    puthelp "PRIVMSG $chan :Lines: $linecount"
}
That's one way to do it.. Could probably use a "while ![eof]" as well..
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Or you replace this:

Code: Select all

foreach line $lines {
  incr linecount
}
with

Code: Select all

set linecount [llength $lines]
in the above example
NML_375
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

nml375 wrote:

Code: Select all

set linecount [llength $lines]
Ohh yeah :)
I forget these simple things :roll:
p
pipo
Voice
Posts: 16
Joined: Sat Nov 18, 2006 2:51 pm

Post by pipo »

thanks :D


My bot is running in two channels, is it possible to let the trigger work only in one channel?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

add

Code: Select all

if {![string equal -nocase #chan $chan]} {return 0}
inside the proc, before 'set linecount 0'. (#chan is the channel where you want to script to work)
Post Reply