Last active
December 15, 2015 17:29
-
-
Save azenla/5296478 to your computer and use it in GitHub Desktop.
RawParser PircBotX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package kenbot.module.allthemutils; | |
import org.pircbotx.PircBotX; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.net.Socket; | |
public class RawParser implements Runnable { | |
private PircBotX bot; | |
public RawParser(PircBotX bot) { | |
this.bot = bot; | |
} | |
@Override | |
public void run() { | |
Socket socket = null; | |
try { | |
if (!bot.getClass().getDeclaredField("socket").isAccessible()) { | |
bot.getClass().getDeclaredField("socket").setAccessible(true); | |
} | |
socket = (Socket) bot.getClass().getDeclaredField("socket").get(new Socket()); | |
} catch (NoSuchFieldException e) { | |
e.printStackTrace(); | |
} catch (IllegalAccessException e) { | |
e.printStackTrace(); | |
} | |
assert socket != null; | |
BufferedReader reader = null; | |
try { | |
reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
while (bot.isConnected()) { | |
assert reader != null; | |
try { | |
System.out.println(reader.readLine()); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
System.out.println("**Bot Socket Closed!**"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment