From 8482bccc475570185682a433b4eefe7fa9eda832 Mon Sep 17 00:00:00 2001 From: ryodoan Date: Sat, 15 Oct 2011 00:10:29 -0400 Subject: [PATCH] Addresses some of the items needed for #13. More work needs to be done so that the bot only tries to op itself in authorized channels, or realizes after a failed op attempt that it does not have authority to self-op in certain channels. --- .../jircbot/commands/jIBCTMaintThread.java | 14 ++++++++++++++ src/org/hive13/jircbot/jIRCBot.java | 2 +- .../jircbot/support/jIRCProperties.java | 19 ++++++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/org/hive13/jircbot/commands/jIBCTMaintThread.java b/src/org/hive13/jircbot/commands/jIBCTMaintThread.java index 323bb86..610b2cf 100644 --- a/src/org/hive13/jircbot/commands/jIBCTMaintThread.java +++ b/src/org/hive13/jircbot/commands/jIBCTMaintThread.java @@ -1,6 +1,7 @@ package org.hive13.jircbot.commands; import org.hive13.jircbot.jIRCBot; import org.hive13.jircbot.jIRCBot.eLogLevel; +import org.hive13.jircbot.support.jIRCProperties; import org.hive13.jircbot.support.jIRCUser.eAuthLevels; @@ -40,6 +41,19 @@ public void loop() { bot.log(this.commandName + " - Bot failed to reconnect... see you in " + Long.toString((dfLoopDelay / 1000)) + " seconds", eLogLevel.severe); } } + + // Check if we are currently an operator + jIRCProperties.getInstance().getOpChannels(); + boolean botIsOp = bot.getUser(channel, bot.getNick()).isOp(); + if(!botIsOp) { + // For some reason we are not... lets try to op ourself. + bot.sendMessage("chanserv", "op " + channel); + } else { + // Ok, so lets wait for the maint thread to tick around again before doing this. + // Now that we are operator, lets check on the peon's in the channel with us. + + } + } @Override diff --git a/src/org/hive13/jircbot/jIRCBot.java b/src/org/hive13/jircbot/jIRCBot.java index 7267f7b..c5f5812 100644 --- a/src/org/hive13/jircbot/jIRCBot.java +++ b/src/org/hive13/jircbot/jIRCBot.java @@ -692,7 +692,7 @@ public void onJoin(String channel, String sender, String login, // Initiate check for credentials startAuthForUser(user); - + // Write the event to the log. logMessage(channel, this.getServer(), sender, "", eMsgTypes.joinMsg); diff --git a/src/org/hive13/jircbot/support/jIRCProperties.java b/src/org/hive13/jircbot/support/jIRCProperties.java index 492a004..064caed 100644 --- a/src/org/hive13/jircbot/support/jIRCProperties.java +++ b/src/org/hive13/jircbot/support/jIRCProperties.java @@ -16,6 +16,8 @@ public class jIRCProperties { private final String defaultBotPass = ""; private final String defaultServer = "irc.freenode.net"; private final String defaultChannels = "#Hive13_test"; + private final String defaultOpChannels = "#Hive13_test"; + private final String defaultBitlyName = ""; private final String defaultBitlyKey = ""; @@ -37,7 +39,8 @@ public class jIRCProperties { /** Directory for commands to use as a cache for data. */ private static File cacheDirectory = null; - private String parsedChannels[] = null; + private String parsedChannels[] = null; + private String parsedOpChannels[] = null; private List parsedOpList = null; private List parsedAdminList = null; private List parsedPlugins = null; @@ -96,6 +99,20 @@ public String[] getChannels() { return parsedChannels; } + public String[] getOpChannels() { + // Since we only read the properties once, it does not make sense + // to repeatedly re-parse the channel string. + if(parsedChannels == null) { + String channels = getProp("opChannels", defaultOpChannels); + String splitChannels[] = channels.split(","); + for (int i = 0; i < splitChannels.length; i++) { + splitChannels[i] = splitChannels[i].trim(); + } + parsedOpChannels = splitChannels; + } + return parsedOpChannels; + } + /** Username to use for the bit.ly API */ public String getBitlyName() { return getProp("bitlyName", defaultBitlyName);