I am wondering if it is possible with the current version of SmartIRC to make a restart command for the bot, like pretty much total shutdown and restart of the script. I am just curious if it's a possible thing, not really looking for the code to do it, though anything would be helpful.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2003-08-12
ok I have kinda done a hack for this to make it work (and it does work although I don't know how orthodox it is):
function restart(&$irc, &$data)
{
if($data->host=="dsl-217-155-154-91.zen.co.uk") {
$irc->quit("Restarting...");
session_write_close();
exec("C:\\PHP\\php C:\\php\\SmartIRC-0.5.5\\examples\\naked-bot.php");
}
else
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'Sorry ' . $data->nick . '. You do not have authorisation to terminate my process.');
}
The problem with the above function was that the original bot client doesn't disconnect so the new instance of the bot connects with a freaky nick as defined in _nicknameinuse()
So I did a little hack of SmartIRC.php in _nicknameinuse() :
// Hey hey hey! Why did the bot die?
// If we get to this point, it got disconnected somehow...
// Let's reconnect!
// Record disconnect information
$dctime = time();
$dccount++;
// Unset old objects
unset($bot);
unset($irc);
// Sleep
sleep(15);
// Restart bot
include('wildbillbot.php');
?>
After the loop is broken, it sleeps, then includes itself. It's useful for not losing any of the various things my bot records (user hostnames, activity times for users, etc), but not for edited my mybot class functions. To restart using this method, I tell my bot to restart, which uses SmartIRC's $irc->quit function.
I've also got a shell script running infinitely in a similar manner on the server I run my bot on (I have dialup), using nohup. When PHP dies, it sleeps, then runs itself again so the bot will be started up. It's crude, but I suck at BASH shell scripts. :P
To get the bot restarted by the shell script, I run a command on my bot that uses die(), just like meebey.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am wondering if it is possible with the current version of SmartIRC to make a restart command for the bot, like pretty much total shutdown and restart of the script. I am just curious if it's a possible thing, not really looking for the code to do it, though anything would be helpful.
I do that why my bot, but thats not a feature of SmartIRC neither PHP ;)
I use a shell script that does:
while true;
do mybot.php;
done
so if the bot dies (like I use a !die command which will invoke a real PHP die();) the while loop will restart the bot...
why=with
I should not post things at this time :)
ok I have kinda done a hack for this to make it work (and it does work although I don't know how orthodox it is):
function restart(&$irc, &$data)
{
if($data->host=="dsl-217-155-154-91.zen.co.uk") {
$irc->quit("Restarting...");
session_write_close();
exec("C:\\PHP\\php C:\\php\\SmartIRC-0.5.5\\examples\\naked-bot.php");
}
else
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'Sorry ' . $data->nick . '. You do not have authorisation to terminate my process.');
}
The problem with the above function was that the original bot client doesn't disconnect so the new instance of the bot connects with a freaky nick as defined in _nicknameinuse()
So I did a little hack of SmartIRC.php in _nicknameinuse() :
function _nicknameinuse()
{
$newnickname = substr($this->_nick, 0, 5).rand(0, 999);
$this->changeNick($newnickname, SMARTIRC_CRITICAL);
$this->_nick = $newnickname;
$this->message(SMARTIRC_TYPE_QUERY,"nickserv","ghost Naked-Bot yourpassword");
$this->changeNick("Naked-Bot");
}
This works because I can use the networks nickserv to kill the ghosted client and then simply changeNick
There is one other problem with this method, you lose debugging on the new instance of the bot, dunno how to get round that.
Let me know what you think, I am no php guru so I am just doing it the best way I can figure out how.
My bot has a restart capability that uses nothing more than PHP. Here's how it's structured:
<?php
include_once('../SmartIRC.php');
if(empty($dccount)) {
class mybot {
// Bot functions
}
}
$bot = &new mybot();
$irc = &new Net_SmartIRC();
$irc->setDebug(SMARTIRC_DEBUG_ALL);
$irc->setUseSockets(TRUE);
$irc->setAutoReconnect(TRUE);
$irc->setAutoRetry(TRUE);
$irc->setChannelSynching(true);
// Action Handlers
// Connect
$irc->connect('irc.whatever.net', 6667);
$irc->login('WildBillBot', 'Net_SmartIRC Client '.SMARTIRC_VERSION, 8, 'wbbot', 'password');
$irc->join($joinChannels);
$irc->listen();
$irc->disconnect();
// Hey hey hey! Why did the bot die?
// If we get to this point, it got disconnected somehow...
// Let's reconnect!
// Record disconnect information
$dctime = time();
$dccount++;
// Unset old objects
unset($bot);
unset($irc);
// Sleep
sleep(15);
// Restart bot
include('wildbillbot.php');
?>
After the loop is broken, it sleeps, then includes itself. It's useful for not losing any of the various things my bot records (user hostnames, activity times for users, etc), but not for edited my mybot class functions. To restart using this method, I tell my bot to restart, which uses SmartIRC's $irc->quit function.
I've also got a shell script running infinitely in a similar manner on the server I run my bot on (I have dialup), using nohup. When PHP dies, it sleeps, then runs itself again so the bot will be started up. It's crude, but I suck at BASH shell scripts. :P
To get the bot restarted by the shell script, I run a command on my bot that uses die(), just like meebey.