本文整理匯總了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)
);
}
示例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);
}
}