|
Joined: Jul 2004
Posts: 59
Babel fish
|
OP
Babel fish
Joined: Jul 2004
Posts: 59 |
I am trying to make a script that will choose a random line from a random log in my log folder, as long as a) it's a channel log and not a PM, and b) the channel name starts with 'd'. Here is what I have so far. It works, but I'd like to add some more parameters to it, and I've hit a wall trying to figure it out. So here goes.
alias logline {
// get number of files in logdir (in this case, only logs where the channel name starts with '#d'
var %i = $findfile($logdir,#d*,0)
// get a random file
var %z = $findfile($logdir,#d*,$rand(1,%i))
// get random line from chosen file, finding a line where someone has spoken (ex. "<person> blah")
var %x = $read(%z, w, *<*>*)
// set %s as the first token in the string, in this case the timestamp
var %s = $gettok(%x,1,32)
// remove the timestamp singled out above, and output
return $remove(%x,%s)
}
I know this is by no means the most optimal way to accomplish this, but it's what I've got so far. Anyways, what I'd like to do is make it so that it will start over and select another line if the line it initially chooses starts with a * (for weeding out joins/parts/topics). Any help is appreciated, thanks
Last edited by synth7; 20/02/08 05:15 AM.
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
alias logline {
; get number of files in logdir (in this case, only logs where the channel name starts with '#d'
var %i = $findfile($logdir,#d*,0)
; Prevent an endless loop caused by no matching files.
if (%i = 0) { echo -a No files found. | return }
; Keep reading in random lines until one that has < as the starting character
; (after timestamps are removed) (i.e. someone speaking)
while ($left(%s,1) != $chr(60)) {
; get a random file
var %z = $findfile($logdir,#d*,$rand(1,%i))
; get random line from chosen file
var %x = $read(%z)
; remove the timestamp
var %s = $deltok(%x,1,32)
}
; output
return %s
}
Note that if you don't want it to keep choosing a new file each time it tries for a line that is spoken rather than join/part/etc, just move the %z line above the while loop. This will speed it up by just looking for a new line in the same file rather than searching new files each time. The only issue with that is that you may have a log without any talking in it (especially if you just joined that day and it's a new log file) and then you would be looping non-stop until the log file had spoken text in it. Because of that, I'd personally leave it in the loop, but that's up to you. EDIT: Fixed to use $chr(60) instead of < so it works and added check for no matching files.
Last edited by Riamus2; 20/02/08 01:22 PM.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Jul 2004
Posts: 59
Babel fish
|
OP
Babel fish
Joined: Jul 2004
Posts: 59 |
Thanks Riamus2, that got it working perfectly. However, I hit another wall trying to add another "rule".
alias logline {
var %i = $findfile($logdir,#d*,0)
if (%i = 0) { echo -a No files found. | return }
while ( $left(%s,1) != $chr(60) ) {
var %z = $findfile($logdir,#d*,$rand(1,%i))
var %x = $read(%z)
var %s = $deltok(%x,1,32)
}
return %s
}
What I'm trying to do is make it so that it won't return a line unless it is more than 20 letters, so that the script doesn't spit out lines that is just someone saying "lol" or "ok". In the line with the while loop, if I add a && ($len(%s) >= 20) it will just return nothing at all.
Last edited by synth7; 21/02/08 12:25 AM.
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
while ( $left(%s,1) != $chr(60) || $len(%s) < 20 ) {
Keep in mind that your $len takes into account the nick length as well. So 20 may be a little low. Up to you, of course.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
|