Added IRC NickServ identify feature.

This commit is contained in:
Christian P. MOMON 2018-10-01 14:53:41 +02:00
parent 42b6faaa5c
commit 880e1d44b6
5 changed files with 63 additions and 4 deletions

View File

@ -12,6 +12,8 @@ irc.host=irc.freenode.org
irc.port=6667
irc.name=Hebdobot
irc.channel=#april-test
irc.identify.nick=
irc.identify.password=
# Pastebin settings.
#pastebin.apiKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

View File

@ -74,6 +74,8 @@ public class Hebdobot extends PircBot
private String host;
private int port;
private String channel;
private String identifyNick;
private String identifyPassword;
private File reviewDirectory;
private String reviewFileSuffix;
private LocalTime reviewWaitTime;
@ -94,22 +96,28 @@ public class Hebdobot extends PircBot
* @param port
* the port
* @param nickname
* the name
* the nickname
* @param channel
* the channel
* @param homeDirectory
* the home directory
* @param reviewDirectory
* the review directory
* @param identifyNick
* the identify nick
* @param identifyPassword
* the identify password
*/
public Hebdobot(final String host, final int port, final String nickname, final String channel, final File homeDirectory,
final File reviewDirectory)
final File reviewDirectory, final String identifyNick, final String identifyPassword)
{
this.homeDirectory = homeDirectory;
this.host = host;
this.port = port;
this.channel = channel;
this.setName(nickname);
this.identifyNick = identifyNick;
this.identifyPassword = identifyPassword;
this.reviewDirectory = reviewDirectory;
this.reviewFileSuffix = null;
this.reviewWaitTime = null;
@ -391,6 +399,17 @@ public class Hebdobot extends PircBot
this.connect(this.host, this.port);
logger.info("Bot connected.");
if (this.identifyPassword == null)
{
logger.info("Skipped identify.");
}
else
{
logger.info("Apply identify.");
sendMessage("NickServ", "identify " + this.identifyNick + " " + this.identifyPassword);
logger.info("Applied identify.");
}
logger.info("Bot joining channel ({}).", this.channel);
this.joinChannel(this.channel);
logger.info("Bot ready.");

View File

@ -201,7 +201,7 @@ public class HebdobotCLI
logger.info("Alias list: " + aliases.toLineString());
Hebdobot bot = new Hebdobot(config.getIrcHost(), config.getIrcPort(), config.getIrcName(), config.getIrcChannel(),
configFile.getParentFile(), reviewDirectory);
configFile.getParentFile(), reviewDirectory, config.getIrcIdentifyNick(), config.getIrcIdentifyPassword());
//
bot.setReviewWaitTime(config.getReviewWaitTime());

View File

@ -177,6 +177,36 @@ public class HebdobotConfigFile extends Properties
return result;
}
/**
* Gets the irc identify login.
*
* @return the irc identify login
*/
public String getIrcIdentifyNick()
{
String result;
result = getProperty("irc.identify.nick");
//
return result;
}
/**
* Gets the identify password.
*
* @return the identify password
*/
public String getIrcIdentifyPassword()
{
String result;
result = getProperty("irc.identify.password");
//
return result;
}
/**
* Gets the name.
*
@ -445,6 +475,14 @@ public class HebdobotConfigFile extends Properties
{
result = false;
}
else if ((getProperty("irc.identify.nick") != null) && (getProperty("irc.identify.password") == null))
{
result = false;
}
else if ((getProperty("irc.identify.nick") == null) && (getProperty("irc.identify.password") != null))
{
result = false;
}
else
{
result = true;

View File

@ -36,7 +36,7 @@ public class BotMock extends Hebdobot
*/
public BotMock() throws Exception
{
super("myHost", 0, "Hebdobot", "#april-mock", null, new File("/tmp/"));
super("myHost", 0, "Hebdobot", "#april-mock", null, new File("/tmp/"), null, null);
}
/* (non-Javadoc)