mIRC Home    About    Download    Register    News    Help

Print Thread
if any-line-infile iswm $1- ? #46415 02/09/03 04:48 AM
Joined: Aug 2003
Posts: 29
2
2big Offline OP
Ameglian cow
OP Offline
Ameglian cow
2
Joined: Aug 2003
Posts: 29
What is the syntax for the if statement, if I wanted to check if any line in a specified file is in the $1- identifier.

Re: if any-line-infile iswm $1- ? #46416 02/09/03 04:56 AM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
Code:
if (what isin $1-) 


you looking for that?


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: if any-line-infile iswm $1- ? #46417 02/09/03 05:00 AM
Joined: Aug 2003
Posts: 29
2
2big Offline OP
Ameglian cow
OP Offline
Ameglian cow
2
Joined: Aug 2003
Posts: 29
Huh?

No, I'm trying to find the syntax that tells me if any line in a specified file, say, example.txt, is in the text someone says, $1-.

Example:

on *:text:*:#: { if (($LineFile(example.txt) iswm $1-)) {
/msg $chan one of the words in what you just said, is in the file example.txt
}
else { halt }
}

Of course, $LineFile isn't an actual identifier, But I'm trying to find what is the correct syntax.

Re: if any-line-infile iswm $1- ? #46418 02/09/03 05:05 AM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
Code:
if ( $read -l $+ %wordline.line $mircdir $+\text.txt == $null ) { halt }
elseif ( $read -l $+ %word.line $mircdir $+ \text.txt isin $1- ) { do stuff }
} 


that one maybe works for you?


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: if any-line-infile iswm $1- ? #46419 02/09/03 05:11 AM
Joined: Aug 2003
Posts: 29
2
2big Offline OP
Ameglian cow
OP Offline
Ameglian cow
2
Joined: Aug 2003
Posts: 29
Err... That doesn't look right at all. It also gives me an error: /if: invalid format


where did you get %word.line from?

Re: if any-line-infile iswm $1- ? #46420 02/09/03 05:14 AM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
thats the code for my word "kicker" it reads a text file and kick the person say a word if it exist in the text file.. and i know it works, cos i running it right now wink

kick: $nick was kicked by $me (Forbidden word)

did u remember to set the %var ?? set %wordline.line $1-


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: if any-line-infile iswm $1- ? #46421 02/09/03 05:16 AM
Joined: Aug 2003
Posts: 29
2
2big Offline OP
Ameglian cow
OP Offline
Ameglian cow
2
Joined: Aug 2003
Posts: 29
You have two different Variables. did you mean to just use one? Example, you put %Wordline.line and %Word.line

Re: if any-line-infile iswm $1- ? #46422 02/09/03 05:19 AM
Joined: Mar 2003
Posts: 1,271
L
LocutusofBorg Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Mar 2003
Posts: 1,271
I gather you wanna search a txt file for a line that is equal to $1-?

(forgive me, I haven't gotten to studying the new file operations yet).

Code:
on *:TEXT:*:[color:blue]#channelname[/color]: {
  var %x = $read([color:blue]filename[/color],w,$replace($1-,$chr(32),$chr(42)))
  if ($readn) echo -a [color:purple]The line was found in the file on line $readn ![/color]
  else echo -a [color:purple]The line was not found[/color]
}


DALnet #Helpdesk
I hear and I forget. I see and I remember. I do and I understand. -Confucius
Re: if any-line-infile iswm $1- ? #46423 02/09/03 05:21 AM
Joined: Aug 2003
Posts: 29
2
2big Offline OP
Ameglian cow
OP Offline
Ameglian cow
2
Joined: Aug 2003
Posts: 29
No, that just searches a file for a line that is equal to $1-. I want to search the file for a word that was in $1-.

Re: if any-line-infile iswm $1- ? #46424 02/09/03 05:25 AM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
my code should work for you.. just set the %var

on *:text:*:#:{ set %wordline.line $1- }

it working for me and doing the stuff you asking for.. so it would be strange if it didnt do the same for you..



if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: if any-line-infile iswm $1- ? #46425 02/09/03 05:33 AM
Joined: Aug 2003
Posts: 29
2
2big Offline OP
Ameglian cow
OP Offline
Ameglian cow
2
Joined: Aug 2003
Posts: 29
yes, but you have two different variables. Look back at your original post. Do I need to set %wordline.line , or do I set %word.line

Re: if any-line-infile iswm $1- ? #46426 02/09/03 05:34 AM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
sorry.. the %var should be the same on both lines.. smile a bit early yet wink


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: if any-line-infile iswm $1- ? #46427 02/09/03 05:40 AM
Joined: Aug 2003
Posts: 29
2
2big Offline OP
Ameglian cow
OP Offline
Ameglian cow
2
Joined: Aug 2003
Posts: 29
It still doesn't work for some reason, can you explain how your code works, I don't get the -1 and how you used the $read identifier.

Re: if any-line-infile iswm $1- ? #46428 02/09/03 05:47 AM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
Code:
on *:text:*:#:{
    set %word.line 1
    :word
    if ( $read -l $+ %word.line $mircdir $+ \text.txt == $null ) { halt }
    elseif ( $read -l $+ %word.line $mircdir $+ \text.txt isin $1- ) { goto command }
    else { inc %word.line | goto word }
    :command
    [color:red] what you want to happen [/color]
    else { halt }
    :end
 }


that should work out for you..

or was it somthing else u wondered about? smile

ahh.. its -L not -1 .. just that its the small l.. and it indicates "line" if i dont remember wrong.. long time since i wroted that thingie smile

Last edited by sparta; 02/09/03 05:51 AM.

if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: if any-line-infile iswm $1- ? #46429 02/09/03 07:48 AM
Joined: Mar 2003
Posts: 1,271
L
LocutusofBorg Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Mar 2003
Posts: 1,271
I might add that since you're performing a read operation everytime, this will be slow, especially with long sentences or a lot of chat. You might wanna switch to using a variable holding the bad words (small list) or a hash table (big list).


DALnet #Helpdesk
I hear and I forget. I see and I remember. I do and I understand. -Confucius
Re: if any-line-infile iswm $1- ? #46430 02/09/03 08:08 AM
Joined: Sep 2003
Posts: 156
B
bleach Offline
Vogon poet
Offline
Vogon poet
B
Joined: Sep 2003
Posts: 156
on *:text:*:#: {
var %i = 1
while (%i <= $lines($myfile)) {
if ($read($myfile,%i) isin $strip($1-)) { .msg $chan one of the words in $&
what you just said, is in the file example.txt
}
inc %i
}
halt
}
alias -l myfile return $+(",$mircdirexample.txt,")
;I hope that could help you.. good luck =)

Re: if any-line-infile iswm $1- ? #46431 02/09/03 11:37 AM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Do you want to do
if (<any line in file> iswm $1-)
or
if (<any line in file> isin $1-)

There's a difference between those two. For example, if your file is:
Code:
one 
two
three
four
and $1- is "I'm the one",
(one iswm $1-) , as well as (two iswm $1-), (three iswm $1-) are FALSE, but
(one isin $1-) is TRUE. For iswm to work, your items should be enclosed in *'s, ie the file should look like:
Code:
*one*
*two*
*three*
*four*


If the file has the 2nd format (ie the items are surrounded by *'s), there is a quick way to check $1- against the entire file at once (without a loop) by using hash tables and taking advantage of $hfind's W switch:
Code:
alias something {
  if !$hget(wordslist) {
    if !$isfile(wordslist.txt) { return }
    hmake wordslist
    hload -n wordslist wordslist.txt
  }
  if $hfind(wordslist,$strip($1),1,W).data { return $true }
  return $false
}
An example usage would be:
Code:
on *:text:*:?: if $something($1-) { msg $nick You just said something that matches the file! }
You can find a detailed explanation about $hfind 'reverse wildcard' feature here ($hfind used to be $hmatch back when that article was written).

If you want to do an "isin" check, I'm afraid you can't do it in one go, so you'd have to loop through the lines in the file one by one. Luckily, with the new /f* commands, this can be quite fast without having to do any tricks:
Code:
alias something {
  .fopen a wordslist.txt
  if $ferr { return }
  var %a = $strip($1)
  while !$feof {
    if $fread(a) isin %a {
      .fclose a
      return $true
    }
  }
  .fclose a
  return $false
}


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: if any-line-infile iswm $1- ? #46432 02/09/03 12:05 PM
Joined: Aug 2003
Posts: 29
2
2big Offline OP
Ameglian cow
OP Offline
Ameglian cow
2
Joined: Aug 2003
Posts: 29
Thank all of you for the help ^_^, I've manage to improvise and somewhat use all of the examples you gave me. Qwerty, I was originally using iswm.

Re: if any-line-infile iswm $1- ? #46433 03/09/03 03:12 AM
Joined: Aug 2003
Posts: 29
2
2big Offline OP
Ameglian cow
OP Offline
Ameglian cow
2
Joined: Aug 2003
Posts: 29
qwerty, I used your first method, and I didn't realize this until now, but it only lets me keep about 7 lines on the file, otherwise it won't read the rest and count it as a word to search in the $1-. Any ideas?

Re: if any-line-infile iswm $1- ? #46434 03/09/03 07:40 AM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
What do you mean exactly? You cannot write more than 7 lines in the file? If this is the case, do you get any error message? Also note that the first method uses /hload to load the file to a hash table. Then the script reads from the hash table, meaning that if you add new lines to the file, the script won't know until you /hload the file again. If you want to add new entries during the time the script is active you can add them to the hash table with /hadd and use /hsave periodically (or inside an on EXIT event) to save it to the file.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com