mIRC Home    About    Download    Register    News    Help

Topic Options
#171267 - 22/02/07 03:44 AM response bot (?) read from text file?
daTerminehtor Offline
Pikka bird

Registered: 17/02/07
Posts: 12
Loc: Great White North
I'm looking for 'something' that will read off different text files, perhaps on a timer, or when the channel has been idle for a while.

Would this perhaps work with a response bot? I don't need/want a full-service (o.O) bot, per-se, just one that issues a response, again, perhaps reading off different text files.

The bots that I've managed to locate offer too many options (protection bots, if you will) and I really don't need that.

Is this/these possible?

Top
#171274 - 22/02/07 04:10 AM Re: response bot (?) read from text file? [Re: daTerminehtor]
drc4 Offline
Vogon poet

Registered: 22/11/05
Posts: 105
Loc: Dover, Delaware
If you can be more specific on how often you want a text file read, and if the text file is just full of one-liners, or multipe lines, I'm sure you'd get a quick response. If you want to try to take a crack at it yourself look at /help timer and /help $read

Top
#171275 - 22/02/07 04:10 AM Re: response bot (?) read from text file? [Re: daTerminehtor]
bwr30060 Offline
Fjord artisan

Registered: 23/05/05
Posts: 449
Loc: Georgia USA
Code:
timer 0 180 {
msg $chan $read(myfile.txt)
}


If you want it to work when the channel is idle, you might want to do something like setting a variable, and unsetting it every time someone says something in the channel. Someone else may have a better way of checking if the channel is idle. The code above will fire every 180 seconds, and in that example, the text file is in your mIRC directory. You can change that number and the file path.
_________________________
Bears on Patrol Chat

Top
#171281 - 22/02/07 04:35 AM Re: response bot (?) read from text file? [Re: bwr30060]
RusselB Offline
Planetary brain

Registered: 03/08/04
Posts: 7252
Loc: Ontario, Canada
You can't have a multiple line timer like that.

Proper format would be
Code:
/timer 0 180 msg $chan $!read(myfile.txt)


The ! in the read statement ensures that a new line is read each time.

Top
#171283 - 22/02/07 04:45 AM Re: response bot (?) read from text file? [Re: daTerminehtor]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: NC, USA
You mentioned a "response bot" in your post. That would make me think you want it to display a message based on a trigger. For example, a !quote script.

For that, you'd do something like this:
Code:
on *:text:!quote:#: {
  set -u5 %Quote.Fld On
  if (!%Quote.Fld) { msg $chan $read(quote.txt) }
}


The %Quote.Fld thing just gives you some basic flood protection (you can only use !quote once every 5 seconds [-u5] ). You can take this and repeat it for a bunch of different triggers if you want to. You could combine them, but repeating it will be easier to figure out on your own and won't hurt anything.

If you want a script that will read a random line from a random TXT file, you can do this:

Code:
alias RndLine {
  var %total = $findfile($qt($scriptdir\Texts),*.txt,0)
  return $read($qt($findfile($qt($scriptdir\Texts),*.txt,$rand(1,%total))))
}


This assumes that your text files are all in a folder called Texts inside your script's folder. You can change this if you want to (replace Texts with whatever folder name you want). For example, if you have mIRC installed in c:\mIRC\ and you have your script saved in c:\mIRC\Bot\ then your text files should all in c:\mIRC\Bot\Texts\ if you don't change "Texts" to something else.

That can be called just by typing /RndLine from the bot, or you can put it in a timer like this:

Code:
on *:connect: {
  .timerRndLine 0 600 $!iif($!me ison #yourchannel,msg #yourchannel RndLine)
}


Replace #yourchannel with the name of your channel. The 600 is the number of seconds between when it happens. 600s = 10min. You can change that if you want to. This will start the timer when you connect to a network and will repeat a random line from a random file every 600 seconds as long as you're in your specified channel.

You can also combine the !quote trigger code with the RndLine alias so that the !quote trigger makes the random line from a random file happen:

Code:
on *:text:!quote:#: {
  set -u5 %Quote.Fld On
  if (!%Quote.Fld) { msg $chan RndLine }
}


To have it work when everyone's been idle for a long time, you can do this:

Code:
on *:text:*:#yourchannel: {
  .timerIdleRndLine 0 600 $!iif($!me ison $chan,msg $chan RndLine)
}


Again, replace #yourchannel with the name of your channel. This will wait until no one has said anything for 10 minutes (600s) and then say a random line from a random text file. It will then wait 10 minutes and say another line if no one talks within that time period. As long as people are talking, it won't say anything. You can change the 600s to something else if you want to.
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#171306 - 22/02/07 04:18 PM Re: response bot (?) read from text file? [Re: Riamus2]
daTerminehtor Offline
Pikka bird

Registered: 17/02/07
Posts: 12
Loc: Great White North
Riamus2

Ya, you nailed it there, thanks (as usual). :p

All files are in the folder \Text, so I am looking for a random line from a random text file to be read every so often. However, with...

Quote:
alias RndLine {
var %total = $findfile($qt($scriptdir\Texts),*.txt,0)
return $read($qt($findfile($qt($scriptdir\Texts),*.txt,$rand(1,%total))))
}


I can't see where I can change the variable for the length of time. Or is it a matter of combining the scripts as such...

Quote:
alias RndLine {
var %total = $findfile($qt($scriptdir\Texts),*.txt,0)
return $read($qt($findfile($qt($scriptdir\Texts),*.txt,$rand(1,%total))))
}

on *:connect: {
.timerRndLine 0 600 $!iif($!me ison #yourchannel,msg #yourchannel RndLine)
}


Or, would those be two different Alias'?

Just to confirm...

a) on text, random line from random file (my channel only)
b) secondly, ramdom line from ramdom file, on a timer (my channel only)

With all files being in /Text.

Further..

Quote:
on *:text:!quote:#: {
set -u5 %Quote.Fld On
if (!%Quote.Fld) { msg $chan $read(quote.txt) }
}


In replacing :text: can I use mulitple words, or am I limited to a single word? Are these words separated by a comma for instance?

/hopefully, final edit :p


Edited by daTerminehtor (22/02/07 09:38 PM)

Top
#171321 - 22/02/07 09:57 PM Re: response bot (?) read from text file? [Re: daTerminehtor]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: NC, USA
Ok. Yeah, I thought it may get confusing with giving you all of that information at once. smile

First off, you said your files are in a folder called "Text" instead of "Texts". If that's the case, you want to change both "Texts" to "Text" in the alias I gave you.

The alias does not include a timer. It just does the work for you. You can manually call it by just typing //echo -a $RndLine in your edit box, or you can put it into a timer like I showed (and like your second example has) **EXCEPT** with one small change that I missed in my first post.

Code:
alias RndLine {
  var %total = $findfile($qt($scriptdir\Texts),*.txt,0)
  return $read($qt($findfile($qt($scriptdir\Texts),*.txt,$rand(1,%total))))
}

on *:connect: {
  .timerRndLine 0 600 $!iif($!me ison #yourchannel,msg #yourchannel $RndLine)
}


Sorry for the mistake. I forgot to put the $ in there.

And, no, they wouldn't be 2 aliases. You have it right. Don't forget to change the channel names.

If you use the on TEXT (the last example in my previous post) that I showed you that has a timer instead of the on CONNECT, it will make the random lines only appear when everyone is idle. If you use the on CONNECT instead of the on TEXT version, then it will display a random line every XX seconds no matter what (in your channel only).

The first example I gave you will display the random line from the specified file whenever someone types the trigger rather than using a timer. You can have your script do both things if you want.

For:
Code:
on *:text:!quote:#: {
  set -u5 %Quote.Fld On
  if (!%Quote.Fld) { msg $chan $read(quote.txt) }
}


You replace !quote, not text. You can have a single word or phrase. For example, !quote could be changed to Help me. You can also use wildcards (*) if you want it to work with phrases that include what you said, but may have more words than what you put there...

hello* will trigger on "hello" or "hello, how are you?" or whatever that starts with "hello"

*hello* will trigger on "hello" or "Riamus: Hello" or "Hello, Riamus" or whatever that has "hello" somewhere in it.

If you want a single on TEXT event instead of one for each word/phrase, then you can do something like:

Code:
on *:text:*:#: {
  if (hello isin $1-) { do this }
  elseif (goodbye isin $1-) { do this }
  elseif (help isin $1-) { do this }
}


Again, you can use wildcards, but if you do use wildcards, then you need to change isin to iswm .
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#171329 - 22/02/07 10:33 PM Re: response bot (?) read from text file? [Re: Riamus2]
daTerminehtor Offline
Pikka bird

Registered: 17/02/07
Posts: 12
Loc: Great White North
Quote:
alias RndLine {
var %total = $findfile($qt($scriptdir\Text),*.txt,0)
return $read($qt($findfile($qt($scriptdir\Text),*.txt,$rand(1,%total))))
}

on *:connect: {
.timerRndLine 0 60 $!iif($!me ison #mychannel,msg #mychannel $RndLine)
}


Changing Texts to Text, and #mychannel to, uh.. my channel :d, produces no results, not even an error.

Quote:
//echo -a $RndLine


Returns the following error...
Quote:
* /echo: insufficient parameters (line 181, ialias1.mrc)


Ideas?

Changing

Top
#171332 - 22/02/07 10:56 PM Re: response bot (?) read from text file? [Re: daTerminehtor]
hixxy Offline
Hoopy frood

Registered: 06/09/05
Posts: 2876
None of that $qt stuff is necessary. Only commands need to use quotes strings, not identifiers.

Also, instead of using an $iif you could just turn off the timer when you leave your channel.

Code:
alias rndline { return $read($findfile($scriptdir $+ texts\,*.txt,$rand(1,$findfile($scriptdir $+ texts\,*.txt,0))),n) }

on *:connect:{ .timerrndline 0 60 msg #mychannel $!rndline }
on *:part:#mychannel:{ .timerrndline off }

Top
#171339 - 22/02/07 11:41 PM Re: response bot (?) read from text file? [Re: hixxy]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: NC, USA
Hm. Ok, for some reason, I thought the $read/$readini required quotes around a spaced path, but I see that I'm incorrect. laugh


As for the error, I don't know why you have that. I have tested it and it's working fine (even using the $qt that ends up being unnecessary). I'm guessing that your path is not correct.

If the script is saved in a folder other than mIRC (such as mIRC\Script\), then the Text folder needs to be in that script's folder (mIRC\Script\Text, not mIRC\Text). Maybe that's the problem? Basically, you have that error because your path isn't finding the text files.
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#171357 - 23/02/07 03:16 AM Re: response bot (?) read from text file? [Re: Riamus2]
daTerminehtor Offline
Pikka bird

Registered: 17/02/07
Posts: 12
Loc: Great White North
K, got it sorted, and no error. :p

Thanks for the help guys, appreciate it.

/me sheepishly admits to originally saving script as alias <g>

Saved it in remotes and all is well.

Top
#171359 - 23/02/07 04:56 AM Re: response bot (?) read from text file? [Re: daTerminehtor]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: NC, USA
Heh. No problem. laugh
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#171657 - 27/02/07 08:11 AM Re: response bot (?) read from text file? [Re: daTerminehtor]
daTerminehtor Offline
Pikka bird

Registered: 17/02/07
Posts: 12
Loc: Great White North
I need to make this server specific.

Here's why, as long as I'm only in my channel (on blitzed) all is well. However, when I join another channel on another server, the script looks for my channel on that server.

Is this possible?

Top
#171661 - 27/02/07 09:48 AM Re: response bot (?) read from text file? [Re: daTerminehtor]
DJ_Sol Offline
Hoopy frood

Registered: 04/01/07
Posts: 1156
Loc: Seattle
if ($network != <network>) halt

of if ($network == <network>) { command }

//echo -a $network
This will show you exactly what to match.

Top
#171683 - 27/02/07 03:20 PM Re: response bot (?) read from text file? [Re: DJ_Sol]
genius_at_work Offline
Hoopy frood

Registered: 08/10/05
Posts: 1741
Do we have to revoke your /halt privileges?

There are VERY few places where using /halt is necessary. In almost all cases, you should use the /return command. It has the added bonus of being able to return a message to the calling script. Example:

Code:
alias a.one {
  a.two $1
  if ($result) echo -a /a.two succeeded
  else echo -a /a.two failed
}
alias a.two {
  if ($check.something($1)) return 0
  do.something $1
  return 1
}


-genius_at_work

Top
#171697 - 27/02/07 08:20 PM Re: response bot (?) read from text file? [Re: daTerminehtor]
daTerminehtor Offline
Pikka bird

Registered: 17/02/07
Posts: 12
Loc: Great White North
So...

The script would look how...

Quote:
alias rndline { return $read($findfile($scriptdir $+ Texts\,*.txt,$rand(1,$findfile($scriptdir $+ Texts\,*.txt,0))),n) }

on *:connect:{ .timerrndline 0 3600 msg #mychannel $!rndline }
on *:part:#mychannel:{ .timerrndline off }

Top
#171704 - 27/02/07 09:58 PM Re: response bot (?) read from text file? [Re: daTerminehtor]
LonDart Offline
Vogon poet

Registered: 21/07/06
Posts: 107
Loc: Virginia USA
Put the check in the on connect event.

Code:
on *:connect:{
  if ( $network == <YOUR_NETWORK_HERE> ) {
    .timerrndline 0 3600 msg #mychannel $!rndline 
  }
}

Quote:
//echo -a $network
This will show you exactly what to match.
_________________________
LonDart

Top
#171775 - 28/02/07 10:35 PM Re: response bot (?) read from text file? [Re: LonDart]
daTerminehtor Offline
Pikka bird

Registered: 17/02/07
Posts: 12
Loc: Great White North
That does it, thanks. wink

Top