当前位置: 首页>>代码示例>>Java>>正文


Java SASLCapHandler类代码示例

本文整理汇总了Java中org.pircbotx.cap.SASLCapHandler的典型用法代码示例。如果您正苦于以下问题:Java SASLCapHandler类的具体用法?Java SASLCapHandler怎么用?Java SASLCapHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SASLCapHandler类属于org.pircbotx.cap包,在下文中一共展示了SASLCapHandler类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: IRCMediator

import org.pircbotx.cap.SASLCapHandler; //导入依赖的package包/类
protected IRCMediator()
{
    Configuration.Builder confBuilder = new Configuration.Builder();

    // check if SSL is enabled, otherwise it won't use SSL connection.
    if (ConfReader.getInstance().isSSL())
    {
        confBuilder.setSocketFactory(new UtilSSLSocketFactory().trustAllCertificates());
    }

    // It tries to authenticate using SASL (it doesn't work on all networks)
    if (ConfReader.getInstance().isIdentifyEnabled())
    {
        confBuilder.addCapHandler(new SASLCapHandler(ConfReader.getInstance().getNick(),
                ConfReader.getInstance().getNickserv_passwd(), true));
    }

    confBuilder.setAutoReconnect(ConfReader.getInstance().isAutoreconnect());
    confBuilder.setAutoReconnectAttempts(ConfReader.getInstance().getReconnectattempts());
    confBuilder.setAutoReconnectDelay(ConfReader.getInstance().getDelaybetweenretries());
    confBuilder.setRealName(ConfReader.getInstance().getRealname());
    confBuilder.setName(ConfReader.getInstance().getNick());
    confBuilder.setLogin(ConfReader.getInstance().getLogin());
    confBuilder.setAutoNickChange(true);
    confBuilder.addServer(ConfReader.getInstance().getIrcserver(), ConfReader.getInstance().getPort());
    confBuilder.addAutoJoinChannel("#" + ConfReader.getInstance().getChannel());

    confBuilder.setVersion(
            ConfReader.getAppProperties().getString("application.name") +
            " v" + ConfReader.getAppProperties()
                    .getString("application.version") +
            " " + ConfReader.getAppProperties()
                    .getString("application.buildnumber")
    );
    confBuilder.addListener(new IRCListener(this) );
    confBuilder.buildConfiguration();

    this.bot = new PircBotX(confBuilder.buildConfiguration());
    this.newsReader = new NewsReader(new IRCOutputter());

    new NewsTimer(ConfReader.getInstance().getPollFrequency()).addTask(
                    new NewsTask(newsReader)
    );
}
 
开发者ID:MadCoderZ,项目名称:NewsBotIRC,代码行数:45,代码来源:IRCMediator.java

示例2: runBot

import org.pircbotx.cap.SASLCapHandler; //导入依赖的package包/类
/**
 * Attempts to connect the bot to an IRC server.
 * Attempts to reconnect upon failure or disconnection.
 * @throws Exception 
 */
protected void runBot() throws Exception{
    int timeInt = 30000;    // milliseconds
    int attempt = 0;
    
    // Continue trying to connect to the server if not in a connected state
    while (!isConnected()) {
        try {
            attempt++;
            if (!configMap.get("password").equals("")){
                getCapHandlers().clear();
                getCapHandlers().add(new SASLCapHandler(configMap.get("nick"), configMap.get("password")));
            }
            
            // Reset IRC threads
            inputThread = null;
            outputThread = null;
            
            // Attempt to connect
            log("Connection attempt " + attempt + "...");
            connect(configMap.get("network"));
        } catch (IOException | IrcException e){
            // Log the exception that caused connection failure
            logException(e);
            
            // Wait for IRC threads to die
            if (inputThread != null) inputThread.join();
            if (outputThread != null) outputThread.join();
            
            // Set delay up to 600 seconds or 10 minutes
            int delay = Math.min(attempt * timeInt, timeInt * 20);
            log("Attempt to reconnect in " + (delay/1000) + " seconds...");
            Thread.sleep(delay);
            
            // Retry
            continue;
        }
        
        // If we make it here that means we're connected, reset attempts
        attempt = 0;
        
        // Wait for any disconnections
        inputThread.join();
        outputThread.join();
        
        // Terminate if no auto-reconnect is required
        if (!autoReconnect) {
            break;
        }
        
        // Otherwise wait the 10 seconds to reconnect
        Thread.sleep(timeInt);
    }
}
 
开发者ID:brrr2,项目名称:irccasino,代码行数:59,代码来源:CasinoBot.java


注:本文中的org.pircbotx.cap.SASLCapHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。