mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2007
Posts: 12
Pikka bird
OP Offline
Pikka bird
Joined: Feb 2007
Posts: 12
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?

Joined: Nov 2005
Posts: 105
D
Vogon poet
Offline
Vogon poet
D
Joined: Nov 2005
Posts: 105
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

Joined: May 2005
Posts: 449
Fjord artisan
Offline
Fjord artisan
Joined: May 2005
Posts: 449
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.

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
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.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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
Joined: Feb 2007
Posts: 12
Pikka bird
OP Offline
Pikka bird
Joined: Feb 2007
Posts: 12
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

Last edited by daTerminehtor; 22/02/07 09:38 PM.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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
Joined: Feb 2007
Posts: 12
Pikka bird
OP Offline
Pikka bird
Joined: Feb 2007
Posts: 12
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

Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
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 }

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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
Joined: Feb 2007
Posts: 12
Pikka bird
OP Offline
Pikka bird
Joined: Feb 2007
Posts: 12
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.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Heh. No problem. laugh


Invision Support
#Invision on irc.irchighway.net
Joined: Feb 2007
Posts: 12
Pikka bird
OP Offline
Pikka bird
Joined: Feb 2007
Posts: 12
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?

Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
if ($network != <network>) halt

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

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

Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
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

Joined: Feb 2007
Posts: 12
Pikka bird
OP Offline
Pikka bird
Joined: Feb 2007
Posts: 12
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 }

Joined: Jul 2006
Posts: 107
L
Vogon poet
Offline
Vogon poet
L
Joined: Jul 2006
Posts: 107
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
Joined: Feb 2007
Posts: 12
Pikka bird
OP Offline
Pikka bird
Joined: Feb 2007
Posts: 12
That does it, thanks. wink


Link Copied to Clipboard