// Private message commands public void onPrivateMessage(PrivateMessageEvent event) throws Exception { String message = event.getMessage(); String[] seperated; if (event.getMessage().contains(" ")) seperated = event.getMessage().split(" "); else seperated = new String[] {event.getMessage()}; // If it's a command, let's execute it! if (privateMessageCommandMap.containsKey(seperated[0])) { String commandString = seperated[0]; Method method = privateMessageCommandMap.get(commandString); PrivateMessageCommand command = method.getAnnotation(PrivateMessageCommand.class); // Build args String[] args = buildArgs(seperated); // Execute command. (null represents object to invoke on, since method is static no object) // Check permissions if (hasPermission(command.permissionLevel(), event.getUser(), null)) { if (args.length < command.minArgs()) { event.respond("Not enough arguements! Usage: " + command.usage()); } else if (args.length > command.maxArgs()) { event.respond("Too many arguements! Usage: " + command.usage()); } else { // Okay, everything's all good, lets run the command! method.invoke(null, event, args); } } else { event.respond("You do not have permission to execute this command!"); } } }
@Override public void onPrivateMessage(PrivateMessageEvent event) { userLevel = Globals.getUserLevel(event.getUser().getNick()); if (userLevel >= Globals.CAN_SAY_DO) { if (Globals.isIdentified(event, event.getUser().getNick())) { String[] parts = event.getMessage().split(" "); // to pm somebody if (parts[0].toLowerCase().equals("sayto") && (userLevel >= Globals.CAN_SAY_DO)) event.getBot().sendMessage(parts[1], Globals.putTogether(parts, 2, parts.length - 1)); // to send an /me action to smby if (parts[0].toLowerCase().equals("doat") && (userLevel >= Globals.CAN_SAY_DO)) event.getBot().sendAction(parts[1], Globals.putTogether(parts, 2, parts.length - 1)); // to send raw irc data if (parts[0].toLowerCase().equals("sendraw") && (userLevel >= Globals.FULL_ADMIN)) event.getBot().sendRawLine(Globals.putTogether(parts, 1, parts.length - 1)); // to enable or disable the verbose mode if (parts[0].equals("verbose") && parts[1].equals("on") && event.getUser().getNick().equals(Globals.BOTMASTER)) Globals.verbose = true; if (parts[0].equals("verbose") && parts[1].equals("off") && event.getUser().getNick().equals(Globals.BOTMASTER)) Globals.verbose = false; // to quit the bot if (parts[0].equals("quit") && event.getUser().getNick().equals(Globals.BOTMASTER)) { event.getBot().disconnect(); try { Thread.sleep(5000); } catch (InterruptedException e) { } System.exit(0); } } else event .getBot() .sendNotice( event.getUser(), "Please identify with NickServ if you want to use the admin commands."); } }