mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 3 1 2 3
#229410 03/02/11 12:13 PM
Joined: Oct 2005
Posts: 71
D
D00M Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Oct 2005
Posts: 71
I'm trying to make a FAQ script for when someone joins the channel and types !FAQ they get a notice with a list of Q&A's.Is there a better/cleaner way of writing this and also how would I make it display the notice to them slower? The FAQ will end up being pretty large and i dont want to flood them/me out with it.


Code:
On *:Text:*:#MYCHAN:{
  if (!FAQ isin $1-) { 
.notice $nick Q. Question 1 here
.notice $nick A. Answer goes here

.notice $nick Q. Question 2 here
.notice $nick A. Answer goes here

.notice $nick Q. Question 3 here
.notice $nick A. Answer goes here
  }
}


Any pointers would be great ,TIA

D00M #229411 03/02/11 12:23 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Put your FAQ in a text file and use /play. You can set the time delay in /play so that you won't get flooded off no matter how many lines are there.


Invision Support
#Invision on irc.irchighway.net
Riamus2 #229412 03/02/11 01:12 PM
Joined: Oct 2005
Posts: 71
D
D00M Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Oct 2005
Posts: 71
ah ok ,i didnt think of that,would something like this be ok you think ?

Code:
On *:Text:*:#MYCHAN:{
  if (!FAQ isin $1-) { 
/play -n c:\text\FAQ.txt 1000
  }
}


I tried the above and it worked but it seems to also spam my status window with the info in the txt file,
Quote:

* Playing 'FAQ.txt' to Z0n3r with 1000ms delay
--------------------
[12:05am] -> -Z0n3r- Q. Question 1 here
--------------------
[12:05am] -> -Z0n3r- A. Answer here
--------------------
[12:05am] -> -Z0n3r- Q. Question 2 here
--------------------
[12:05am] -> -Z0n3r- A. Answer here
--------------------
[12:05am] -> -Z0n3r- Q.question 3 here
--------------------
[12:05am] -> -Z0n3r- A. Answer here
--------------------
* Playback of 'FAQ.txt' complete


Is there a way so it doesn't spam my status window?
And how would I go about adding more triggers?

I tried the following but it only seems to work on the first one:

Code:
On *:Text:*:#MYCHAN:{
  if (!FAQ isin $1-) { 
    /play -n $nick c:\InvisionOLD\Text\FAQ.txt 1000
  }
}
On *:Text:*:#MYCHAN:{
  if (!clog isin $1-) { 
    /play -n $nick c:\InvisionOLD\Text\MMlog.txt 1000
  }
}
On *:Text:*:#MYCHAN:{
  if (!latest isin $1-) { 
    .notice $nick http://some_website.com
  }
}


As I said it only see's the first one (!FAQ) but when someone types !clog or !latest it doesnt respond,any help would be great wink

Last edited by D00M; 03/02/11 02:01 PM.
D00M #229413 03/02/11 02:21 PM
Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Try this (you seem to already know about . silencing commands):
Code:
on *:TEXT:*:#mychan:{
  if ($1 == !FAQ) .play -n $nick c:\InvisionOLD\Text\FAQ.txt 1000
  elseif ($1 == !clog) .play -n $nick c:\InvisionOLD\Text\MMlog.txt 1000
  elseif ($1 == !latest) .notice $nick http://some_website.com
}

Multiple on TEXT events will not work if their matchtext section (in your case *) are already matched by an on TEXT event earlier in the script.

5618 #229414 03/02/11 02:52 PM
Joined: Oct 2005
Posts: 71
D
D00M Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Oct 2005
Posts: 71
Originally Posted By: 5618

Multiple on TEXT events will not work if their matchtext section (in your case *) are already matched by an on TEXT event earlier in the script.


Ah I see there is still lots I need to learn ,working like a treat btw 5618,thanks for the help guys wink

