Skip to content

Instantly share code, notes, and snippets.

@fredsted
Last active August 29, 2015 14:03
Show Gist options
  • Save fredsted/f51bcc9c25e9ebe5c392 to your computer and use it in GitHub Desktop.
Save fredsted/f51bcc9c25e9ebe5c392 to your computer and use it in GitHub Desktop.
VikingBot NickServ Plugin
<?php
/*
VikingBot NickServ Plugin
To install, put this file in your /plugins directory.
Then append the following to your vikingbot config.php
replacing the nickname and password with your actual
nickserv details. Then restart the bot.
————————————————————————————————————————————————————————
$config['plugins']['nickserv'] = array(
"username" => "BotNickName",
"password" => "botpasswdxyz",
);
————————————————————————————————————————————————————————
*/
class nickservPlugin implements pluginInterface {
private $isLoggedIn = false;
private $isLoggingIn = false;
private $maxRetries = 3;
private $retries = 0;
private $waitBeforeLogin = 7;
private $NS = "NickServ";
private $successMsg = "You are now identified";
private $config, $pconfig, $socket, $startTime;
function init($config, $socket) {
$this->startTime = time() + $this->waitBeforeLogin;
$this->config = $config;
$this->socket = $socket;
$this->pconfig = $config['plugins']['nickserv'];
logMsg("<NickServ Plugin> Loaded");
}
function tick() {
if ($this->isLoggedIn) return;
if (time() > $this->startTime)
if ((!$this->isLoggingIn) && ($this->retries < $this->maxRetries)) {
$this->isLoggingIn = true;
$this->retries++;
$this->nickservAuth();
}
}
function nickservAuth()
{
$authStr = "LOGIN {$this->pconfig['username']} {$this->pconfig['password']}";
sendData(
$this->socket,
"PRIVMSG {$this->NS} :$authStr\n"
);
}
function onMessage($from, $channel, $msg) {
}
function onData($data) {
if ($this->isLoggedIn) return;
if ($this->isLoggingIn)
if (strpos($data, $this->NS) !== FALSE) {
$bits = explode(' ', $data);
if ($bits[1] == 'NOTICE') {
$msg = '';
for ($i=3; $i<count($bits); $i++) {
$msg .= ' '.$bits[$i];
}
if (strpos($msg, $this->successMsg) !== FALSE) {
$this->isLoggedIn = true;
$this->isLoggingIn = false;
logMsg("<NickServ Plugin> Login successful");
}
}
}
}
function destroy() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment