![]() Up to five people can chat together in beautiful HD. ![]() Or hang out face-to-face with your nearest and dearest friends, subs, and teammates with video calls. Start a call with anyone by sending an instant invite link to chat. So you can spend less time herding cats, and more time, chatting, video messaging, and playing together.Ĭrystal-clear voice calls whether between one or two friends or an entire raid group. Attach your Twitch channel to your server so your community can watch live and use Twitch Chat right within the app.įriend Sync quickly imports all your friends and games you follow. A virtual home for your community to chat, watch, and play with fully customizable text and voice rooms. Since process commands only returns -1 or 0 (like error codes, but not quite) you might return a boolean that simply determines whether to close the bot or not. The actual command execution is done in chat.processCommands. The only command it knows is to shut down the bot. Then you can scroll down if you need details about the implementation.ĮxecuteCommand does not really execute commands. ![]() Better move the public members to the top, so that you can easily see what the class's interface is and what it is supposed to do. In Bot, you have only one public method, and that is located at the end of the class. A better name would be for example waitForCommands(), if that is what it is doing. ![]() To see what it does, you need to read the code, and to do that you have to jump through your sorce code. The name loop() tells you that you just made that method to make your start() method shorter, but not the intent of the method. In normal circumstances, it shouldn't be called twice anyway, and if you want to be sure you can expose the bot's running state with a method isRunning() so the caller can check first whether to call start() or not. Since the bot is not started by user input, but by Main creating and starting it, you might throw an exception, because calling start() twice is a mistake of the code that is worth finding. Just returning from the start() method if the Bot is already running hides potential bugs. Then use a char instead of a string, and everywhere in your code where you need to use the password, overwrite the contents of the char with NULL characters afterwards you can't overwrite a string, and just setting the reference to null still requires to wait for the garbage collector to actually delete it. Instead of making it constant and thus readable in your source code as well as your memory, have the user type the password in. Private static final String PASS = "oauth:xxxxx" is a possible security hole. The same in Bot, however there they (as well as HOST, CHANNEL and PORT) should be written in camelCase, because they are not constants there. In Main, PASS and IDENT should better be PASSWORD and USERNAME. Public static void addWarning(String user) Public static void demoteModerator(String user) Public static void promoteViewer(String user) Private static HashMap users = new HashMap() I have a plan for it, but its not 100% finished. I also have a User class that is not currently implemented. Public void sendToUser(BufferedWriter bw, String user, String message) SendToServer(bw, "PRIVMSG #" + CHANNEL + " :" + message) Public void sendToChat(BufferedWriter bw, String message) Public void sendToServer(BufferedWriter bw, String message) If(command.equals("!shutdown") & user.equals(CHANNEL)) Public int processCommands(BufferedWriter bw, String user, String message) Public Chat(String IDENT, String CHANNEL) The Chat class contains methods for sending data to the server, and for processing commands sent by people in chat. (user + " ~~ " + message) Ĭhat.sendToServer(bw, "PING :") Ĭhat.sendToServer(bw, "PART #" + CHANNEL) (user + " has left " + CHANNEL + "'s Channel") (user + " has joined " + CHANNEL + "'s Channel") Int command = chat.processCommands(bw, user, message) Ĭhat.sendToServer(bw, "PONG :") String message = line.substring(line.indexOf(" :") + 2) String user = line.substring(1, line.indexOf("!")) While((line = br.readLine()) != null & isRunning) Public Bot(String IDENT, String HOST, String PASS, String CHANNEL, int PORT)īw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream())) īr = new BufferedReader(new InputStreamReader(s.getInputStream())) Ĭhat.sendToServer(bw, "CAP REQ :/membership") Ĭhat.sendToServer(bw, "CAP REQ :/commands") Ĭhat.sendToServer(bw, "JOIN #" + CHANNEL) The Bot class contains my main loop and creates a chat object. Private static final String CHANNEL = "xxxxx" īot twitchBot = new Bot(IDENT, HOST, PASS, CHANNEL, PORT) Private static final String IDENT = "xxxxx" Private static final String PASS = "oauth:xxxxx" Private static final String HOST = "xxxxx" This is my Main class, all it does is start the bot object.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |