| View previous topic :: View next topic |
| Author |
Message |
pipo Voice
Joined: 18 Nov 2006 Posts: 16
|
Posted: Tue Nov 21, 2006 5:33 am Post subject: counting stored lines in db |
|
|
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 |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Tue Nov 21, 2006 3:13 pm Post subject: |
|
|
| 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 |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Tue Nov 21, 2006 5:55 pm Post subject: |
|
|
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 |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Tue Nov 21, 2006 6:23 pm Post subject: |
|
|
| nml375 wrote: | | Code: | | set linecount [llength $lines] | |
Ohh yeah
I forget these simple things  |
|
| Back to top |
|
 |
pipo Voice
Joined: 18 Nov 2006 Posts: 16
|
Posted: Tue Nov 21, 2006 7:37 pm Post subject: |
|
|
thanks
My bot is running in two channels, is it possible to let the trigger work only in one channel? |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Tue Nov 21, 2006 8:34 pm Post subject: |
|
|
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 |
|
 |
|