Skip to content

Commit

Permalink
bugs and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SocraticPhoenix committed Nov 13, 2017
1 parent 02c3f86 commit 7d13af7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ apply plugin : 'idea'
//End Plugins

//Program Specific Variables
def programVersion = "0.0.5"
def programVersion = "0.0.6"
def programGroup = "com.gmail.socraticphoenix"
//End Variables

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private void executeCommand(User user, Room room, long id, String handle, String
} else if (cmd.equals("help")) {
room.send(handle + " [TIOBot command list](https://github.com/SocraticPhoenix/TioBot/wiki/Commands)");
} else if (cmd.equals("version")) {
room.send(handle + " TIOBot v 0.0.4");
room.send(handle + " TIOBot v 0.0.6");
} else if (cmd.equals("alias")) {
if (content == null) {
room.send(handle + " expected more arguments...");
Expand Down
60 changes: 52 additions & 8 deletions src/main/java/com/gmail/socraticphoenix/tiobot/TioBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -154,21 +155,64 @@ public static void main(String[] args) throws IOException {
} else if (command.startsWith("leave")) {
String[] pieces = command.split(" ");
try {
boolean silent = pieces.length >= 3 && pieces[2].equals("silent");
synchronized (roomConf) {
rooms.entrySet().stream().filter(r -> r.getKey().getRoomId() == Integer.parseInt(pieces[1])).forEach(r -> {
int id = Integer.parseInt(pieces[2]);
ChatHost host = ChatHost.valueOf(pieces[1]);
boolean silent = pieces.length >= 4 && pieces[3].equals("silent");

Optional<Room> target = rooms.keySet().stream().filter(r -> r.getRoomId() == id && r.getHost() == host).findFirst();

if (target.isPresent()) {
Room room = target.get();

if (!silent) {
r.getKey().send("TIOBot logging off!");
room.send("TIOBot logging off!");
}
r.getKey().leave();
});

room.leave();
rooms.remove(room);
}
}
} catch (NumberFormatException e) {
System.out.println(pieces[1] + " must be an integer room id");
System.out.println(pieces[2] + " must be an integer room id");
} catch (IllegalArgumentException e) {
System.out.println(pieces[1] + " must be one of " + Arrays.toString(ChatHost.values()));
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Expected 1 arguments");
System.out.println("Expected 2 arguments");
}
} else if (command.startsWith("atuoleave")) {
String[] pieces = command.split(" ");
try {
synchronized (roomConf) {
int id = Integer.parseInt(pieces[2]);
ChatHost host = ChatHost.valueOf(pieces[1]);
boolean silent = pieces.length >= 4 && pieces[3].equals("silent");

Optional<Room> target = rooms.keySet().stream().filter(r -> r.getRoomId() == id && r.getHost() == host).findFirst();

if (target.isPresent()) {
Room room = target.get();

if (!silent) {
room.send("TIOBot logging off!");
}

room.leave();
rooms.remove(room);

if (roomConf.keySet().contains(host.toString())) {
roomConf.getJSONObject(host.toString()).remove(String.valueOf(id));
}
}
}
} catch (NumberFormatException e) {
System.out.println(pieces[2] + " must be an integer room id");
} catch (IllegalArgumentException e) {
System.out.println(pieces[1] + " must be one of " + Arrays.toString(ChatHost.values()));
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Expected 2 arguments");
}
} else if (command.startsWith("join")) {
} else if (command.startsWith("join")) {
String[] pieces = command.split(" ");
try {
synchronized (roomConf) {
Expand Down

0 comments on commit 7d13af7

Please sign in to comment.