D00M #229416 03/02/11 04:38 PM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
An alternative suggestion
Code:
on *:TEXT:*:#mychan:{
  if ($1 == !latest) .notice $nick http://some_website.com
  elseif $istok(!FAQ !clog,$1,32) {
    .play -n $nick c:\InvistionOLD\Text\ $+ $iif($1 == !FAQ,FAQ.txt,MMlog.txt) 1000
  }
}


RusselB #229419 03/02/11 04:44 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Although that's not bad for 2 commands, it will quickly become a pain if you want to add more commands. I'd leave it as multiple elseif lines (one per command).

If you do want to use $istok() to have a single elseif, then I'd suggest naming the files with the same name as the command and using $remove($1,!) $+ .txt for the filename instead of using $iif(). That is actually more efficient than multiple elseifs, but you are basically required to use the same filename as the command, which may or may not be what the OP wants.

Example:
Code:
on *:TEXT:*:#mychan:{
  if ($1 == !latest) .notice $nick http://some_website.com
  elseif $istok(!FAQ !clog !othercommand !yetonemorecommand,$1,32) {
    .play -n $nick c:\InvistionOLD\Text\ $+ $remove($1,!) $+ .txt 1000
  }
}

Filenames for the above example would need to be: faq.txt, clog.txt, othercommand.txt, and yetonemorecommand.txt

To the OP: Be advised that although 1000 works well for smaller outputs, it's still often too fast for long outputs. I'd recommend 1500 as that will usually work. However, you may have to adjust it higher yet if you have a really long FAQ or log or anything else depending on the server. Just try it out and if you get kicked for excess flooding, increase it. 2000 is very slow, but it is also pretty much immune from excess flood kicks except in cases when you are lagging badly and suddenly send many lines at once to the server. Anyhow, you can set different time delays for each command. Shorter outputs can be set lower without much of a problem, for example.

Last edited by Riamus2; 03/02/11 04:51 PM.

Invision Support
#Invision on irc.irchighway.net
Riamus2 #229420 03/02/11 05:16 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Or better yet (requires no modification of the script, only extra files):

Code:
alias -l cmdfile { return $scriptdirCommands\ $+ $1.txt }

on *:text:!*:#mychan:{
  if ($1 == !latest) { .notice $nick http://www.some_website.com }
  elseif ($isfile($cmdfile($mid(1,2)))) { .play -n $nick $qt($cmdfile($mid(1,2))) }
}


For this to work you need to create a "Commands" subdirectory in the same directory as the script, and put all of the different text files you want to be able to play in that directory.

hixxy #229421 03/02/11 07:19 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Heh, nice. I probably wouldn't choose to do a script that way myself, but it's definitely an interesting way to handle commands. laugh


Invision Support
#Invision on irc.irchighway.net
Riamus2 #229494 07/02/11 11:21 AM
Joined: Oct 2005
Posts: 71
D
D00M Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Oct 2005
Posts: 71
Hey guys ,back to pick your brains again,

The above !FAQ works nice but it will end up becoming very large and take a lifetime for it to finish the notice and its not very specific.So we thought of trying to make a script that when users type in the chan as an example: !faq TEST or !faq BSG or what ever, it will search a txt file for the key word and return the result to them as a .notice. A friend and I managed to get this far but seemed to have hit a wall (he knows more than me but we are still both learning) so here is what we have so far:

Code:
on *:TEXT:!faq*:#MYCHAN: {
  .notice $nick Results:- " $+ $read(faq.txt) $+ "
}
menu * {
  .Update FAQs: var %a $?="Add FAQs Answers Here ,e.g BSG - ANSWER HERE:" | write FAQ.txt %a
}


And this is what I have in the text file

Quote:

BSG - ANSWER_HERE
TEST - ANSWER_HERE
TEST2 - ANSWER_HERE
TEST3 - ANSWER_HERE
TEST4 - ANSWER_HERE


Ok first Im not sure how I should have the text file setup so it returns the correct results or if we are even going about it the right way.As it stands I can update/write single lines to the faq.txt file with a right click on the screen and select Add FAQs from the menu,which is what we want so that part works fine but when we try to search the text it just comes back with random lines from the .txt file.This is what we get in the chan:

Quote:

[9:21pm] <Z0n3r> !faq BSG
[9:21pm] *D00M* Results:- "TEST3 - ANSWER_HERE"
[9:21pm] <Z0n3r> !faq BSG
[9:21pm] *D00M* Results:- "TEST - ANSWER_HERE"
[9:22pm] <Z0n3r> !faq test2
[9:22pm] *D00M* Results:- "TEST4 - ANSWER_HERE"
[9:22pm] <Z0n3r> !faq test2
[9:22pm] *D00M* Results:- "TEST3 - ANSWER_HERE"
[9:22pm] <Z0n3r> !faq test2
[9:22pm] *D00M* Results:- "TEST3 - ANSWER_HERE"
[9:22pm] <Z0n3r> !faq test2
[9:22pm] *D00M* Results:- "TEST - ANSWER_HERE"
[9:22pm] <Z0n3r> !faq test2
[9:22pm] *D00M* Results:- "TEST4 - ANSWER_HERE"


So as you can see its just calling random lines from the faq.txt file instead of the answer we want.Any help tips would be great ,TIA wink

D00M #229495 07/02/11 11:28 AM
Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
See /help $read
E.g. $read(faq.txt,sn,$$2) where $$2 is the word after !faq. This scans the txt file for a line beginning with $2 and returns whatever is after the match (in your case "- ANSWER_HERE").

5618 #229496 07/02/11 11:38 AM
Joined: Oct 2005
Posts: 71
D
D00M Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Oct 2005
Posts: 71
Thanks 5618 on the heads up with $$2 ,it seems to be working nice now wink

Quote:

[10:02pm] <+Z0n3r> !faq bsg
[10:02pm] *D00M* Results:- "- BSG_ANSWER_HERE"
[10:02pm] <+Z0n3r> !faq bsg
[10:02pm] *D00M* Results:- "- BSG_ANSWER_HERE"
[10:03pm] <+Z0n3r> !faq test3
[10:03pm] *D00M* Results:- "- TEST3_ANSWER_HERE"
[10:03pm] <+Z0n3r> !faq test4
[10:03pm] *D00M* Results:- "- TEST4_ANSWER_HERE"
[10:03pm] <+Z0n3r> !faq test10
[10:03pm] *D00M* Results:- "- TEST10_ANSWER_HERE"


Again thanks for the help wink


D00M #229498 07/02/11 02:36 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Keep in mind that they way you have it, you can't actually update a specific item in the FAQ from your menu. It will just add the item to the file a second time and still only read the original. You might consider using an INI file instead or else check to see if the item exists in the file before writing the update and if it exists, overwrite that line or else delete it and add the new line.


Invision Support
#Invision on irc.irchighway.net
Riamus2 #229576 09/02/11 05:19 PM
Joined: Oct 2005
Posts: 71
D
D00M Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Oct 2005
Posts: 71
Originally Posted By: Riamus2
You might consider using an INI file instead or else check to see if the item exists in the file before writing the update and if it exists, overwrite that line or else delete it and add the new line.


We are finding out now that you maybe right lol.Although it works for the most part,we are already starting to run into trouble.

Basically we are trying to have a txt file that has a list of Q&A's (question on one line and the answer on the second line) with a space then the next Q&A and so on.

Example of the txt file:

Code:
question1 here
answer 1 here

question2 here
answer2 here


I thought having a key word would make it easy but I found that the key word can mean more than one result and its hard to come up with common key words and we had to have the Q&A all on one line so it noticed it all to the user.

How would we go about making it so a user can come in and type !faq MY QUESTION HERE and have it search the whole entire txt (or ini as you said if thats better) and return all the answers in the file.

Code:

<user1> !faq my question here (could be up to 8 words)
*D00M* Found:- "your answer1"
*D00M* Found:- "your answer2"
*D00M* Found:- "your answer3"
<user4> !faq my question here (could be up to 4 words)
*D00M* Found:- "your answer1"
*D00M* Found:- "your answer2"


The above is basically what we are trying to do and as you said Riamus2 updating is really a fail.We can add a single line to the txt (with no real control/spaces) but to delete or replace lines I have to edit the txt itself outside of mirc. To be honest I think we are in over our heads but any tips would be great ,TIA wink

Code we have atm:
Code:
on *:TEXT:*:#MY_CHAN:{
  if ($1 == !help) .notice $nick Here is a list of triggers that are used in this channel: !clog  (latest change log) - !kw (list of key words for !faq) - !faq KEY_WORD (e.g. !faq BSG) - !version (Main thread LINK HERE). 
  elseif ($1 == !clog) .play -n $nick c:\InvisionOLD\clog.txt 1000
  elseif ($1 == !faq) .notice $nick Found:- " $+ $read(faq.txt,sn,$$2) $+ "
  elseif ($1 == !kw) .play -n $nick c:\InvisionOLD\kw.txt 1000
  elseif ($1 == !version) .notice $nick Current version: x.xx.xx http://some.website.com
}
menu * {
  .Add FAQs: var %a $?="Add FAQs Here ,e.g BSG - ANSWER HERE:" | write FAQ.txt %a
}



Last edited by D00M; 09/02/11 05:24 PM.
D00M #229577 09/02/11 06:01 PM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
You're looking at the $read identifier with its -s switch:
Code:
on *:TEXT:!faq *:#MY_CHAN:{
 if ($read(file.txt,s,$2)) {
  msg # $v1
}
}
So in your text file, you have the question set up as:
Quote:
Question1 Here is the answer for Q1
Question2 Here is the answer for Q2
Question3 Here is the answer for Q3
Once a user enters
Quote:
!faq Question1
The code will scan that particular line and output
Quote:
Here is the answer for Q1
And so on and so forth.

Tomao #229585 10/02/11 03:08 AM
Joined: Oct 2005
Posts: 71
D
D00M Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Oct 2005
Posts: 71
looks like $read is some of the problem as it can only return single lines if I understand correctly.My mate said something about he was going to look into regex with %var but like I said we are far from experts on any of this. The above works for the most part so thanks for trying to help guys wink

D00M #229586 10/02/11 03:23 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
While $read will only return one line, you can make it look like multiple lines by using $crlf in the line that is being read.
Note: In order for this to work, you'll have to drop the n switch from the $read

Another option, that I just thought of, is to format your txt file like this
Quote:

[topic]
line 1
line 2
line 3
.
.
.

Then use /play -ttopic file.txt

See /help /play for more information.

Last edited by RusselB; 10/02/11 03:25 AM.
D00M #229589 10/02/11 07:18 AM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Yes, like RusselB has pointed out, the -t switch is very handy to play all the messages into the channel within a certain topic enclosed by the [ ]. Then all you have to do is modify the code around like so:
Code:
on *:TEXT:!faq *:#MY_CHAN:{
   var %f = file.txt
   if ($isfile(%f)) && ($read(%f,nw,$+([,$2,]))) {
    .play $+(-t,$2) # %f
  }
}
Upon someone entering the command !faq Question1, it'll message all the lines to the channel under Question1. Question2 for all the lines under it. You must set up your text file like this:
Quote:
[Question1]
1st line
2nd line
3rd line
4th line
[Question2]
1st line
2nd line
3rd line
4th line
5th line
[Question3]
so on and so forth...

Tomao #229599 10/02/11 06:41 PM
Joined: Oct 2005
Posts: 71
D
D00M Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Oct 2005
Posts: 71
Ah nice one Tomao ,can [question1] thats setup in the txt file to be more than one word? e.g:

[question one here]

As in can there be spaces or is it limited to a single word?

D00M #229600 10/02/11 07:12 PM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
As far as I know it doesn't accept the spaces inside the brackets. But you can manipulate them. In your text file, make it like this:
Quote:
[question_one_here]
Then the code like so:
Code:
on *:TEXT:!faq *:#MY_CHAN:{
  var %f = file.txt, %x = $replace($2-,$chr(32),_)
  if ($isfile(%f)) && ($read(%f,nw,$+([,%x,]))) {
    .play $+(-t,%x) # %f
  }
}
The user can then enter command as usual with spaces:
Quote:
!faq question one here
What happens is that the $replace identifier will change all the spaces to underscores, which will then match with the topics exactly.

Tomao #229607 11/02/11 02:51 AM
Joined: Oct 2005
Posts: 71
D
D00M Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Oct 2005
Posts: 71
ah very nice ,thank you so much Tomao (and anyone else that helped) ,you have earned your cookie wink

Tomao #229618 11/02/11 06:02 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Rather than use $read() I would suggest using $ini() for checking the existence of a topic in the ini file, it's more suitable:

Code:
on *:TEXT:!faq *:#MY_CHAN:{
  var %f = file.txt, %x = $replace($2-,$chr(32),_)
  if ($ini(%f,%x)) {
    .play $+(-t,%x) # %f
  }
}


There's also no need to check $isfile() before using $ini() or $read(). mIRC is a pretty relaxed scripting language and does a lot of internal error checking. It doesn't raise an error if you try to read a file that doesn't exist. Try it: //noop $read(nonexistentfile.mrc)

hixxy #229624 11/02/11 09:33 PM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Nice, Hixxy. I didn't think of using the $ini() identifier. ^^ But about
Quote:
//noop $read(nonexistentfile.mrc)
It didn't return a thing. Even if I've changed it //noop $read(mirc.ini) , nothing gets returned.

hixxy #229626 11/02/11 09:37 PM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Quote:
Rather than use $read() I would suggest using $ini() for checking the existence of a topic in the ini file, it's more suitable:
The thing is, it uses a text file, not an ini file.

I'm not sure if the use of $ini will apply to the text file to match the string inside the brackets.

Perhaps you meant to tell me the use of $ini can mimic the ini format stored in a .txt?

Tomao #229628 11/02/11 10:15 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
It doesn't return anything, but that's my point.. even though the file doesn't exist mIRC doesn't raise an error.

/noop is a command that does nothing with the return value of the identifier. It's for identifiers that you don't need to do anything with the out, such as $findfile:

Code:
//noop $findfile($mircdir,*,0,echo -s $1-)


$ini() will work with text files too.

hixxy #229629 11/02/11 10:21 PM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Thanks for your humble explanation, hixxy. smile

I, to some degree, know what noop does, and it works quite the same as
Code:
.echo -q
and
Quote:
.xyzzy
Excuse me for overlooking your point. blush

Tomao #229630 11/02/11 10:30 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
You're right, /.echo -q used to be the only way to suppress the output until /noop was added smile

hixxy #229635 12/02/11 05:12 AM
Joined: Oct 2005
Posts: 71
D
D00M Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Oct 2005
Posts: 71
Originally Posted By: hixxy

Code:
on *:TEXT:!faq *:#MY_CHAN:{
  var %f = file.txt, %x = $replace($2-,$chr(32),_)
  if ($ini(%f,%x)) {
    .play $+(-t,%x) # %f
  }
}



Hey hixxy ,I tried your code and it seems to work nice,it still responds as it should but im trying to understand the code itself so if I need to update it (like a notice instead of a msg to the chan or have it say no results if it doesnt find a result ect..) Can you explain to me or point me in the right direction with a little explaination of your code?

D00M #229637 12/02/11 07:02 AM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Originally Posted By: D00M
Can you explain to me or point me in the right direction with a little explaination of your code?
What hixxy has suggested is simple to explain, he takes advantage of the $ini() identifier used for mIRC INI for the setup of a text file, because it just so happens that [string] is what a INI file would look like as a topic. If you read the help file for the $ini identifier, you'll get a grasp of it easily.
Originally Posted By: D00M
I need to update it (like a notice instead of a msg to the chan or have it say no results if it doesnt find a result ect..)
To make the message displayed as a notice, just add the -n switch, along with an else condition to tell a user if a topic exists or not.
Quote:
on *:TEXT:!faq *:#MY_CHAN:{
var %f = file.txt, %x = $replace($2-,$chr(32),_)
if ($ini(%f,%x)) { .play $+(-nt,%x) $nick %f }
else { notice $nick Sorry the topic $qt($2-) does not exist! }
}
And since you choose notice, it'd be better to replace # with $nick. But you can use # if you wish.

hixxy #229638 12/02/11 07:56 AM
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
unfortunately $ini() is one of those identifiers that accepts 'N/name', but /play -t only accepts a name :P i would suggest using /play directly and just trapping any errors, saves mIRC having to access the file multiple times in the successful case:

Code:
  play -t $+ %x # %f
  return

  :error

  if (? /play: unable to open * iswm $error) {
    reseterror
    ; file not found
  }

  elseif (? /play: topic ?& not found * iswm $error) {
    reseterror
    ; topic not found
  }


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
jaytea #229640 12/02/11 08:10 AM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
jaytea, very nice suggestion, but you're sort of making it more perplexed for beginners...:p

Tomao #229641 12/02/11 10:03 AM
Joined: Oct 2005
Posts: 71
D
D00M Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Oct 2005
Posts: 71
Originally Posted By: Tomao
To make the message displayed as a notice, just add the -n switch, along with an else condition to tell a user if a topic exists or not.

on *:TEXT:!faq *:#MY_CHAN:{
var %f = file.txt, %x = $replace($2-,$chr(32),_)
if ($ini(%f,%x)) { .play $+(-nt,%x) $nick %f }
else { notice $nick Sorry the topic $qt($2-) does not exist! }
}
and since you choose notice, it'd be better to replace # with $nick. But you can use # if you wish.


Originally Posted By: Tomao
jaytea, very nice suggestion, but you're sort of making it more perplexed for beginners...:p


lol well my head is already spinning form all this so yes,jayteas code through me for a loop laugh .I ended up trying what you said Tomao and this is exactly what we were trying too do.I can see from your code that we wouldn't have got it anytime soon lol.I did try playing around with the -n switch and also tried .notice but I can see I was way off.

What throws me so much is understanding all the $ % & * ect.. and were they are ment to go.. but I'm sure that will come over time.At the moment a user comes in and types !faq some question here and it rips through the text file we have (which have over 1200 lines of txt) and within a second it notices the user in the room if it finds something or not,this is awesome and exactly what we want.Thanks heaps guys you have all been great wink

/me slips Tomao a bonus cookie laugh

jaytea #229645 12/02/11 02:53 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Good point!

D00M,

As for an explanation of the code and yours and jaytea's suggested improvements, here's a commented version:

Code:
on *:TEXT:!faq *:#MY_CHAN:{

  /*
  Set %f to the location of the file, and %x to be the name of the topic in the ini file you want to read from. 

  If the requested topic is a number, it will read the Nth topic from the file. 

  0 is an invalid name for a topic, as $ini() will return the number of topics in the file if you use $ini(<file>,0) rather than the actual topic called 0.
  */

  var %f = file.txt, %x = $iif($2 isnum 1-,$ini(%f,$2),$iif($2- == 0,$null,$replace($2-,$chr(32),_)))

  ; $ini(%f,%x,0) will check that the topic you want to read exists and also that some data exists under that topic before attempting to /play it. 

  if ($ini(%f,%x,0)) {

    /*
    This /play command will read the contents of the specified topic (%x) in the ini file (%f).

    It will then send those contents as notices (the -n switch) to the channel (#) with a default delay of 1 second between each message.
    */

    .play $+(-nt,%x) # %f
  }

  ; else.. this code block will trigger if the requested topic does not exist or if there's no data under the topic.

  else {

    /*
    This code block will prevent people from flooding you off the server by typing !faq <non_existent_topic> lots of times.

    What it does is, if the variable %faq.flood does not exist, it sets this variable to "1" for 3 seconds and sends a notice telling the channel that the request topic doesn't exist. 

    Whilst this variable exists the code will not trigger. After 3 seconds the variable will unset and the code will trigger again.
    */

    if (!%faq.flood) {
      inc -u3 %faq.flood
      .notice # No such FAQ topic: %x
    }
  }
}


