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.

Page 1 of 3 1 2 3

Link Copied to Clipboard