|
Joined: Nov 2005
Posts: 105
Vogon poet
|
OP
Vogon poet
Joined: Nov 2005
Posts: 105 |
Hi, I currently have a .txt file with approximately 400-500 lines of text, and I'd like to allow users to search the file and then /notice them 5 matching results. For example, a user would type @find test and it would search the .txt file for anything with *text* and then notice them the first 5 results. I've made several attempts at this and can't get it to notice all the matching results. I can even get it to notice the first 5 lines of matching text with a while loop, but keep running into problems unseting the variable after the 5 lines are sent to the user. Also, if no matching lines of text are found in the file, tell the user that the text isn't found. I'd post the code I have, but it's pretty sloppy. Any help in doing so would be greatly appreciated. Oh, and I also noticed the /filter command, and reading in the help file that you can save that to an alias. Would that be quicker than $read(filename.txt)? Thanks in advance again.
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
Please post your code. It's usually easier to fix up a code that you've already got than to make one from scratch. Plus by working with your code, we can show what chnages were made and why.
P.S.: Don't forget to use the Code tags
|
|
|
|
Joined: Nov 2005
Posts: 105
Vogon poet
|
OP
Vogon poet
Joined: Nov 2005
Posts: 105 |
on *:TEXT:@find*:#test:{
var %i = 1
while ($read(test.txt,%i)) {
if ($2 isin $read(test.txt,%i)) {
set %test. [ $+ [ $nick ] ] $addtok(%test. [ $+ [ $nick ] ],32) $read(test.txt,%i)
}
inc %i
}
if ($numtok(%test. [ $+ [ $nick ] ],32) > 0) {
notice $nick found $numtok(%test. [ $+ [ $nick ] ],32) (found).
var %i
while ($gettok(%test. [ $+ [ $nick ] ],%i,32)) {
if (%i > 5) { goto end }
notice $nick $gettok(%test. [ $+ [ $nick ] ],%i,32)
inc %i
}
}
else {
.notice $nick no text found
}
:end
unset %test. [ $+ [ $nick ] ]
} This isn't my partion of code, it's code that a friend done, that doesn't work. I've kept playing around with what I had, and now it fails to work. I understand what I'm doing .. to an extent, not famaliar with $gettok $addtok or anything though. I'll doctor up my .. sloppy simple code and paste it once I return from class. Thanks again, and hope you're able to help. I know it's something so simple, I'm just overlooking.
Last edited by drc4; 22/11/05 05:41 PM.
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
Give this a try...I'm having a hard time connecting at the moment, so I'm unable to test it. on *:TEXT:@find*:#test:{
var %i = 1, %found
while $read(test.txt,w,$+(*,$2,*),%i) {
var %i = $readn
.notice $nick $read(test.txt,%i)
inc %found
if %found = 5 {
var %i = $lines(test.txt)
}
inc %i
}
if !%found {
.notice $nick Sorry no matches found
}
}
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
on @*:text:@find &:#mychannel: findlines temp.txt $2 5
[color:red] [/color]
alias findlines {
var %tmp = $+($ticks,.txt)
filter -ff $1 %tmp $+(*,$$2,*)
if ($filtered) {
if ($ifmatch > $3) filter -ffcr $+(1-,$3) %tmp %tmp
.play -n $nick %tmp
}
else notice $nick No matches for $2
.remove %tmp
} You could also use the file handling commands, in this particular case they could even be faster than using /filter, since you have a limit to the number of results you want returned. The code is somewhat longer though, and the speed will be relatively neglectible, you wouldn't notice it.
Gone.
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
Err, two things:
* You should probably remove that @ in the "on @*" part, as it would only trigger if you are an op. * I think you'll figure it out but I mention it anyway: you should change #mychannel to the channels where you want this to trigger on. For multiple channels, seperate them with commas, for all channels simply put #
Gone.
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
I had done a similar file, but not as good so I tried yours with a few mods based on what I have seen you post in the past
on *:text:!find &:#: findlines list.txt $2 5
alias findlines {
filter -ffc $1 tmp $+(*,$$2,*)
if ($filtered) {
if ($ifmatch > $3) filter -ffcr $+(1-,$3) tmp tmp
.play -nm1 $nick tmp
}
else notice $nick No matches for $2
}
just wondering why you chose in this case to make the txt file note I did have to add the c to the filter command as tmp didnt clear out (not %tmp) until I added the switch, yet /remove tmp wont find it as a file (scratch scratch)
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
The reason I made the txt file with $ticks value in it this time, is because I remember in some other thread there were complaints about "tmp" as a filename (I can't seem to find the thread). I've never had any trouble writing/reading/deleting to file "tmp", but I figured I'd use $ticks anyway.
In my version of /findlines, I don't need the c flag in the first filter, because the file will not exist yet (it's unique because of $ticks)
I don't know why you can't use /remove tmp in your mIRC, here it works fine.
Gone.
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
hmm, its entirely possible I was typing in the wrong copy of mIRC (had a couple open)
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
LOL it turns out it was actually you who made that comment about "tmp", here Hehehe.
Gone.
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
ehem, I knew that.......
|
|
|
|
|