|
Joined: Oct 2005
Posts: 71
Babel fish
|
OP
Babel fish
Joined: Oct 2005
Posts: 71 |
ah very nice ,thank you so much Tomao (and anyone else that helped) ,you have earned your cookie
|
|
|
|
Joined: Sep 2005
Posts: 2,881
Hoopy frood
|
Hoopy frood
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: 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)
|
|
|
|
Joined: Jul 2007
Posts: 1,129
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,129 |
Nice, Hixxy. I didn't think of using the $ini() identifier. ^^ But about //noop $read(nonexistentfile.mrc) It didn't return a thing. Even if I've changed it //noop $read(mirc.ini) , nothing gets returned.
|
|
|
|
Joined: Jul 2007
Posts: 1,129
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,129 |
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?
|
|
|
|
Joined: Sep 2005
Posts: 2,881
Hoopy frood
|
Hoopy frood
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: //noop $findfile($mircdir,*,0,echo -s $1-) $ini() will work with text files too.
|
|
|
|
Joined: Jul 2007
Posts: 1,129
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,129 |
Thanks for your humble explanation, hixxy. I, to some degree, know what noop does, and it works quite the same as and Excuse me for overlooking your point.
|
|
|
|
Joined: Sep 2005
Posts: 2,881
Hoopy frood
|
Hoopy frood
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
|
|
|
|
Joined: Oct 2005
Posts: 71
Babel fish
|
OP
Babel fish
Joined: Oct 2005
Posts: 71 |
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?
|
|
|
|
Joined: Jul 2007
Posts: 1,129
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,129 |
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. 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. 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.
|
|
|
|
Joined: Feb 2006
Posts: 546
Fjord artisan
|
Fjord artisan
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:
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
|
|
|
|
Joined: Jul 2007
Posts: 1,129
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,129 |
jaytea, very nice suggestion, but you're sort of making it more perplexed for beginners...:p
|
|
|
|
Joined: Oct 2005
Posts: 71
Babel fish
|
OP
Babel fish
Joined: Oct 2005
Posts: 71 |
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.
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 .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 /me slips Tomao a bonus cookie
|
|
|
|
Joined: Sep 2005
Posts: 2,881
Hoopy frood
|
Hoopy frood
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: 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.
|
|
|
|
Joined: Oct 2005
Posts: 71
Babel fish
|
OP
Babel fish
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
|
|
|
|
Joined: Oct 2005
Posts: 71
Babel fish
|
OP
Babel fish
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: * /play: topic '[100]' not found in 'faq.db' (line 19, FAQ.mrc)
Here is an example of the channel output with the 2009 problem: <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:
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:
[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:
$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.
|
|
|
|
Joined: Jul 2007
Posts: 1,129
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,129 |
For some reason, the won't take numbers. I have no idea why. After changing it to this: if ($read(%f,nw,$+([,$2,]))) { play $+(-nt,%x) $nick %f } It works.
|
|
|
|
Joined: Oct 2005
Posts: 71
Babel fish
|
OP
Babel fish
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 D00M
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
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
|
|
|
|
Joined: Jul 2007
Posts: 1,129
Hoopy frood
|
Hoopy frood
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.
|
|
|
|
Joined: Oct 2005
Posts: 71
Babel fish
|
OP
Babel fish
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: * 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
|
|
|
|
|