get disconnect reason from string using regex
This commit is contained in:
1 parent
a5f6d008fa
commit
65ce3acab3
1 file changed
+16
-1
@@ -17,6 +17,8 @@ import com.github.steveice10.packetlib.tcp.TcpClientSession;
|
|||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class Bot extends Thread {
|
public class Bot extends Thread {
|
||||||
|
|
||||||
@@ -73,7 +75,20 @@ public class Bot extends Thread {
|
|||||||
connected = false;
|
connected = false;
|
||||||
Log.info();
|
Log.info();
|
||||||
Log.info(nickname + " disconnected");
|
Log.info(nickname + " disconnected");
|
||||||
Log.info(" -> " + event.getReason());
|
|
||||||
|
//Log.info(" -> " + event.getReason());
|
||||||
|
|
||||||
|
//fix broken reason string by finding the content with regex
|
||||||
|
Pattern pattern = Pattern.compile("content=\"(.*?)\"");
|
||||||
|
Matcher matcher = pattern.matcher(event.getReason());
|
||||||
|
|
||||||
|
StringBuilder reason = new StringBuilder();
|
||||||
|
while (matcher.find()) {
|
||||||
|
reason.append(matcher.group(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.info(" -> " + reason.toString());
|
||||||
|
|
||||||
if(event.getCause() != null) {
|
if(event.getCause() != null) {
|
||||||
event.getCause().printStackTrace();
|
event.getCause().printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user