From 880e1d44b6be71248a702991ff2caee33b9aac21 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Mon, 1 Oct 2018 14:53:41 +0200 Subject: [PATCH] Added IRC NickServ identify feature. --- resources/conf/hebdobot-sample.conf | 2 + src/org/april/hebdobot/bot/Hebdobot.java | 23 ++++++++++- src/org/april/hebdobot/cli/HebdobotCLI.java | 2 +- .../hebdobot/cli/HebdobotConfigFile.java | 38 +++++++++++++++++++ test/org/april/hebdobot/BotMock.java | 2 +- 5 files changed, 63 insertions(+), 4 deletions(-) diff --git a/resources/conf/hebdobot-sample.conf b/resources/conf/hebdobot-sample.conf index 48dc3b7..dd03da7 100644 --- a/resources/conf/hebdobot-sample.conf +++ b/resources/conf/hebdobot-sample.conf @@ -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 diff --git a/src/org/april/hebdobot/bot/Hebdobot.java b/src/org/april/hebdobot/bot/Hebdobot.java index 44446e0..377d7d0 100644 --- a/src/org/april/hebdobot/bot/Hebdobot.java +++ b/src/org/april/hebdobot/bot/Hebdobot.java @@ -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."); diff --git a/src/org/april/hebdobot/cli/HebdobotCLI.java b/src/org/april/hebdobot/cli/HebdobotCLI.java index 2c5690f..622dbd8 100644 --- a/src/org/april/hebdobot/cli/HebdobotCLI.java +++ b/src/org/april/hebdobot/cli/HebdobotCLI.java @@ -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()); diff --git a/src/org/april/hebdobot/cli/HebdobotConfigFile.java b/src/org/april/hebdobot/cli/HebdobotConfigFile.java index 40d78da..e673b47 100644 --- a/src/org/april/hebdobot/cli/HebdobotConfigFile.java +++ b/src/org/april/hebdobot/cli/HebdobotConfigFile.java @@ -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; diff --git a/test/org/april/hebdobot/BotMock.java b/test/org/april/hebdobot/BotMock.java index b5f4067..99490a4 100644 --- a/test/org/april/hebdobot/BotMock.java +++ b/test/org/april/hebdobot/BotMock.java @@ -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)