Exemple #1
0
<?php

$lang = array('en' => array('help' => 'Usage: %CMD% [<server>]. List the channels where %BOT% is online.', 'none' => 'I am not connected to any channel on %s.', 'out' => 'I am in %d channels on %s: %s.'));
$plugin = Dog::getPlugin();
$argv = $plugin->argv();
$argc = count($argv);
if ($argc === 0) {
    $server = Dog::getServer();
} elseif ($argc !== 1) {
    return $plugin->showHelp();
} else {
    if (false === ($server = Dog::getServerByArg($argv[0]))) {
        return Dog::rply('err_server');
    }
}
if (!$server->isConnected()) {
    return Dog::rply('err_connection');
}
$out = '';
$channels = $server->getChannels();
foreach ($channels as $channel) {
    $channel instanceof Lamb_Channel;
    $out .= sprintf(', %s(%d)', $channel->getName(), count($channel->getUsers()));
}
if ($out === '') {
    return $plugin->rply('none', array($server->displayName()));
}
$plugin->rply('out', array(count($channels), $server->displayName(), substr($out, 2)));
Exemple #2
0
    $prot = $server->isSSL() ? 'ircs' : 'irc';
    $port = $server->getPort();
} else {
    $url = parse_url($argv[0]);
    if (!isset($url['host'])) {
        return $plugin->rply('err_url');
    }
    $host = $url['host'];
    $prot = isset($url['scheme']) ? strtolower($url['scheme']) : 'irc';
    if ($prot !== 'irc' && $prot !== 'ircs') {
        return $plugin->rply('err_url');
    }
    $default_port = $prot === 'ircs' ? 6697 : 6667;
    $port = isset($url['port']) ? intval($url['port']) : $default_port;
    $options = Dog_Server::DEFAULT_OPTIONS;
    $options |= $prot === 'ircs' ? Dog_Server::SSL : 0;
}
if (false !== ($server = Dog::getServerByArg($argv[0])) || false !== ($server = Dog::getServerByArg($host))) {
    $plugin->reply('reconnecting');
    $server->saveOption(Dog_Server::ACTIVE, true);
    $server->saveOption(Dog_Server::SSL, $prot === 'ircs');
    $server->saveVar('serv_port', $port);
} else {
    $plugin->reply('adding_server');
    $server = Dog_Server::getOrCreate($host, $port, $options);
    $server->setVar('dog_connector', Dog::getUser());
    $server->setConf('ircoppass', GWF_Random::randomKey(8));
    Dog::addServer($server);
}
$server->setConnectIn(0.5);
$plugin->rply('connect');