Skip to content

Commit

Permalink
v3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidpatchy committed Nov 5, 2023
1 parent 47071c0 commit 47d6099
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jar {
}

group 'com.sidpatchy'
version '3.0'
version '3.1.0'

sourceCompatibility = 17
targetCompatibility = 17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static EmbedBuilder getInfo(User author) {
.addField("Add Me to a Server", "Adding me to a server is simple, all you have to do is click [here](https://invite.clairebot.net)", true)
.addField("GitHub", "ClaireBot is open source, that means you can view all of its code! Check out its [GitHub!](https://github.com/Sidpatchy/ClaireBot)", true)
.addField("Server Count", "I have enlightened **" + Main.getApi().getServers().size() + "** servers.", true)
.addField("Version", "I am running ClaireBot **v3.0.0**, released on **2023-07-25**", true)
.addField("Version", "I am running ClaireBot **v3.1.0**, released on **2023-11-05**", true)
.addField("Uptime", "Started on <t:" + Main.getStartMillis() / 1000 + ">" + "\n*" + timeSinceStart + "*", true);
}
}
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());
});
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.sidpatchy.clairebot.Embed.Commands.Regular;

import com.sidpatchy.clairebot.Main;
import com.sidpatchy.clairebot.Util.VotingUtils;
import com.sidpatchy.clairebot.Util.Voting.VotingUtils;
import org.javacord.api.entity.message.embed.EmbedBuilder;
import org.javacord.api.entity.server.Server;
import org.javacord.api.entity.user.User;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.sidpatchy.clairebot.MessageComponents.Regular.VotingComponents;
import com.sidpatchy.clairebot.Util.ChannelUtils;
import org.apache.logging.log4j.Logger;
import org.javacord.api.entity.channel.TextChannel;
import org.javacord.api.entity.message.MessageFlag;
import org.javacord.api.entity.message.embed.EmbedBuilder;
import org.javacord.api.entity.server.Server;
Expand Down Expand Up @@ -173,6 +174,22 @@ else if (commandName.equalsIgnoreCase(parseCommands.getCommandName("poll"))) {
.join();
}
}
else if (commandName.equalsIgnoreCase(parseCommands.getCommandName("quote"))) {
TextChannel channel = slashCommandInteraction.getChannel().orElse(null);
if (channel == null) {
slashCommandInteraction.createImmediateResponder()
.addEmbed(ErrorEmbed.getError("NotInAChannel"))
.respond();
return;
}

User finalUser = user;
slashCommandInteraction.respondLater().thenAccept(interactionOriginalResponseUpdater -> {
QuoteEmbed.getQuote(server, finalUser, channel).thenAccept(embedBuilder -> {
interactionOriginalResponseUpdater.addEmbed(embedBuilder).update();
});
});
}
else if (commandName.equalsIgnoreCase(parseCommands.getCommandName("request"))) {
if (server == null) {
slashCommandInteraction.createImmediateResponder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.sidpatchy.clairebot.Main;
import com.sidpatchy.clairebot.Util.MessageUtils;
import com.sidpatchy.clairebot.Util.VotingUtils;
import com.sidpatchy.clairebot.Util.Voting.VotingUtils;
import org.apache.logging.log4j.Logger;
import org.javacord.api.entity.message.Message;
import org.javacord.api.entity.message.embed.Embed;
Expand Down Expand Up @@ -33,8 +33,7 @@ public void onMessageCreate(MessageCreateEvent event) {
embed = message.getEmbeds().get(0);
}
catch (Exception e) {
e.printStackTrace();
Main.getLogger().error(e.getMessage());
Main.getLogger().debug(e.getMessage());
return;
}
if (embed == null) { return; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.sidpatchy.clairebot.Main;
import com.sidpatchy.clairebot.Util.MessageUtils;
import com.sidpatchy.clairebot.Util.VotingUtils;
import com.sidpatchy.clairebot.Util.Voting.VotingUtils;
import org.javacord.api.entity.message.Message;
import org.javacord.api.entity.message.Reaction;
import org.javacord.api.entity.message.embed.Embed;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/sidpatchy/clairebot/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static void main(String[] args) throws InvalidConfigurationException {
Clockwork.initClockwork();

// Set the bot's activity
api.updateActivity("ClaireBot v3.0.0", video_url);
api.updateActivity("ClaireBot v3.1.0", video_url);

// Register slash commands
registerSlashCommands();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public static void RegisterSlashCommand(DiscordApi api) {
.addOption(SlashCommandOption.create(SlashCommandOptionType.STRING, "choice-7", "Custom choice"))
.addOption(SlashCommandOption.create(SlashCommandOptionType.STRING, "choice-8", "Custom choice"))
.addOption(SlashCommandOption.create(SlashCommandOptionType.STRING, "choice-9", "Custom choice")),
new SlashCommandBuilder().setName(parseCommands.getCommandName("quote")).setDescription(parseCommands.getCommandOverview("quote"))
.addOption(SlashCommandOption.create(SlashCommandOptionType.USER, "User", "Optionally mention a user", false)),
new SlashCommandBuilder().setName(parseCommands.getCommandName("request")).setDescription(parseCommands.getCommandOverview("request"))
.addOption(SlashCommandOption.create(SlashCommandOptionType.STRING, "question", "Question to ask", false))
.addOption(SlashCommandOption.create(SlashCommandOptionType.BOOLEAN, "allow-multiple-choices", "Whether multiple choices should be enabled.", false))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sidpatchy.clairebot.Util;
package com.sidpatchy.clairebot.Util.Voting;

import org.apache.commons.lang3.StringUtils;

Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ poll:
help: "Creates a poll. If no queries are added, it will behave similar to the request function."
overview: ""

quote:
name: "quote"
usage: "/quote <user>"
help: "Picks a random message from a user and posts it."
overview: ""

request:
name: "request"
usage: "/request <question>, <optional: allow-multiple-choices>, <optional: queries>..."
Expand Down

0 comments on commit 47d6099

Please sign in to comment.