mIRC Home    About    Download    Register    News    Help

Print Thread
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.

Joined: Feb 2003
Posts: 3,432
S
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,.) }
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.

Joined: Feb 2003
Posts: 3,432
S
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,.) }
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?

Joined: Feb 2003
Posts: 3,432
S
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,.) }
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

Joined: Mar 2003
Posts: 1,271
L
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
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-.

Joined: Feb 2003
Posts: 3,432
S
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,.) }
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

Joined: Feb 2003
Posts: 3,432
S
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,.) }
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.

Joined: Feb 2003
Posts: 3,432
S
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,.) }
Joined: Mar 2003
Posts: 1,271
L
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
Joined: Sep 2003
Posts: 156
B
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 =)

Joined: Jan 2003
Posts: 2,523
Q
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
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.

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?

Joined: Jan 2003
Posts: 2,523
Q
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

Link Copied to Clipboard