-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
71 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/com/sidpatchy/clairebot/Embed/Commands/Regular/QuoteEmbed.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.sidpatchy.clairebot.Embed.Commands.Regular; | ||
import com.sidpatchy.clairebot.Embed.ErrorEmbed; | ||
import com.sidpatchy.clairebot.Main; | ||
import org.javacord.api.entity.channel.TextChannel; | ||
import org.javacord.api.entity.message.Message; | ||
import org.javacord.api.entity.message.embed.EmbedBuilder; | ||
import org.javacord.api.entity.server.Server; | ||
import org.javacord.api.entity.user.User; | ||
|
||
import java.util.List; | ||
import java.util.Random; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class QuoteEmbed { | ||
public static CompletableFuture<EmbedBuilder> getQuote(Server server, final User user, TextChannel channel) { | ||
|
||
return channel.getMessages(50000).thenApply(messages -> { | ||
List<Message> userMessages = messages.stream() | ||
.filter(message -> message.getAuthor().getId() == user.getId()) | ||
.toList(); | ||
|
||
if (userMessages.isEmpty()) { | ||
// user not sent messages | ||
return ErrorEmbed.getError(Main.getErrorCode("UserNotInSet")); | ||
} | ||
|
||
Random random = new Random(); | ||
int rand = random.nextInt(userMessages.size()); | ||
Message randomMessage = userMessages.get(rand); | ||
|
||
return new EmbedBuilder() | ||
.setAuthor(user.getDisplayName(server), randomMessage.getLink().toString(), user.getAvatar()) | ||
.setDescription(randomMessage.getContent()) | ||
.setTimestamp(randomMessage.getCreationTimestamp()) | ||
.setFooter(randomMessage.getIdAsString()); | ||
}); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/com/sidpatchy/clairebot/Embed/Commands/Regular/VotingEmbed.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...sidpatchy/clairebot/Util/VotingUtils.java → ...hy/clairebot/Util/Voting/VotingUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters