Package rs.kreme.ksbot.api.queries
Class ChatQuery
- java.lang.Object
-
- rs.kreme.ksbot.api.queries.ChatQuery
-
public class ChatQuery extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description ChatQuery(java.util.Collection<KSChatMessages> chats)
Constructor to initialize the query with a collection of ChatMessages.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ChatQuery
betweenTimestamps(long startTimestamp, long endTimestamp)
Filters chat messages sent between two timestamps.ChatQuery
contains(java.lang.String string)
Filters chat messages that contain a specific substring in their content.int
count()
Counts the number of chat messages in the stream.boolean
empty()
Checks if there are no chat messages in the query.boolean
exists()
Checks if any chat messages exist in the stream.ChatQuery
filter(java.util.function.Predicate<? super KSChatMessages> predicate)
Filters the chat messages based on a provided predicate.KSChatMessages
first()
Retrieves the first chat message in the stream.java.util.List<KSChatMessages>
first(int i)
Retrieves the first 'i' chat messages in the stream.ChatQuery
from(java.lang.String string)
Filters chat messages sent by a specific user.KSChatMessages
last()
Retrieves the last chat message in the stream.java.util.List<KSChatMessages>
list()
Retrieves all remaining chat messages as a list.ChatQuery
messagesAgo(long duration, java.util.concurrent.TimeUnit timeUnit)
Filters chat messages sent within a specific duration from the current time.KSChatMessages
random()
Retrieves a random chat message from the stream.ChatQuery
withoutType(KSChatMessages.MessageTypes type)
Excludes chat messages of a specific type.ChatQuery
withType(KSChatMessages.MessageTypes type)
Filters chat messages of a specific type.
-
-
-
Constructor Detail
-
ChatQuery
public ChatQuery(java.util.Collection<KSChatMessages> chats)
Constructor to initialize the query with a collection of ChatMessages.- Parameters:
chats
- the collection of chat messages to query.
-
-
Method Detail
-
filter
public ChatQuery filter(java.util.function.Predicate<? super KSChatMessages> predicate)
Filters the chat messages based on a provided predicate.- Parameters:
predicate
- the condition to filter messages.- Returns:
- the current instance for method chaining.
-
contains
public ChatQuery contains(java.lang.String string)
Filters chat messages that contain a specific substring in their content.- Parameters:
string
- the substring to match.- Returns:
- the current instance for method chaining.
-
from
public ChatQuery from(java.lang.String string)
Filters chat messages sent by a specific user.- Parameters:
string
- the username to match.- Returns:
- the current instance for method chaining.
-
withType
public ChatQuery withType(KSChatMessages.MessageTypes type)
Filters chat messages of a specific type.- Parameters:
type
- the type of messages to match.- Returns:
- the current instance for method chaining.
-
withoutType
public ChatQuery withoutType(KSChatMessages.MessageTypes type)
Excludes chat messages of a specific type.- Parameters:
type
- the type of messages to exclude.- Returns:
- the current instance for method chaining.
-
empty
public boolean empty()
Checks if there are no chat messages in the query.- Returns:
- true if the stream is empty; otherwise, false.
-
first
public KSChatMessages first()
Retrieves the first chat message in the stream.- Returns:
- the first message, or null if the stream is empty.
-
last
public KSChatMessages last()
Retrieves the last chat message in the stream.- Returns:
- the last message, or null if the stream is empty.
-
random
public KSChatMessages random()
Retrieves a random chat message from the stream.- Returns:
- a random message, or null if the stream is empty.
-
count
public int count()
Counts the number of chat messages in the stream.- Returns:
- the number of messages.
-
list
public java.util.List<KSChatMessages> list()
Retrieves all remaining chat messages as a list.- Returns:
- a list of chat messages.
-
exists
public boolean exists()
Checks if any chat messages exist in the stream.- Returns:
- true if there are messages; otherwise, false.
-
first
public java.util.List<KSChatMessages> first(int i)
Retrieves the first 'i' chat messages in the stream.- Parameters:
i
- the maximum number of messages to retrieve.- Returns:
- a list containing up to 'i' messages.
-
betweenTimestamps
public ChatQuery betweenTimestamps(long startTimestamp, long endTimestamp)
Filters chat messages sent between two timestamps.- Parameters:
startTimestamp
- the lower bound (inclusive) of the time range.endTimestamp
- the upper bound (exclusive) of the time range.- Returns:
- the current instance for method chaining.
-
messagesAgo
public ChatQuery messagesAgo(long duration, java.util.concurrent.TimeUnit timeUnit)
Filters chat messages sent within a specific duration from the current time.- Parameters:
duration
- the amount of time to look back.timeUnit
- the unit of time for the duration (e.g., SECONDS, MINUTES, HOURS, DAYS).- Returns:
- the current instance for method chaining.
-
-