Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
Addresses some of the items needed for #13. More work needs to be done
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pvince committed Oct 15, 2011
1 parent 8ba5ca3 commit 8482bcc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/org/hive13/jircbot/commands/jIBCTMaintThread.java
Original file line number Diff line number Diff line change
@@ -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;


Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/org/hive13/jircbot/jIRCBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 18 additions & 1 deletion src/org/hive13/jircbot/support/jIRCProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand All @@ -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<String> parsedOpList = null;
private List<String> parsedAdminList = null;
private List<String> parsedPlugins = null;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8482bcc

Please sign in to comment.