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 

counting stored lines in db

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


Joined: 18 Nov 2006
Posts: 16

PostPosted: Tue Nov 21, 2006 5:33 am    Post subject: counting stored lines in db Reply with quote

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
Back to top
View user's profile Send private message
rosc2112
Revered One


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

PostPosted: Tue Nov 21, 2006 3:13 pm    Post subject: Reply with quote

Code:

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..
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Tue Nov 21, 2006 5:55 pm    Post subject: Reply with quote

Or you replace this:
Code:
foreach line $lines {
  incr linecount
}
with
Code:
set linecount [llength $lines]
in the above example
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
rosc2112
Revered One


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

PostPosted: Tue Nov 21, 2006 6:23 pm    Post subject: Reply with quote

nml375 wrote:
Code:
set linecount [llength $lines]

Ohh yeah Smile
I forget these simple things Rolling Eyes
Back to top
View user's profile Send private message
pipo
Voice


Joined: 18 Nov 2006
Posts: 16

PostPosted: Tue Nov 21, 2006 7:37 pm    Post subject: Reply with quote

thanks Very Happy


My bot is running in two channels, is it possible to let the trigger work only in one channel?
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Tue Nov 21, 2006 8:34 pm    Post subject: Reply with quote

add
Code:
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)
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
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