Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/oakbot/CliArguments.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ All messages that are sent to the mock chat room are displayed in stdout (this
Prints the version of this program.

--help
Prints this help message.""".formatted(Main.VERSION, Main.URL, defaultContext);
Prints this help message.""".formatted(Main.getVersion(), Main.getUrl(), defaultContext);
}
}
26 changes: 19 additions & 7 deletions src/main/java/oakbot/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
public final class Main {
private static final Logger logger = LoggerFactory.getLogger(Main.class);

public static final String VERSION;
public static final String URL;
public static final Instant BUILT;
private static final String VERSION;
private static final String URL;
private static final Instant BUILT;

static {
var props = new Properties();
Expand Down Expand Up @@ -78,24 +78,36 @@ public final class Main {
BUILT = built;
}

private static final String defaultContextPath = "bot-context.xml";
public static String getVersion() {
return VERSION;
}

public static String getUrl() {
return URL;
}

public static Instant getBuilt() {
return BUILT;
}

private static final String DEFAULT_CONTEXT_PATH = "bot-context.xml";

public static void main(String[] args) throws Exception {
var arguments = new CliArguments(args);

if (arguments.help()) {
var help = arguments.printHelp(defaultContextPath);
var help = arguments.printHelp(DEFAULT_CONTEXT_PATH);
System.out.println(help);
return;
}

if (arguments.version()) {
System.out.println(Main.VERSION);
System.out.println(Main.getVersion());
return;
}

var mock = arguments.mock();
var contextPath = (arguments.context() == null) ? defaultContextPath : arguments.context();
var contextPath = (arguments.context() == null) ? DEFAULT_CONTEXT_PATH : arguments.context();

BotProperties botProperties;
Database database;
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/oakbot/bot/ActionContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package oakbot.bot;

import com.github.mangstadt.sochat4j.ChatMessage;

/**
* Context information for executing chat actions.
* Provides access to bot functionality without exposing entire Bot class.
*/
public class ActionContext {
private final Bot bot;
private final ChatMessage message;

public ActionContext(Bot bot, ChatMessage message) {
this.bot = bot;
this.message = message;
}

public Bot getBot() {
return bot;
}

public ChatMessage getMessage() {
return message;
}

public int getRoomId() {
return message.getRoomId();
}
}
Loading