- Joined
- May 24, 2016
- Messages
- 1,113
- Thread Author
- #1
One of the things I do to reduce cpu usage in some bots, is to ditch using a ChatboxListener wherever possible.
Instead you can use:
However this returns every single message in your chatbox. To fix this I made a class which will return recent messages only. Feel free to use it!
Example usage:
Instead you can use:
Code:
List<Chatbox.Message> messages = Chatbox.getMessages()
However this returns every single message in your chatbox. To fix this I made a class which will return recent messages only. Feel free to use it!
Code:
/**
* Class for grabbing recent messages in the Chatbox
*
* @author auxi
* @version 1.0
*/
public class Chat {
public static List<Chatbox.Message> getRecentMessages(int messages, Chatbox.Message.Type type) {
return Chatbox.getMessages(type).stream().sorted(Comparator.reverseOrder()).limit(messages).collect(Collectors.toList());
}
public static boolean isMessagePresent(String message, int messagesToCheck, Chatbox.Message.Type type) {
return getRecentMessages(messagesToCheck, type).stream().map(Chatbox.Message::getMessage).anyMatch(a -> a.contains(message));
}
}
Example usage:
Code:
if (Interaction.interact(pouch, "Summon") && Execution.delayUntil(() -> !pouch.isValid(), 1200, 1800)) {
bot.setStatus("[Familiar] Successfully summoned familiar");
} else if (Chat.isMessagePresent("too big to summon here", 5, Chatbox.Message.Type.SERVER)) {
getLogger().warn("[Familiar] Failed to summon familiar as area is too small!");
}
Last edited: