Do you want the bot to say something just to you or to everyone? To you want it to wait for a response only from you or from anyone? Is the bot supposed to be in this "suspended" state for everyone or just for you?
In any case, this is all very possible. Simply set a state variable. If the state variable is set to one value, it works normally, if set to a different value, it only responds to a given message. You always want to let the bot maintain control (never use sleep, for example), but "seem" like it is suspended by only responding to a particular message.
Joined: 27 Jan 2005 Posts: 109 Location: Lewiston, ME
Posted: Tue Feb 01, 2005 12:16 am Post subject:
sorry, just want to do this inside of a command, so that whoever runs the command, will then have to type something specific, like yes or no, before moving on.
I'd like to avoid having to code the on_im handler to check the state of that variable, then check the screenname of the person who just typed, and then decide what to do based on that.
He basically means the same sort of thing as when you run a template bot for the first time and it asks for your settings (like MayaBot4) but he wants it inside a command. Must admit, it would be very useful...
I'd like to avoid having to code the on_im handler to check the state of that variable, then check the screenname of the person who just typed, and then decide what to do based on that.
You can't avoid everything or else there'd be no point in programming.
You can easily accomplish this by maintaining a hash that stores the state of each user. (Better yet, use a database). I do something similar when new users use my bots. I require them to read a short agreement and then type "I agree" before they can continue.
Somewhere in your message handler, you would have something like this:
Code:
my $state = $statehash->{$username} || 0;<br /><br />if( $state == 99 )<br />{<br /> if( $message eq 'yes' )<br /> {<br /> $statehash->{$username} = 0;<br /> # do whatever you want now that they answered yes<br /> }<br /> else<br /> {<br /> # do whatever, tell them they have to say yes?<br /> }<br />}<br />else<br />{<br /> # normal code<br />}
And you would have some code that gets them into state 99.