Skip to content
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM openjdk:8-alpine

RUN apk add --no-cache maven

COPY . /usr/src/unobot
WORKDIR /usr/src/unobot
RUN mvn package
CMD java -jar ./target/UnoBot-1.0-SNAPSHOT-jar-with-dependencies.jar
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and allows members of the channel to play a game of uno. It also has an AI so it
1. You must have Java 1.7 JDK or higher installed.
2. The Java bin folder must be in your classpath if you are running windows.
3. Maven
4. Alternatively: The bot can be run with only having docker installed.

## Installation

Expand All @@ -17,6 +18,13 @@ and allows members of the channel to play a game of uno. It also has an AI so it
3. run `mvn package` (you will have to cd to UnoBot's directory)
4. run `UnoBot-1.0-SNAPSHOT-jar-with-dependencies.jar` using the `java -jar ./target/UnoBot-1.0-SNAPSHOT-jar-with-dependencies.jar` command

## Running with Docker

1. `docker build . -t unobot`
2. `docker-compose up`
3. Set the CONFIG_PATH to provide a location to store the scoreboard file and the config.ini (if using the config.ini file).
4. All of the key:value pairs from the config file can be used when starting the docker container and have the same effect. If there is no config file found in the CONIFG_PATH, the environment variables will be used

### values in the config file

Server - if no value given it will default to localhost
Expand Down
20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
version: "3.2"

services:
unobot:
image: 127.0.0.1:5000/unobot
environment:
CONFIG_PATH: /config/ # Primarily storing the scoreboard file
Server: irc.freenode.net
Port: 6697
Nick: unoBot
Channel: #spdcx
BotOps: roofis0
UpdateScript: ./runUnoBot.sh
Verbose: "true"
SSL: "true"

volumes:
- /mnt/data/unobot:/config

44 changes: 39 additions & 5 deletions src/main/java/com/mjsalerno/unobot/UnoBotMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,38 @@
* @author roofis0
*/
public class UnoBotMain {



public static void main(String[] args) throws Exception {

Properties p = new Properties();
try (FileInputStream in = new FileInputStream(new File("./config.ini"))) {
p.load(in);

String path = getVarOrDefault("CONFIG_PATH","./");
String filename = path + "/config.ini";
File configFile = new File(filename);
if (configFile.exists()) {
try (FileInputStream in = new FileInputStream(configFile)) {
p.load(in);
}
} else { // Allows loading of the config values from either java properties or environment variables
putToProperties(p, "Server", getVarOrDefault("Server", "localhost"));
putToProperties(p, "Port", getVarOrDefault("Port", "6667"));
putToProperties(p, "Channel", getVarOrDefault("Channel", "#uno"));
putToProperties(p, "Nick", getVarOrDefault("Nick", "unoBot"));

putToProperties(p, "BotOps", getVarOrDefault("BotOps", ""));
putToProperties(p, "ScoreBoardFileName", path + getVarOrDefault("ScoreBoardFileName", "/ScoreBoard.dat"));
putToProperties(p, "UpdateScript", getVarOrDefault("UpdateScript", null));
putToProperties(p, "SSL", getVarOrDefault("SSL", "false"));
putToProperties(p, "Token", getVarOrDefault("Token", "!"));
putToProperties(p, "nickSrvPasswd", getVarOrDefault("nickSrvPasswd", null));
putToProperties(p, "serverPasswd", getVarOrDefault("serverPasswd", null));
putToProperties(p, "webIRCPasswd", getVarOrDefault("webIRCPasswd", null));

putToProperties(p, "aiWebIRCPasswd", getVarOrDefault("aiWebIRCPasswd", null));
putToProperties(p, "aiServerPasswd", getVarOrDefault("aiServerPasswd", null));
putToProperties(p, "aiNickSrvPasswd", getVarOrDefault("aiNickSrvPasswd", null));
putToProperties(p, "AINick", getVarOrDefault("AINick", "unoAI"));
}

// System.setProperty("socksProxyHost", "localhost");
// System.setProperty("socksProxyPort", "9999");

Expand Down Expand Up @@ -116,6 +138,18 @@ public static void main(String[] args) throws Exception {
System.exit(0);
}
}

public static String getVarOrDefault(String key, String def) {
String javaProp = System.getProperty(key, def);
return System.getenv().getOrDefault(key, javaProp);
}

public static void putToProperties(Properties p, String key, String value) {
if (value == null) {
return;
}
p.setProperty(key, value);
}

static class ExceptionListener extends ListenerAdapter {
@Override
Expand Down