jaytea's version is good too, but as stated it's perhaps a bit more complex than performing your own error checking.

hixxy #229680 13/02/11 06:47 PM
Joined: Oct 2005
Posts: 71
D
D00M Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Oct 2005
Posts: 71
ah nice hixxy thank you very much for the breakdown of the code,it helps me alot.I added the flood protection to the script and it works like a treat,thanks again for the explanation wink

D00M #231301 11/04/11 02:22 PM
Joined: Oct 2005
Posts: 71
D
D00M Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Oct 2005
Posts: 71
Hi guys ,back again to pick your brains.Rather than open a new thread I thought I'd post here since its related to the same script.The below script is what we have come up with after all your help here (which was great btw) but we have found a problem and cant seem to get it right.

The problem is if someone comes in and does say, !faq 2009 it doesnt find my topic with [2009],it just returns nothing found in the notice.Also if they say for example search !faq 100 (or any number below 1000) and I don't have [100] as a topic ,it will give the following error in my status window:
Quote:

* /play: topic '[100]' not found in 'faq.db' (line 19, FAQ.mrc)


Here is an example of the channel output with the 2009 problem:

Quote:

<DOOM> !faq opened channel
*FAQBot* The channel was opened in 2009 by D00M!
<DOOM> !faq 2009
*FAQBot* Sorry Your Question " 2009 " was not found!


Here is the script we ended up with:
Code:
on *:TEXT:!faq*:#MY_CHAN:{
  inc %faq69
  var %f = faq.db, %x = $replace($2-,$chr(32),_)
  if ($ini(%f,%x)) { play $+(-nt,%x) $nick %f }
  else {
    if (!%faq.flood) {
      inc -u3 %faq.flood
      notice $nick Sorry Your Question " %x " was not found!
    }
  }
}


And here is an example of the faq.db setup:
Code:
[channel]
The channel was opened in 2009 by D00M!
[Opened]
The channel was opened in 2009 by D00M!
[2009]
The channel was opened in 2009 by D00M!
[channel_Opened]
The channel was opened in 2009 by D00M!
[Opened_Channel]
The channel was opened in 2009 by D00M!
[Opened_2009]
The channel was opened in 2009 by D00M!


We tried:

Code:
$iif($2- == 0,$null,$replace($2-,$chr(32),_)))


but its still not returning the number 2009 (or any number above 1000) when in fact they are in the faq.db or gives the status window error above with any number not present below 1000 instead of noticing the nick it wasnt found.Everything as worked great up until now so any help/advice again would be great,TIA

DOOM.


Last edited by D00M; 11/04/11 06:57 PM.
D00M #231304 11/04/11 05:12 PM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
For some reason, the
Code:
 $ini()
won't take numbers. I have no idea why.

After changing it to this:
Code:
if ($read(%f,nw,$+([,$2,]))) { play $+(-nt,%x) $nick %f }
It works.

Tomao #231307 11/04/11 06:54 PM
Joined: Oct 2005
Posts: 71
D
D00M Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Oct 2005
Posts: 71
Yes ,we didnt have any problems with the script what so ever until we did the numbers and noticed no return on my query.I un silenced it to see what was up and thats what the status window reported.I'v added what you suggested and it is now working like a charm again ,exactly what we wanted/needed ,thank you Tomao once again wink

D00M

D00M #231309 11/04/11 08:17 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
$ini() and other identifiers use numbers to select the specific numbered item if you don't know the item name. For example, $chan(1) will give you the first channel. Using numbers as item names or section names in an INI file can give you problems because of that. Anytime you see N in the help file for an identifier, you know that it probably will take a number and look up the Nth item rather than looking up an item with that numbered name.

I'd suggest not using numbers or else making sure every number is represented (no missing numbers) so that the first item is 1, the second is 2, and so on. That way when you look up item 1, you'll get the item with the name of 1. Ideally, you'd just avoid using numbers, but that's up to you.


Invision Support
#Invision on irc.irchighway.net
D00M #231311 11/04/11 09:29 PM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Oh right. Riamus2 has brought up the main reason why it wouldn't work. The $ini() is trying to find the match for the topic 2009 :P , which probably doesn't exist. According to the help file, $ini(mirc.ini,1) returns the 1st topic and so on. By using $ini() with a number in conjunction with the play command's topic match confuses it! This $ini() suggestion was made by hixxy originally and jaytea confirmed that it may result in a potential error. I suppose we all learn something from our oversight at one point or another. smile

Tomao #231840 06/05/11 03:32 PM
Joined: Oct 2005
Posts: 71
D
D00M Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Oct 2005
Posts: 71
Hey guys,back to pick your brains again,seen as its to do with the above script I thought I'd post here again rather than opening a new thread.

What I'm trying to do is when the script plays a txt file to a user,if a second (or 3rd,4th etc) user triggers the txt file at the same time or while its still playing,it will state in my status window:
Quote:

* Queued 'help.db' to user2 with 1000ms delay


Is there any way I can have that msg that goes to my status window goto the user instead.So basically users are not sitting there thinking the bot isn't responding or something and start spamming the trigger.

user1 !help
user2 !help
user3 !help

it will send user 2 and 3 a notice etc.. (if its still playing the txt to user1) saying they are in Q and it will be displayed shortly.Hope that makes sense lol ,I did have a look in the /help for queuing a played txt file but didn't see anything about it.

TIA D00M

D00M #231841 06/05/11 04:20 PM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
You might want to check if any item is in the play queue:
Code:
TEXT EVENT {
  if ($play(0)) { notice $nick I have $v1 items in my playback queue }

  YOUR CODE, e.g. /play to $nick
}


In case you want to check for a specific file, you'll have to loop all items in the play queue, for example:
Code:
TEXT EVENT {
  var %n = 1, %queued = 0
  while ($play(%n)) {
    if ($nopath($play(%n).fname) == help.db) { inc %queued }
    inc %n
  }
  if (%queued) { notice $nick I have $v1 requests for "help.db" in my playback queue }

  YOUR CODE, e.g. /play to $nick
}



Horstl #231870 08/05/11 05:26 PM
Joined: Oct 2005
Posts: 71
D
D00M Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Oct 2005
Posts: 71
EDIT:

Thanks Horstl it worked great wink

Last edited by D00M; 08/05/11 06:45 PM.
D00M #231872 08/05/11 05:46 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
"TEXT EVENT" refers to your actual text event.

For example:

Code:
on *:TEXT:!faq*:#MY_CHAN:{


It's just saying that you use it within your text event(s).


Invision Support
#Invision on irc.irchighway.net
Riamus2 #231873 08/05/11 06:16 PM
Joined: Oct 2005
Posts: 71
D
D00M Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Oct 2005
Posts: 71
Originally Posted By: Riamus2
"TEXT EVENT" refers to your actual text event.

For example:

Code:
on *:TEXT:!faq*:#MY_CHAN:{


It's just saying that you use it within your text event(s).


lol oh ok my bad ,I think I get it now.I did the above suggestion and it worked great ,thanks again guys as always wink

Last edited by D00M; 08/05/11 06:43 PM.
Page 1 of 3 1 2 3

Link Copied to Clipboard