-
-
Notifications
You must be signed in to change notification settings - Fork 763
Add message search #3052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add message search #3052
Changes from 28 commits
b82bac6
b6ff773
fe0fe5d
77a47b0
3b82ae4
c6666e8
546a661
ba806df
ad58a7d
7c69a14
1bb7e50
16b6bc0
158c318
d43e321
43bdb06
a55a518
e573b11
02e4e2f
6620206
1692ac7
e0437f9
6f16f83
c4c41bc
99f6bab
8a8c366
1524f3b
7f80d25
129a983
98a3c73
f6fa00d
785a120
e66861a
7a30c27
fcb60f2
901617d
a7305c3
af103fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,131 @@ | ||||||
| /* | ||||||
| * Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors | ||||||
| * | ||||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
| * you may not use this file except in compliance with the License. | ||||||
| * You may obtain a copy of the License at | ||||||
| * | ||||||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||||||
| * | ||||||
| * Unless required by applicable law or agreed to in writing, software | ||||||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
| * See the License for the specific language governing permissions and | ||||||
| * limitations under the License. | ||||||
| */ | ||||||
|
|
||||||
| package net.dv8tion.jda.api.entities.messages; | ||||||
|
|
||||||
| import net.dv8tion.jda.api.entities.Guild; | ||||||
| import net.dv8tion.jda.api.entities.Message; | ||||||
| import org.jetbrains.annotations.Unmodifiable; | ||||||
|
|
||||||
| import java.util.List; | ||||||
|
|
||||||
| import javax.annotation.Nonnull; | ||||||
|
|
||||||
| /** | ||||||
| * Base interface for message search responses. | ||||||
| * | ||||||
| * @see Guild#searchMessages() | ||||||
| */ | ||||||
| public interface MessageSearchResponse { | ||||||
| /** | ||||||
| * Whether the message search results are not ready yet. | ||||||
| * | ||||||
| * <p>If this returns {@code true}, you must use {@link #asNotReady()} | ||||||
| * to retry the request according to the returned {@linkplain NotReady#getRetryAfter() delay}. | ||||||
| * | ||||||
| * <p>If this returns {@code false}, you must use {@link #asResults()} to read the results. | ||||||
| * | ||||||
| * <p><b>Tip:</b> You can use this in a guard condition: | ||||||
| * {@snippet lang=java: | ||||||
| * MessageSearchResponse searchResponse; // Assuming you have a response | ||||||
| * if (searchResponse.isNotReady()) { | ||||||
| * // Reply | ||||||
| * return; | ||||||
| * } | ||||||
| * } | ||||||
|
freya022 marked this conversation as resolved.
Outdated
|
||||||
| * | ||||||
| * @return {@code true} if the index is not ready yet, {@code false} otherwise | ||||||
| */ | ||||||
| boolean isNotReady(); | ||||||
|
|
||||||
| /** | ||||||
| * Returns this instance as {@link NotReady NotReady}, if it is one. | ||||||
| * | ||||||
| * @throws IllegalStateException | ||||||
| * If the search has succeeded | ||||||
| * | ||||||
| * @return The {@link NotReady NotReady} state | ||||||
| */ | ||||||
| @Nonnull | ||||||
| NotReady asNotReady(); | ||||||
|
|
||||||
| /** | ||||||
| * Returns this instance as {@link Results Results}, if it is one. | ||||||
| * | ||||||
| * @throws IllegalStateException | ||||||
| * If the search is not ready yet | ||||||
| * | ||||||
| * @return The {@link Results Results} state | ||||||
| */ | ||||||
| @Nonnull | ||||||
| Results asResults(); | ||||||
|
|
||||||
| /** | ||||||
| * Represents a response indicating the search index is not yet ready. | ||||||
| * | ||||||
| * @see #asNotReady() | ||||||
| */ | ||||||
| interface NotReady extends MessageSearchResponse { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not use a union here, since these two response types have nothing in common. Having
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah I forgot to remove the |
||||||
| /** | ||||||
| * The number of documents that has been indexed thus far. | ||||||
| * | ||||||
| * @return Number of currently indexed documents | ||||||
| */ | ||||||
| int getDocumentsIndexed(); | ||||||
|
|
||||||
| /** | ||||||
| * The delay (in seconds) after which you should retry the message search. | ||||||
| * <br>If the value is {@code 0}, you should retry the request after a short delay. | ||||||
| * | ||||||
| * @return Delay (in seconds) before retrying the request | ||||||
| */ | ||||||
| int getRetryAfter(); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we probably should have a utility to automatically do this retry logic, maybe as a followup. Our rate-limiter can already handle retries.
freya022 marked this conversation as resolved.
Outdated
|
||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Represents a response with the found messages. | ||||||
| * | ||||||
| * @see #asResults() | ||||||
| */ | ||||||
| interface Results extends MessageSearchResponse { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| /** | ||||||
| * The messages satisfying the search query. | ||||||
| * | ||||||
| * <p>The returned messages will be missing reactions, member objects (unless cached) | ||||||
| * and the containing thread's members will only contain the {@linkplain net.dv8tion.jda.api.entities.Guild#getSelfMember() current member}, | ||||||
| * if it has joined the thread. | ||||||
| * | ||||||
| * @return The matching messages | ||||||
| */ | ||||||
| @Nonnull | ||||||
| @Unmodifiable | ||||||
| List<Message> getMessages(); | ||||||
|
|
||||||
| /** | ||||||
| * Whether the guild is still being indexed. | ||||||
| * | ||||||
| * @return {@code true} if the indexing is still being done | ||||||
| */ | ||||||
| boolean isDoingDeepHistoricalIndex(); | ||||||
|
|
||||||
| /** | ||||||
| * The total number of messages. May not be accurate as messages are created/deleted. | ||||||
| * | ||||||
| * @return The total results | ||||||
| */ | ||||||
| int getTotalResults(); | ||||||
| } | ||||||
| } | ||||||
Uh oh!
There was an error while loading. Please reload this page.