Skip to content

Commit cee1bd4

Browse files
committed
Make command prefix configurable.
1 parent b6a4a41 commit cee1bd4

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

bitbot-template.properties

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ server.resource = testing
55
rooms = test
66
room.test.name = [email protected]
77
room.test.nick = BitBot
8+
commandPrefix = !

src/bitbot/BitBot.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static void main(String[] args) {
2222

2323
public BitBot(BotConfig config) {
2424
this.config = config;
25-
MessageHandler messageHandler = new MessageHandler();
25+
MessageHandler messageHandler = new MessageHandler(config.getCommandPrefix());
2626
server = new ChatServer(config.getChatServerConfig(), messageHandler);
2727
}
2828

src/bitbot/BotConfig.java

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class BotConfig {
1212

1313
private ChatServerConfig chatServerConfig;
1414
private List<RoomConfig> roomConfigs = new ArrayList<RoomConfig>();
15+
private char commandPrefix;
1516

1617
public BotConfig() {
1718
}
@@ -27,6 +28,10 @@ public ChatServerConfig getChatServerConfig() {
2728
public List<RoomConfig> getRoomConfigs() {
2829
return roomConfigs;
2930
}
31+
32+
public char getCommandPrefix() {
33+
return commandPrefix;
34+
}
3035

3136
public void load(File file) throws IOException {
3237
Properties props = new Properties();
@@ -42,6 +47,7 @@ public void load(File file) throws IOException {
4247
for (String room : rooms.split("\\s")) {
4348
roomConfigs.add(new RoomConfig(props, "room." + room));
4449
}
50+
commandPrefix = props.getProperty("commandPrefix").charAt(0);
4551
}
4652

4753
}

src/bitbot/MessageHandler.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ public class MessageHandler {
66

77
private final char commandPrefix;
88

9-
public MessageHandler() {
10-
commandPrefix = '!';
9+
public MessageHandler(char commandPrefix) {
10+
this.commandPrefix = commandPrefix;
1111
}
1212

1313
public void processMessage(String text, User user, boolean pm, Replier replier) {

0 commit comments

Comments
 (0)