This commit is contained in:
@@ -6,7 +6,8 @@ import java.util.LinkedList;
|
||||
|
||||
public class Alias
|
||||
{
|
||||
private Alias() {
|
||||
private Alias()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
@@ -14,11 +15,11 @@ public class Alias
|
||||
{
|
||||
LinkedList<String> aliases = command.getCommandLabels();
|
||||
StringBuilder aliasesStringBuilder = new StringBuilder();
|
||||
for(int i = 0; i < aliases.size(); i++)
|
||||
for (int i = 0; i < aliases.size(); i++)
|
||||
{
|
||||
aliasesStringBuilder.append("`").append(aliases.get(i)).append("`");
|
||||
|
||||
if(i + 1 != aliases.size())
|
||||
if (i + 1 != aliases.size())
|
||||
aliasesStringBuilder.append(", "); // separate with comma except on last iteration
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@ import java.util.List;
|
||||
|
||||
public class BotInfo
|
||||
{
|
||||
private BotInfo() {
|
||||
private BotInfo()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
@@ -25,7 +26,7 @@ public class BotInfo
|
||||
|
||||
// thumbnail
|
||||
String botAvatarUrl = HidekoBot.getAPI().getSelfUser().getAvatarUrl();
|
||||
if(botAvatarUrl != null) embedBuilder.setThumbnail(botAvatarUrl);
|
||||
if (botAvatarUrl != null) embedBuilder.setThumbnail(botAvatarUrl);
|
||||
|
||||
// help field
|
||||
long ownerId = Cache.getBotOwnerId();
|
||||
@@ -37,12 +38,12 @@ public class BotInfo
|
||||
|
||||
// type-specific commands list field
|
||||
StringBuilder commandsListBuilder = new StringBuilder();
|
||||
commandsListBuilder.append(commandLabels.size()).append( " total - ");
|
||||
for(int i = 0; i < commandLabels.size(); i++)
|
||||
commandsListBuilder.append(commandLabels.size()).append(" total - ");
|
||||
for (int i = 0; i < commandLabels.size(); i++)
|
||||
{
|
||||
commandsListBuilder.append("`").append(commandLabels.get(i)).append("`");
|
||||
|
||||
if(i + 1 != commandLabels.size()) // don't add comma in last iteration
|
||||
if (i + 1 != commandLabels.size()) // don't add comma in last iteration
|
||||
{
|
||||
commandsListBuilder.append(", ");
|
||||
}
|
||||
@@ -55,9 +56,10 @@ public class BotInfo
|
||||
|
||||
// message commands info field
|
||||
String messageCommandsInfo;
|
||||
if(Cache.getMessageCommandListener() == null)
|
||||
if (Cache.getMessageCommandListener() == null)
|
||||
messageCommandsInfo = "❌ disabled";
|
||||
else {
|
||||
else
|
||||
{
|
||||
messageCommandsInfo = "✅ available";
|
||||
commandsCount += Cache.getMessageCommandListener().getRegisteredCommands().size();
|
||||
}
|
||||
@@ -65,9 +67,10 @@ public class BotInfo
|
||||
|
||||
// slash commands info field
|
||||
String slashCommandsInfo;
|
||||
if(Cache.getMessageCommandListener() == null)
|
||||
if (Cache.getMessageCommandListener() == null)
|
||||
slashCommandsInfo = "❌ disabled";
|
||||
else {
|
||||
else
|
||||
{
|
||||
slashCommandsInfo = "✅ available";
|
||||
commandsCount += Cache.getSlashCommandListener().getRegisteredCommands().size();
|
||||
}
|
||||
@@ -75,10 +78,11 @@ public class BotInfo
|
||||
|
||||
// random.org integration field
|
||||
String randomOrgInfo;
|
||||
if(RandomUtil.isRandomOrgKeyValid())
|
||||
if (RandomUtil.isRandomOrgKeyValid())
|
||||
{
|
||||
randomOrgInfo = "✅ connected";
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
randomOrgInfo = "❌ disabled";
|
||||
}
|
||||
embedBuilder.addField("Random.org", randomOrgInfo, true);
|
||||
|
||||
@@ -14,34 +14,42 @@ import java.util.List;
|
||||
|
||||
public class ClearChat
|
||||
{
|
||||
private ClearChat() {
|
||||
private ClearChat()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static String getLabel() {
|
||||
public static String getLabel()
|
||||
{
|
||||
return "clear";
|
||||
}
|
||||
|
||||
public static String getDescription() {
|
||||
public static String getDescription()
|
||||
{
|
||||
return "Clear the current channel's chat.";
|
||||
}
|
||||
|
||||
public static Permission getPermission() {
|
||||
public static Permission getPermission()
|
||||
{
|
||||
return Permission.MESSAGE_MANAGE;
|
||||
}
|
||||
|
||||
public static String checkDMs(Channel channel)
|
||||
{
|
||||
if(!(channel instanceof TextChannel))
|
||||
{ return "\uD83D\uDE22 Sorry! I can't delete messages here."; }
|
||||
if (!(channel instanceof TextChannel))
|
||||
{
|
||||
return "\uD83D\uDE22 Sorry! I can't delete messages here.";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String checkDeleteAmount(int toDeleteAmount)
|
||||
{
|
||||
if(toDeleteAmount <= 0)
|
||||
{ return "\uD83D\uDE22 Sorry, I can't delete that amount of messages!"; }
|
||||
if (toDeleteAmount <= 0)
|
||||
{
|
||||
return "\uD83D\uDE22 Sorry, I can't delete that amount of messages!";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -65,7 +73,7 @@ public class ClearChat
|
||||
|
||||
//if there are some messages left, but less than <limit>, we need one more iterations.
|
||||
int remainder = toDeleteAmount % limit;
|
||||
if(remainder != 0) iterations++;
|
||||
if (remainder != 0) iterations++;
|
||||
|
||||
// set the starting point.
|
||||
long messageId = startingMessageId;
|
||||
@@ -74,59 +82,62 @@ public class ClearChat
|
||||
boolean outOfBounds = false;
|
||||
|
||||
// do iterate.
|
||||
for(int iteration = 0; iteration < iterations; iteration++)
|
||||
for (int iteration = 0; iteration < iterations; iteration++)
|
||||
{
|
||||
if(outOfBounds) break;
|
||||
if (outOfBounds) break;
|
||||
|
||||
// set how many messages to delete for this iteration (usually <limit> unless there's a remainder)
|
||||
int iterationSize = limit;
|
||||
|
||||
// if we are at the last iteration... check if we have <limit> or fewer messages to delete
|
||||
if(iteration+1 == iterations && remainder != 0) {
|
||||
if (iteration + 1 == iterations && remainder != 0)
|
||||
{
|
||||
iterationSize = remainder;
|
||||
}
|
||||
|
||||
if(iterationSize == 1)
|
||||
if (iterationSize == 1)
|
||||
{
|
||||
// grab the message
|
||||
Message toDelete = channel.retrieveMessageById(messageId).complete();
|
||||
//only delete one message
|
||||
if(toDelete != null) toDelete.delete().queue();
|
||||
if (toDelete != null) toDelete.delete().queue();
|
||||
else outOfBounds = true;
|
||||
// increase deleted counter by 1
|
||||
deleted++;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
// get the last <iterationSize - 1> messages.
|
||||
MessageHistory.MessageRetrieveAction action = channel.getHistoryBefore(messageId, iterationSize - 1);
|
||||
// note: first one is the most recent, last one is the oldest message.
|
||||
List<Message> messages = new ArrayList<>();
|
||||
// (we are skipping first iteration since it would return an error, given that the id is the slash command and not a message)
|
||||
if(iteration!=0) messages.add(channel.retrieveMessageById(messageId).complete());
|
||||
if (iteration != 0) messages.add(channel.retrieveMessageById(messageId).complete());
|
||||
messages.addAll(action.complete().getRetrievedHistory());
|
||||
|
||||
// check if we only have one or zero messages left (trying to delete more than possible)
|
||||
if(messages.size() <= 1)
|
||||
if (messages.size() <= 1)
|
||||
{
|
||||
outOfBounds = true;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
// before deleting, we need to grab the <previous to the oldest> message's id for next iteration.
|
||||
action = channel.getHistoryBefore(messages.getLast().getIdLong(), 1);
|
||||
|
||||
List<Message> previousMessage = action.complete().getRetrievedHistory();
|
||||
|
||||
// if that message exists (we are not out of bounds)... store it
|
||||
if(!previousMessage.isEmpty()) messageId = previousMessage.getFirst().getIdLong();
|
||||
if (!previousMessage.isEmpty()) messageId = previousMessage.getFirst().getIdLong();
|
||||
else outOfBounds = true;
|
||||
}
|
||||
|
||||
// queue messages for deletion
|
||||
if(messages.size() == 1)
|
||||
if (messages.size() == 1)
|
||||
{
|
||||
messages.getFirst().delete().queue();
|
||||
}
|
||||
else if(!messages.isEmpty())
|
||||
} else if (!messages.isEmpty())
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
((TextChannel) channel).deleteMessages(messages).complete();
|
||||
/* alternatively, we could use purgeMessages, which is smarter...
|
||||
however, it also tries to delete messages older than 2 weeks
|
||||
@@ -156,18 +167,22 @@ public class ClearChat
|
||||
public static String parseAmount(int deleted)
|
||||
{
|
||||
|
||||
if(deleted < 1)
|
||||
if (deleted < 1)
|
||||
{
|
||||
return "\uD83D\uDE22 Couldn't clear any message!";
|
||||
} else if(deleted == 1)
|
||||
} else if (deleted == 1)
|
||||
{
|
||||
return "✂ Cleared 1 message!";
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
return "✂ Cleared " + deleted + " messages!";
|
||||
}
|
||||
}
|
||||
|
||||
// cap the amount to avoid abuse.
|
||||
public static int getMaxAmount() { return 1000; }
|
||||
public static int getMaxAmount()
|
||||
{
|
||||
return 1000;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,11 +14,13 @@ import java.util.List;
|
||||
public class CoinFlip
|
||||
{
|
||||
|
||||
private CoinFlip() {
|
||||
private CoinFlip()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static Button getReflipButton() {
|
||||
public static Button getReflipButton()
|
||||
{
|
||||
return Button.primary("coinflip_reflip", "Flip again")
|
||||
.withEmoji(Emoji.fromUnicode("\uD83E\uDE99"));
|
||||
}
|
||||
@@ -28,10 +30,11 @@ public class CoinFlip
|
||||
int rand = RandomUtil.getRandomNumber(0, 1);
|
||||
String msg;
|
||||
|
||||
if(rand == 1)
|
||||
if (rand == 1)
|
||||
{
|
||||
msg = ":coin: It's **Heads**!";
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
msg = "It's **Tails**! :coin:";
|
||||
}
|
||||
|
||||
@@ -41,7 +44,7 @@ public class CoinFlip
|
||||
public static void buttonReFlip(ButtonInteractionEvent event)
|
||||
{
|
||||
// check if the user interacting is the same one who ran the command
|
||||
if(!(Cache.getDatabaseSource().isUserTrackedFor(event.getUser().getId(), event.getMessageId())))
|
||||
if (!(Cache.getDatabaseSource().isUserTrackedFor(event.getUser().getId(), event.getMessageId())))
|
||||
{
|
||||
event.reply("❌ You did not run this command!").setEphemeral(true).queue();
|
||||
return;
|
||||
@@ -59,7 +62,8 @@ public class CoinFlip
|
||||
{
|
||||
// set the command as expiring and restrict it to the user who ran it
|
||||
trackAndRestrict(message, event.getUser());
|
||||
}, (error) -> {});
|
||||
}, (error) -> {
|
||||
});
|
||||
}
|
||||
|
||||
public static void trackAndRestrict(Message replyMessage, User user)
|
||||
|
||||
@@ -15,7 +15,8 @@ import java.util.UUID;
|
||||
public class DiceRoll
|
||||
{
|
||||
|
||||
private DiceRoll() {
|
||||
private DiceRoll()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
@@ -30,25 +31,26 @@ public class DiceRoll
|
||||
UUID lastPushedDice = null;
|
||||
int totalRolls = 0;
|
||||
|
||||
for(String arg : args)
|
||||
for (String arg : args)
|
||||
{
|
||||
if(totalRolls > 200)
|
||||
if (totalRolls > 200)
|
||||
{
|
||||
return new MessageResponse("Too many total rolls!", null);
|
||||
}
|
||||
|
||||
if(arg.matches(amountRegex))
|
||||
if (arg.matches(amountRegex))
|
||||
{
|
||||
currentAmount = Integer.parseInt(arg);
|
||||
|
||||
if(currentDice == null)
|
||||
if (currentDice == null)
|
||||
{
|
||||
currentDice = new Dice(6);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
currentDice = new Dice(currentDice);
|
||||
}
|
||||
|
||||
if(currentAmount > 100)
|
||||
if (currentAmount > 100)
|
||||
{
|
||||
return new MessageResponse("Too many rolls (`" + currentAmount + "`)!", null);
|
||||
}
|
||||
@@ -56,25 +58,24 @@ public class DiceRoll
|
||||
lastPushedDice = currentDice.getUUID();
|
||||
dicesToRoll.put(currentDice, currentAmount);
|
||||
totalRolls += currentAmount;
|
||||
}
|
||||
else if(arg.matches(diceRegex))
|
||||
} else if (arg.matches(diceRegex))
|
||||
{
|
||||
int sides = Integer.parseInt(arg.substring(1));
|
||||
|
||||
if(sides > 10000)
|
||||
if (sides > 10000)
|
||||
{
|
||||
return new MessageResponse("Too many sides (`" + sides + "`)!", null);
|
||||
}
|
||||
|
||||
if(args.length == 1)
|
||||
if (args.length == 1)
|
||||
{
|
||||
dicesToRoll.put(new Dice(sides), 1);
|
||||
totalRolls++;
|
||||
} else
|
||||
{
|
||||
if(currentDice != null)
|
||||
if (currentDice != null)
|
||||
{
|
||||
if(lastPushedDice == null || !lastPushedDice.equals(currentDice.getUUID()))
|
||||
if (lastPushedDice == null || !lastPushedDice.equals(currentDice.getUUID()))
|
||||
{
|
||||
dicesToRoll.put(currentDice, 1);
|
||||
lastPushedDice = currentDice.getUUID();
|
||||
@@ -87,16 +88,16 @@ public class DiceRoll
|
||||
}
|
||||
}
|
||||
|
||||
if(lastPushedDice == null)
|
||||
if (lastPushedDice == null)
|
||||
{
|
||||
if(currentDice != null)
|
||||
if (currentDice != null)
|
||||
{
|
||||
dicesToRoll.put(currentDice, 1);
|
||||
totalRolls++;
|
||||
}
|
||||
} else
|
||||
{
|
||||
if(!lastPushedDice.equals(currentDice.getUUID()))
|
||||
if (!lastPushedDice.equals(currentDice.getUUID()))
|
||||
{
|
||||
dicesToRoll.put(new Dice(currentDice), 1);
|
||||
totalRolls++;
|
||||
@@ -106,19 +107,19 @@ public class DiceRoll
|
||||
LinkedList<Dice> rolledDices = new LinkedList<>();
|
||||
|
||||
// in case no dice was specified (or invalid), roll a standard 6-sided dice.
|
||||
if(dicesToRoll.isEmpty())
|
||||
if (dicesToRoll.isEmpty())
|
||||
{
|
||||
Dice standardDice = new Dice(6);
|
||||
dicesToRoll.put(standardDice, 1);
|
||||
totalRolls = 1;
|
||||
}
|
||||
|
||||
for(Map.Entry<Dice, Integer> entry : dicesToRoll.entrySet())
|
||||
for (Map.Entry<Dice, Integer> entry : dicesToRoll.entrySet())
|
||||
{
|
||||
Dice dice = entry.getKey();
|
||||
Integer rollsToMake = entry.getValue();
|
||||
|
||||
for(int roll = 0; roll < rollsToMake; roll++)
|
||||
|
||||
for (int roll = 0; roll < rollsToMake; roll++)
|
||||
{
|
||||
dice.roll();
|
||||
rolledDices.add(new Dice(dice));
|
||||
@@ -131,20 +132,23 @@ public class DiceRoll
|
||||
embedBuilder.setAuthor(author.getAsTag(), null, author.getAvatarUrl());
|
||||
embedBuilder.setTitle("Dice Roll");
|
||||
|
||||
if(RandomUtil.isRandomOrgKeyValid())
|
||||
if (RandomUtil.isRandomOrgKeyValid())
|
||||
embedBuilder.setFooter("Seed provided by random.org");
|
||||
|
||||
StringBuilder message = new StringBuilder();
|
||||
int total = 0;
|
||||
|
||||
int previousDiceSides = 0;
|
||||
for (Dice dice : rolledDices) {
|
||||
for (Dice dice : rolledDices)
|
||||
{
|
||||
int diceSize = dice.getSides();
|
||||
|
||||
if (previousDiceSides != diceSize) {
|
||||
if (previousDiceSides != diceSize)
|
||||
{
|
||||
message.append("\nd").append(diceSize).append(": ");
|
||||
previousDiceSides = diceSize;
|
||||
} else if (previousDiceSides != 0) {
|
||||
} else if (previousDiceSides != 0)
|
||||
{
|
||||
message.append(", ");
|
||||
}
|
||||
|
||||
@@ -154,7 +158,7 @@ public class DiceRoll
|
||||
}
|
||||
|
||||
// discord doesn't allow embed fields to be longer than 1024 and errors out
|
||||
if(message.length() > 1024)
|
||||
if (message.length() > 1024)
|
||||
{
|
||||
return new MessageResponse("Too many rolls!", null);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ import wtf.beatrice.hidekobot.HidekoBot;
|
||||
public class Invite
|
||||
{
|
||||
|
||||
private Invite() {
|
||||
private Invite()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
@@ -22,7 +23,7 @@ public class Invite
|
||||
{
|
||||
embedBuilder.setColor(Cache.getBotColor());
|
||||
String avatarUrl = HidekoBot.getAPI().getSelfUser().getAvatarUrl();
|
||||
if(avatarUrl != null) embedBuilder.setThumbnail(avatarUrl);
|
||||
if (avatarUrl != null) embedBuilder.setThumbnail(avatarUrl);
|
||||
embedBuilder.setTitle("Invite");
|
||||
embedBuilder.appendDescription("Click on the button below to invite " +
|
||||
Cache.getBotName() +
|
||||
|
||||
@@ -11,7 +11,8 @@ import java.util.concurrent.TimeUnit;
|
||||
public class LoveCalculator
|
||||
{
|
||||
|
||||
private LoveCalculator() {
|
||||
private LoveCalculator()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
@@ -21,7 +22,7 @@ public class LoveCalculator
|
||||
String userId2 = user2.getId();
|
||||
|
||||
Integer loveAmount = Cache.getLoveCalculatorValue(userId1, userId2);
|
||||
if(loveAmount == null)
|
||||
if (loveAmount == null)
|
||||
{
|
||||
loveAmount = RandomUtil.getRandomNumber(0, 100);
|
||||
Cache.cacheLoveCalculatorValue(userId1, userId2, loveAmount);
|
||||
@@ -30,9 +31,9 @@ public class LoveCalculator
|
||||
}
|
||||
|
||||
String formattedAmount = loveAmount + "%";
|
||||
if(loveAmount <= 30) formattedAmount += "... \uD83D\uDE22";
|
||||
else if(loveAmount < 60) formattedAmount += "! \uD83E\uDDD0";
|
||||
else if(loveAmount < 75) formattedAmount += "!!! \uD83E\uDD73";
|
||||
if (loveAmount <= 30) formattedAmount += "... \uD83D\uDE22";
|
||||
else if (loveAmount < 60) formattedAmount += "! \uD83E\uDDD0";
|
||||
else if (loveAmount < 75) formattedAmount += "!!! \uD83E\uDD73";
|
||||
else formattedAmount = "✨ " + formattedAmount + "!!! \uD83D\uDE0D\uD83D\uDCA5";
|
||||
|
||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
|
||||
@@ -14,7 +14,8 @@ import java.util.List;
|
||||
public class MagicBall
|
||||
{
|
||||
|
||||
private MagicBall() {
|
||||
private MagicBall()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
@@ -55,7 +56,7 @@ public class MagicBall
|
||||
{
|
||||
// add a question mark at the end, if missing.
|
||||
// this might not always apply but it's fun
|
||||
if(!question.endsWith("?")) question += "?";
|
||||
if (!question.endsWith("?")) question += "?";
|
||||
|
||||
String answer = getRandomAnswer();
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@ import wtf.beatrice.hidekobot.objects.MessageResponse;
|
||||
public class ProfileImage
|
||||
{
|
||||
|
||||
private ProfileImage() {
|
||||
private ProfileImage()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
@@ -20,9 +21,11 @@ public class ProfileImage
|
||||
// method to find closest value to accepted values
|
||||
int distance = Math.abs(acceptedSizes[0] - resolution);
|
||||
int idx = 0;
|
||||
for(int c = 1; c < acceptedSizes.length; c++){
|
||||
for (int c = 1; c < acceptedSizes.length; c++)
|
||||
{
|
||||
int cdistance = Math.abs(acceptedSizes[c] - resolution);
|
||||
if(cdistance < distance){
|
||||
if (cdistance < distance)
|
||||
{
|
||||
idx = c;
|
||||
distance = cdistance;
|
||||
}
|
||||
@@ -40,14 +43,15 @@ public class ProfileImage
|
||||
User.Profile userProfile = user.retrieveProfile().complete();
|
||||
ImageProxy bannerProxy = userProfile.getBanner();
|
||||
|
||||
if(imageType == ImageType.AVATAR)
|
||||
if (imageType == ImageType.AVATAR)
|
||||
{
|
||||
resolutionString = resolution + " × " + resolution;
|
||||
imageLink = user.getEffectiveAvatar().getUrl(resolution);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
int verticalRes = 361 * resolution / 1024;
|
||||
resolutionString = resolution + " × " + verticalRes;
|
||||
if(bannerProxy != null)
|
||||
if (bannerProxy != null)
|
||||
imageLink = bannerProxy.getUrl(resolution);
|
||||
}
|
||||
|
||||
@@ -64,21 +68,22 @@ public class ProfileImage
|
||||
|
||||
// string builder to create a string that links to all available resolutions
|
||||
StringBuilder links = new StringBuilder();
|
||||
for(int pos = 0; pos < acceptedSizes.length; pos++)
|
||||
for (int pos = 0; pos < acceptedSizes.length; pos++)
|
||||
{
|
||||
int currSize = acceptedSizes[pos];
|
||||
|
||||
String currLink;
|
||||
if(imageType == ImageType.AVATAR)
|
||||
if (imageType == ImageType.AVATAR)
|
||||
{
|
||||
currLink = user.getEffectiveAvatar().getUrl(currSize);
|
||||
} else {
|
||||
if(bannerProxy == null) break;
|
||||
} else
|
||||
{
|
||||
if (bannerProxy == null) break;
|
||||
currLink = bannerProxy.getUrl(currSize);
|
||||
}
|
||||
|
||||
links.append("**[").append(currSize).append("px](").append(currLink).append(")**");
|
||||
if(pos + 1 != acceptedSizes.length) // don't add a separator on the last iteration
|
||||
if (pos + 1 != acceptedSizes.length) // don't add a separator on the last iteration
|
||||
{
|
||||
links.append(" | ");
|
||||
}
|
||||
@@ -87,15 +92,16 @@ public class ProfileImage
|
||||
embedBuilder.addField("Available resolutions", links.toString(), false);
|
||||
|
||||
|
||||
|
||||
if(imageLink != null)
|
||||
if (imageLink != null)
|
||||
embedBuilder.setImage(imageLink);
|
||||
|
||||
|
||||
if(imageLink == null) {
|
||||
if (imageLink == null)
|
||||
{
|
||||
String error = "I couldn't find " + user.getAsMention() + "'s " + imageTypeName + "!";
|
||||
return new MessageResponse(error, null);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
return new MessageResponse(null, embedBuilder.build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,13 @@ import net.dv8tion.jda.api.Permission;
|
||||
public class Say
|
||||
{
|
||||
|
||||
private Say() {
|
||||
private Say()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static Permission getPermission() {
|
||||
public static Permission getPermission()
|
||||
{
|
||||
return Permission.MESSAGE_MANAGE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,8 @@ import java.util.concurrent.TimeUnit;
|
||||
public class Trivia
|
||||
{
|
||||
|
||||
private Trivia() {
|
||||
private Trivia()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
@@ -52,14 +53,23 @@ public class Trivia
|
||||
// first string is the channelId, the list contain all score records for that channel
|
||||
public static HashMap<String, LinkedList<TriviaScore>> channelAndScores = new HashMap<>();
|
||||
|
||||
public static String getTriviaLink(int categoryId) {return TRIVIA_API_LINK + categoryId; }
|
||||
public static String getCategoriesLink() {return TRIVIA_API_CATEGORIES_LINK; }
|
||||
public static String getTriviaLink(int categoryId)
|
||||
{
|
||||
return TRIVIA_API_LINK + categoryId;
|
||||
}
|
||||
|
||||
public static String getNoDMsError() {
|
||||
public static String getCategoriesLink()
|
||||
{
|
||||
return TRIVIA_API_CATEGORIES_LINK;
|
||||
}
|
||||
|
||||
public static String getNoDMsError()
|
||||
{
|
||||
return "\uD83D\uDE22 Sorry! Trivia doesn't work in DMs.";
|
||||
}
|
||||
|
||||
public static String getTriviaAlreadyRunningError() {
|
||||
public static String getTriviaAlreadyRunningError()
|
||||
{
|
||||
// todo nicer looking
|
||||
return "Trivia is already running here!";
|
||||
}
|
||||
@@ -67,10 +77,10 @@ public class Trivia
|
||||
public static MessageResponse generateMainScreen()
|
||||
{
|
||||
JSONObject categoriesJson = Trivia.fetchJson(Trivia.getCategoriesLink());
|
||||
if(categoriesJson == null)
|
||||
if (categoriesJson == null)
|
||||
return new MessageResponse("Error fetching trivia!", null); // todo nicer with emojis
|
||||
List<TriviaCategory> categories = Trivia.parseCategories(categoriesJson);
|
||||
if(categories.isEmpty())
|
||||
if (categories.isEmpty())
|
||||
return new MessageResponse("Error parsing trivia categories!", null); // todo nicer with emojis
|
||||
|
||||
categories.sort(new TriviaCategoryComparator());
|
||||
@@ -90,7 +100,7 @@ public class Trivia
|
||||
|
||||
StringSelectMenu.Builder menuBuilder = StringSelectMenu.create("trivia_categories");
|
||||
|
||||
for(TriviaCategory category : categories)
|
||||
for (TriviaCategory category : categories)
|
||||
{
|
||||
String name = category.categoryName();
|
||||
int id = category.categoryId();
|
||||
@@ -102,20 +112,22 @@ public class Trivia
|
||||
|
||||
public static JSONObject fetchJson(String link)
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
URL url = new URL(link);
|
||||
URLConnection connection = url.openConnection();
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
|
||||
String currentChar;
|
||||
StringBuilder jsonStrBuilder = new StringBuilder();
|
||||
while((currentChar = bufferedReader.readLine()) != null)
|
||||
while ((currentChar = bufferedReader.readLine()) != null)
|
||||
{
|
||||
jsonStrBuilder.append(currentChar);
|
||||
}
|
||||
bufferedReader.close();
|
||||
return new JSONObject(jsonStrBuilder.toString());
|
||||
} catch (IOException e) {
|
||||
} catch (IOException e)
|
||||
{
|
||||
LOGGER.error("JSON Parsing Exception", e);
|
||||
}
|
||||
|
||||
@@ -128,7 +140,7 @@ public class Trivia
|
||||
|
||||
JSONArray results = jsonObject.getJSONArray("results");
|
||||
|
||||
for(Object currentQuestionGeneric : results)
|
||||
for (Object currentQuestionGeneric : results)
|
||||
{
|
||||
JSONObject questionJson = (JSONObject) currentQuestionGeneric;
|
||||
String question = StringEscapeUtils.unescapeHtml4(questionJson.getString("question"));
|
||||
@@ -137,7 +149,7 @@ public class Trivia
|
||||
List<String> incorrectAnswersList = new ArrayList<>();
|
||||
|
||||
JSONArray incorrectAnswers = questionJson.getJSONArray("incorrect_answers");
|
||||
for(Object incorrectAnswerGeneric : incorrectAnswers)
|
||||
for (Object incorrectAnswerGeneric : incorrectAnswers)
|
||||
{
|
||||
String incorrectAnswer = (String) incorrectAnswerGeneric;
|
||||
incorrectAnswersList.add(StringEscapeUtils.unescapeHtml4(incorrectAnswer));
|
||||
@@ -154,7 +166,7 @@ public class Trivia
|
||||
{
|
||||
List<TriviaCategory> categories = new ArrayList<>();
|
||||
JSONArray categoriesArray = jsonObject.getJSONArray("trivia_categories");
|
||||
for(Object categoryObject : categoriesArray)
|
||||
for (Object categoryObject : categoriesArray)
|
||||
{
|
||||
JSONObject categoryJson = (JSONObject) categoryObject;
|
||||
|
||||
@@ -172,14 +184,14 @@ public class Trivia
|
||||
User user = event.getUser();
|
||||
String channelId = event.getChannel().getId();
|
||||
|
||||
if(trackResponse(user, event.getChannel()))
|
||||
if (trackResponse(user, event.getChannel()))
|
||||
{
|
||||
LinkedList<TriviaScore> scores = channelAndScores.get(channelId);
|
||||
if(scores == null) scores = new LinkedList<>();
|
||||
if (scores == null) scores = new LinkedList<>();
|
||||
TriviaScore currentUserScore = null;
|
||||
for(TriviaScore score : scores)
|
||||
for (TriviaScore score : scores)
|
||||
{
|
||||
if(score.getUser().equals(user))
|
||||
if (score.getUser().equals(user))
|
||||
{
|
||||
currentUserScore = score;
|
||||
scores.remove(score);
|
||||
@@ -187,29 +199,31 @@ public class Trivia
|
||||
}
|
||||
}
|
||||
|
||||
if(currentUserScore == null)
|
||||
if (currentUserScore == null)
|
||||
{
|
||||
currentUserScore = new TriviaScore(user);
|
||||
}
|
||||
|
||||
if(answerType.equals(AnswerType.CORRECT))
|
||||
if (answerType.equals(AnswerType.CORRECT))
|
||||
{
|
||||
|
||||
event.reply(user.getAsMention() + " got it right! \uD83E\uDD73 (**+3**)").queue();
|
||||
currentUserScore.changeScore(3);
|
||||
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
event.reply("❌ " + user.getAsMention() + ", that's not the right answer! (**-1**)").queue();
|
||||
currentUserScore.changeScore(-1);
|
||||
}
|
||||
|
||||
scores.add(currentUserScore);
|
||||
channelAndScores.put(channelId, scores);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
event.reply("☹️ " + user.getAsMention() + ", you can't answer twice!")
|
||||
.queue(interaction ->
|
||||
Cache.getTaskScheduler().schedule(() ->
|
||||
interaction.deleteOriginal().queue(), 3, TimeUnit.SECONDS));
|
||||
Cache.getTaskScheduler().schedule(() ->
|
||||
interaction.deleteOriginal().queue(), 3, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,17 +234,18 @@ public class Trivia
|
||||
|
||||
List<String> responders = channelAndWhoResponded.get(channelId);
|
||||
|
||||
if(responders == null)
|
||||
if (responders == null)
|
||||
{
|
||||
responders = new ArrayList<>();
|
||||
}
|
||||
|
||||
if(responders.isEmpty() || !responders.contains(userId))
|
||||
if (responders.isEmpty() || !responders.contains(userId))
|
||||
{
|
||||
responders.add(userId);
|
||||
channelAndWhoResponded.put(channelId, responders);
|
||||
return true; // response was successfully tracked
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
return false; // response wasn't tracked because there already was an entry
|
||||
}
|
||||
}
|
||||
@@ -238,7 +253,7 @@ public class Trivia
|
||||
public static void handleMenuSelection(StringSelectInteractionEvent event)
|
||||
{
|
||||
// check if the user interacting is the same one who ran the command
|
||||
if(!(Cache.getDatabaseSource().isUserTrackedFor(event.getUser().getId(), event.getMessageId())))
|
||||
if (!(Cache.getDatabaseSource().isUserTrackedFor(event.getUser().getId(), event.getMessageId())))
|
||||
{
|
||||
event.reply("❌ You did not run this command!").setEphemeral(true).queue();
|
||||
return;
|
||||
@@ -263,7 +278,7 @@ public class Trivia
|
||||
Message message = event.getMessage();
|
||||
MessageChannel channel = message.getChannel();
|
||||
|
||||
if(Trivia.channelsRunningTrivia.contains(channel.getId()))
|
||||
if (Trivia.channelsRunningTrivia.contains(channel.getId()))
|
||||
{
|
||||
// todo nicer looking
|
||||
// todo: also what if the bot stops (database...?)
|
||||
@@ -271,7 +286,8 @@ public class Trivia
|
||||
Message err = event.reply("Trivia is already running here!").complete().retrieveOriginal().complete();
|
||||
Cache.getTaskScheduler().schedule(() -> err.delete().queue(), 10, TimeUnit.SECONDS);
|
||||
return;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
// todo nicer looking
|
||||
event.reply("Starting new Trivia session!").queue();
|
||||
}
|
||||
@@ -288,7 +304,8 @@ public class Trivia
|
||||
Trivia.channelsRunningTrivia.add(channel.getId());
|
||||
}
|
||||
|
||||
public enum AnswerType {
|
||||
public enum AnswerType
|
||||
{
|
||||
CORRECT, WRONG
|
||||
}
|
||||
|
||||
|
||||
@@ -25,15 +25,19 @@ import java.util.List;
|
||||
public class UrbanDictionary
|
||||
{
|
||||
|
||||
private UrbanDictionary() {
|
||||
private UrbanDictionary()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static LinkedList<String> getCommandLabels()
|
||||
{ return new LinkedList<>(Arrays.asList("urban", "urbandictionary", "ud")); }
|
||||
{
|
||||
return new LinkedList<>(Arrays.asList("urban", "urbandictionary", "ud"));
|
||||
}
|
||||
|
||||
|
||||
public static String getBaseUrl() {
|
||||
public static String getBaseUrl()
|
||||
{
|
||||
return "https://www.urbandictionary.com/define.php?term=";
|
||||
}
|
||||
|
||||
@@ -55,7 +59,8 @@ public class UrbanDictionary
|
||||
.withEmoji(Emoji.fromFormatted("\uD83D\uDDD1️"));
|
||||
}
|
||||
|
||||
public static String getNoArgsError() {
|
||||
public static String getNoArgsError()
|
||||
{
|
||||
return "\uD83D\uDE22 I need to know what to search for!";
|
||||
}
|
||||
|
||||
@@ -63,7 +68,7 @@ public class UrbanDictionary
|
||||
{
|
||||
term = term.replaceAll("[^\\w\\s]", ""); // only keep letters, numbers and spaces
|
||||
term = WordUtils.capitalizeFully(term); // Make Every Word Start With A Capital Letter
|
||||
if(forUrl) term = term.replaceAll("\\s+", "+"); // replace all whitespaces with + for the url
|
||||
if (forUrl) term = term.replaceAll("\\s+", "+"); // replace all whitespaces with + for the url
|
||||
if (term.length() > 64) term = term.substring(0, 64); // cut it to length to avoid abuse
|
||||
return term;
|
||||
}
|
||||
@@ -74,10 +79,10 @@ public class UrbanDictionary
|
||||
}
|
||||
|
||||
public static MessageEmbed buildEmbed(String term,
|
||||
String url,
|
||||
User author,
|
||||
UrbanSearch search,
|
||||
int page)
|
||||
String url,
|
||||
User author,
|
||||
UrbanSearch search,
|
||||
int page)
|
||||
{
|
||||
|
||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
@@ -87,7 +92,7 @@ public class UrbanDictionary
|
||||
embedBuilder.addField("\uD83D\uDCD6 Definition", search.getPlaintextMeanings().get(page), false);
|
||||
embedBuilder.addField("\uD83D\uDCAD Example", search.getPlaintextExamples().get(page), false);
|
||||
embedBuilder.addField("\uD83D\uDCCC Submission",
|
||||
"*Entry " + (page+1) + " | Sent by " + search.getContributorsNames().get(page) +
|
||||
"*Entry " + (page + 1) + " | Sent by " + search.getContributorsNames().get(page) +
|
||||
" on" + search.getSubmissionDates().get(page) + "*",
|
||||
false);
|
||||
|
||||
@@ -118,7 +123,8 @@ public class UrbanDictionary
|
||||
DatabaseSource database = Cache.getDatabaseSource();
|
||||
|
||||
// check if the user interacting is the same one who ran the command
|
||||
if (!(database.isUserTrackedFor(event.getUser().getId(), messageId))) {
|
||||
if (!(database.isUserTrackedFor(event.getUser().getId(), messageId)))
|
||||
{
|
||||
event.reply("❌ You did not run this command!").setEphemeral(true).queue();
|
||||
return;
|
||||
}
|
||||
@@ -140,9 +146,9 @@ public class UrbanDictionary
|
||||
serializedExamples, serializedContributors, serializedDates);
|
||||
|
||||
// move to new page
|
||||
if(changeType == ChangeType.NEXT)
|
||||
if (changeType == ChangeType.NEXT)
|
||||
page++;
|
||||
else if(changeType == ChangeType.PREVIOUS)
|
||||
else if (changeType == ChangeType.PREVIOUS)
|
||||
page--;
|
||||
|
||||
term = UrbanDictionary.sanitizeArgs(term, false);
|
||||
@@ -153,17 +159,19 @@ public class UrbanDictionary
|
||||
// get all attached components and check which ones need to be enabled or disabled
|
||||
List<ItemComponent> components = new ArrayList<>();
|
||||
|
||||
if(page > 0)
|
||||
if (page > 0)
|
||||
{
|
||||
components.add(UrbanDictionary.getPreviousPageButton().asEnabled());
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
components.add(UrbanDictionary.getPreviousPageButton().asDisabled());
|
||||
}
|
||||
|
||||
if(page + 1 == search.getPages())
|
||||
if (page + 1 == search.getPages())
|
||||
{
|
||||
components.add(UrbanDictionary.getNextPageButton().asDisabled());
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
components.add(UrbanDictionary.getNextPageButton().asEnabled());
|
||||
}
|
||||
|
||||
@@ -216,10 +224,10 @@ public class UrbanDictionary
|
||||
contributorsNames = new LinkedList<>();
|
||||
submissionDates = new LinkedList<>();
|
||||
|
||||
for(Element definition : definitions)
|
||||
for (Element definition : definitions)
|
||||
{
|
||||
Elements meaningSingleton = definition.getElementsByClass("meaning");
|
||||
if(meaningSingleton.isEmpty())
|
||||
if (meaningSingleton.isEmpty())
|
||||
{
|
||||
plaintextMeanings.add(" ");
|
||||
} else
|
||||
@@ -231,13 +239,13 @@ public class UrbanDictionary
|
||||
// this is used to fix eg. & being shown literally instead of being parsed
|
||||
text = StringEscapeUtils.unescapeHtml4(text);
|
||||
// discord only allows 1024 characters for embed fields
|
||||
if(text.length() > 1024) text = text.substring(0, 1020) + "...";
|
||||
if (text.length() > 1024) text = text.substring(0, 1020) + "...";
|
||||
plaintextMeanings.add(text);
|
||||
}
|
||||
|
||||
Elements exampleSingleton = definition.getElementsByClass("example");
|
||||
|
||||
if(exampleSingleton.isEmpty())
|
||||
if (exampleSingleton.isEmpty())
|
||||
{
|
||||
plaintextExamples.add(" ");
|
||||
} else
|
||||
@@ -249,12 +257,12 @@ public class UrbanDictionary
|
||||
// this is used to fix eg. & being shown literally instead of being parsed
|
||||
text = StringEscapeUtils.unescapeHtml4(text);
|
||||
// discord only allows 1024 characters for embed fields
|
||||
if(text.length() > 1024) text = text.substring(0, 1020) + "...";
|
||||
if (text.length() > 1024) text = text.substring(0, 1020) + "...";
|
||||
plaintextExamples.add(text);
|
||||
}
|
||||
|
||||
Elements contributorSingleton = definition.getElementsByClass("contributor");
|
||||
if(contributorSingleton.isEmpty())
|
||||
if (contributorSingleton.isEmpty())
|
||||
{
|
||||
contributorsNames.add("Unknown");
|
||||
} else
|
||||
@@ -282,39 +290,48 @@ public class UrbanDictionary
|
||||
pages = submissionDates.size();
|
||||
}
|
||||
|
||||
public List<String> getPlaintextMeanings() {
|
||||
public List<String> getPlaintextMeanings()
|
||||
{
|
||||
return this.plaintextMeanings;
|
||||
}
|
||||
|
||||
public List<String> getPlaintextExamples() {
|
||||
public List<String> getPlaintextExamples()
|
||||
{
|
||||
return this.plaintextExamples;
|
||||
}
|
||||
|
||||
public List<String> getContributorsNames() {
|
||||
public List<String> getContributorsNames()
|
||||
{
|
||||
return this.contributorsNames;
|
||||
}
|
||||
|
||||
public List<String> getSubmissionDates() {
|
||||
public List<String> getSubmissionDates()
|
||||
{
|
||||
return this.submissionDates;
|
||||
}
|
||||
|
||||
public String getSerializedMeanings() {
|
||||
public String getSerializedMeanings()
|
||||
{
|
||||
return serializedMeanings;
|
||||
}
|
||||
|
||||
public String getSerializedExamples() {
|
||||
public String getSerializedExamples()
|
||||
{
|
||||
return serializedExamples;
|
||||
}
|
||||
|
||||
public String getSerializedContributors() {
|
||||
public String getSerializedContributors()
|
||||
{
|
||||
return serializedContributors;
|
||||
}
|
||||
|
||||
public String getSerializedDates() {
|
||||
public String getSerializedDates()
|
||||
{
|
||||
return serializedDates;
|
||||
}
|
||||
|
||||
public int getPages() {
|
||||
public int getPages()
|
||||
{
|
||||
return pages;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,8 @@ import java.util.concurrent.TimeUnit;
|
||||
public class UserPunishment
|
||||
{
|
||||
|
||||
private UserPunishment() {
|
||||
private UserPunishment()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
@@ -42,24 +43,24 @@ public class UserPunishment
|
||||
User targetUser = null;
|
||||
|
||||
OptionMapping targetUserArg = event.getOption("target");
|
||||
if(targetUserArg != null)
|
||||
if (targetUserArg != null)
|
||||
{
|
||||
targetUser = targetUserArg.getAsUser();
|
||||
}
|
||||
|
||||
List<IMentionable> mentions = null;
|
||||
if(targetUser != null) mentions = new ArrayList<>(Collections.singletonList(targetUser));
|
||||
if (targetUser != null) mentions = new ArrayList<>(Collections.singletonList(targetUser));
|
||||
|
||||
String reason = null;
|
||||
OptionMapping reasonArg = event.getOption("reason");
|
||||
if(reasonArg != null)
|
||||
if (reasonArg != null)
|
||||
{
|
||||
reason = reasonArg.getAsString();
|
||||
}
|
||||
|
||||
String timeDiff = null;
|
||||
OptionMapping timeDiffArg = event.getOption("duration");
|
||||
if(timeDiffArg != null)
|
||||
if (timeDiffArg != null)
|
||||
{
|
||||
timeDiff = timeDiffArg.getAsString();
|
||||
}
|
||||
@@ -71,13 +72,13 @@ public class UserPunishment
|
||||
// we should probably rework the it so that it works better in both scenarios.
|
||||
String[] reasonSplit = null;
|
||||
// generate the arguments array by splitting the string
|
||||
if(reason != null) reasonSplit = reason.split("\\s+");
|
||||
if (reason != null) reasonSplit = reason.split("\\s+");
|
||||
//prepend timediff at index 0
|
||||
if(timeDiff != null) reasonSplit = ArrayUtils.insert(0, reasonSplit, timeDiff);
|
||||
if (timeDiff != null) reasonSplit = ArrayUtils.insert(0, reasonSplit, timeDiff);
|
||||
// in message-commands, the first arg would contain the user mention. since we have no one mentioned here,
|
||||
// because it's in its own argument, we just prepend an empty string. note that this makes relying on the
|
||||
// first argument BAD, because it is no longer ensured that it contains the user mention.
|
||||
if(timeDiff != null) reasonSplit = ArrayUtils.insert(0, reasonSplit, "");
|
||||
if (timeDiff != null) reasonSplit = ArrayUtils.insert(0, reasonSplit, "");
|
||||
|
||||
MessageResponse response = getResponse(event.getUser(),
|
||||
punishmentType,
|
||||
@@ -85,9 +86,9 @@ public class UserPunishment
|
||||
mentions,
|
||||
reasonSplit);
|
||||
|
||||
if(response.embed() != null)
|
||||
if (response.embed() != null)
|
||||
event.getHook().editOriginalEmbeds(response.embed()).queue();
|
||||
else if(response.content() != null)
|
||||
else if (response.content() != null)
|
||||
event.getHook().editOriginal(response.content()).queue();
|
||||
}
|
||||
|
||||
@@ -102,9 +103,9 @@ public class UserPunishment
|
||||
mentions,
|
||||
args);
|
||||
|
||||
if(response.embed() != null)
|
||||
if (response.embed() != null)
|
||||
event.getMessage().replyEmbeds(response.embed()).queue();
|
||||
else if(response.content() != null)
|
||||
else if (response.content() != null)
|
||||
event.getMessage().reply(response.content()).queue();
|
||||
}
|
||||
|
||||
@@ -117,13 +118,13 @@ public class UserPunishment
|
||||
String punishmentTypeName = punishmentType.name().toLowerCase();
|
||||
|
||||
|
||||
if(!(channel instanceof TextChannel))
|
||||
if (!(channel instanceof TextChannel))
|
||||
{
|
||||
// todo nicer looking with emojis
|
||||
return new MessageResponse("Sorry! I can't " + punishmentTypeName + " people in DMs.", null);
|
||||
}
|
||||
|
||||
if(mentions == null || mentions.isEmpty())
|
||||
if (mentions == null || mentions.isEmpty())
|
||||
{
|
||||
// todo nicer looking with emojis
|
||||
return new MessageResponse("You have to tell me who to " + punishmentTypeName + "!", null);
|
||||
@@ -132,7 +133,8 @@ public class UserPunishment
|
||||
String mentionedId = mentions.get(0).getId();
|
||||
User mentioned = null;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
mentioned = HidekoBot.getAPI().retrieveUserById(mentionedId).complete();
|
||||
} catch (RuntimeException ignored)
|
||||
{
|
||||
@@ -146,21 +148,21 @@ public class UserPunishment
|
||||
// some commands require an additional parameter before the reason, so in that case, we should start at 2.
|
||||
int startingPoint = punishmentType == PunishmentType.TIMEOUT ? 2 : 1;
|
||||
|
||||
if(args != null && args.length > startingPoint)
|
||||
if (args != null && args.length > startingPoint)
|
||||
{
|
||||
for(int i = startingPoint; i < args.length; i++)
|
||||
for (int i = startingPoint; i < args.length; i++)
|
||||
{
|
||||
String arg = args[i];
|
||||
reasonBuilder.append(arg);
|
||||
|
||||
if(i + 1 != arg.length())
|
||||
if (i + 1 != arg.length())
|
||||
reasonBuilder.append(" "); // separate args with a space except on last iteration.
|
||||
}
|
||||
|
||||
reason = reasonBuilder.toString();
|
||||
}
|
||||
|
||||
if(mentioned == null)
|
||||
if (mentioned == null)
|
||||
{
|
||||
// todo nicer looking with emojis
|
||||
return new MessageResponse("I can't " + punishmentTypeName + " that user!", null);
|
||||
@@ -172,12 +174,15 @@ public class UserPunishment
|
||||
AuditableRestAction<Void> punishmentAction = null;
|
||||
boolean impossible = false;
|
||||
|
||||
try {
|
||||
switch (punishmentType) {
|
||||
try
|
||||
{
|
||||
switch (punishmentType)
|
||||
{
|
||||
case BAN -> punishmentAction = guild.ban(mentioned, 0, TimeUnit.SECONDS);
|
||||
case KICK -> punishmentAction = guild.kick(mentioned);
|
||||
case TIMEOUT -> {
|
||||
if(args != null)
|
||||
case TIMEOUT ->
|
||||
{
|
||||
if (args != null)
|
||||
{
|
||||
String durationStr = args[1];
|
||||
duration = FormatUtil.parseDuration(durationStr);
|
||||
@@ -185,14 +190,14 @@ public class UserPunishment
|
||||
|
||||
boolean isDurationValid = true;
|
||||
|
||||
if(duration == null) isDurationValid = false;
|
||||
if (duration == null) isDurationValid = false;
|
||||
else
|
||||
{
|
||||
if(duration.compareTo(maxTimeoutDuration) > 0) isDurationValid = false;
|
||||
if(minTimeoutDuration.compareTo(duration) > 0) isDurationValid = false;
|
||||
if (duration.compareTo(maxTimeoutDuration) > 0) isDurationValid = false;
|
||||
if (minTimeoutDuration.compareTo(duration) > 0) isDurationValid = false;
|
||||
}
|
||||
|
||||
if(duration == null || !isDurationValid)
|
||||
if (duration == null || !isDurationValid)
|
||||
{
|
||||
// todo nicer looking with emojis
|
||||
return new MessageResponse("Sorry, but the specified duration is invalid!", null);
|
||||
@@ -201,24 +206,26 @@ public class UserPunishment
|
||||
punishmentAction = guild.timeoutFor(mentioned, duration);
|
||||
}
|
||||
}
|
||||
} catch (RuntimeException ignored) {
|
||||
} catch (RuntimeException ignored)
|
||||
{
|
||||
impossible = true;
|
||||
}
|
||||
|
||||
if(punishmentAction == null)
|
||||
if (punishmentAction == null)
|
||||
impossible = true;
|
||||
|
||||
if(impossible)
|
||||
if (impossible)
|
||||
{
|
||||
// todo nicer looking with emojis
|
||||
return new MessageResponse("Sorry, I couldn't " + punishmentTypeName + " " + mentioned.getAsMention() + "!",
|
||||
null);
|
||||
}
|
||||
|
||||
if(!reason.isEmpty() && !reasonBuilder.isEmpty())
|
||||
if (!reason.isEmpty() && !reasonBuilder.isEmpty())
|
||||
punishmentAction.reason("[" + author.getAsTag() + "] " + reason);
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
punishmentAction.complete();
|
||||
} catch (RuntimeException ignored)
|
||||
{
|
||||
@@ -235,10 +242,10 @@ public class UserPunishment
|
||||
|
||||
embedBuilder.addField("\uD83D\uDC64 User", mentioned.getAsMention(), false);
|
||||
embedBuilder.addField("✂️ By", author.getAsMention(), false);
|
||||
if(duration != null)
|
||||
if (duration != null)
|
||||
embedBuilder.addField("⏱️ Duration", FormatUtil.getNiceDuration(duration), false);
|
||||
|
||||
if(reason.isEmpty())
|
||||
if (reason.isEmpty())
|
||||
reason = "*No reason specified*";
|
||||
|
||||
embedBuilder.addField("\uD83D\uDCD6 Reason", reason, false);
|
||||
@@ -248,7 +255,8 @@ public class UserPunishment
|
||||
|
||||
}
|
||||
|
||||
public enum PunishmentType {
|
||||
public enum PunishmentType
|
||||
{
|
||||
KICK("kicked"),
|
||||
BAN("banned"),
|
||||
TIMEOUT("timed out"),
|
||||
|
||||
@@ -13,23 +13,25 @@ import java.util.List;
|
||||
public class ProfileImageCommandCompleter extends SlashArgumentsCompleterImpl
|
||||
{
|
||||
|
||||
public ProfileImageCommandCompleter(SlashCommand parentCommand) {
|
||||
public ProfileImageCommandCompleter(SlashCommand parentCommand)
|
||||
{
|
||||
super(parentCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCompletion(@NotNull CommandAutoCompleteInteractionEvent event) {
|
||||
if(event.getFocusedOption().getName().equals("size"))
|
||||
public void runCompletion(@NotNull CommandAutoCompleteInteractionEvent event)
|
||||
{
|
||||
if (event.getFocusedOption().getName().equals("size"))
|
||||
{
|
||||
|
||||
List<Command.Choice> options = new ArrayList<>();
|
||||
|
||||
for(int res : Cache.getSupportedAvatarResolutions())
|
||||
for (int res : Cache.getSupportedAvatarResolutions())
|
||||
{
|
||||
String resString = String.valueOf(res);
|
||||
String userInput = event.getFocusedOption().getValue();
|
||||
|
||||
if(resString.startsWith(userInput))
|
||||
if (resString.startsWith(userInput))
|
||||
options.add(new Command.Choice(resString, res));
|
||||
}
|
||||
|
||||
|
||||
@@ -17,43 +17,49 @@ public class AliasCommand implements MessageCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public LinkedList<String> getCommandLabels() {
|
||||
public LinkedList<String> getCommandLabels()
|
||||
{
|
||||
return new LinkedList<>(Arrays.asList("alias", "aliases"));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<Permission> getPermissions() {
|
||||
public List<Permission> getPermissions()
|
||||
{
|
||||
return null; // anyone can use it
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passRawArgs() {
|
||||
public boolean passRawArgs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandCategory getCategory() {
|
||||
public CommandCategory getCategory()
|
||||
{
|
||||
return CommandCategory.TOOLS;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDescription() {
|
||||
public String getDescription()
|
||||
{
|
||||
return "See other command aliases.";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUsage() {
|
||||
public String getUsage()
|
||||
{
|
||||
return "<command>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(MessageReceivedEvent event, String label, String[] args)
|
||||
{
|
||||
if(args.length == 0)
|
||||
if (args.length == 0)
|
||||
{
|
||||
event.getMessage().reply("\uD83D\uDE20 Hey, you have to specify a command!").queue();
|
||||
return;
|
||||
@@ -61,14 +67,14 @@ public class AliasCommand implements MessageCommand
|
||||
|
||||
String commandLabel = args[0].toLowerCase();
|
||||
MessageCommand command = Cache.getMessageCommandListener().getRegisteredCommand(commandLabel);
|
||||
if(command == null)
|
||||
if (command == null)
|
||||
{
|
||||
event.getMessage().reply("Unrecognized command: `" + commandLabel + "`!").queue(); // todo prettier
|
||||
return;
|
||||
}
|
||||
|
||||
String aliases = Alias.generateNiceAliases(command);
|
||||
aliases = "Aliases for **" + command.getCommandLabels().get(0) + "**: " + aliases;
|
||||
aliases = "Aliases for **" + command.getCommandLabels().get(0) + "**: " + aliases;
|
||||
|
||||
event.getMessage()
|
||||
.reply(aliases)
|
||||
|
||||
@@ -16,40 +16,46 @@ import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class AvatarCommand implements MessageCommand
|
||||
public class AvatarCommand implements MessageCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public LinkedList<String> getCommandLabels() {
|
||||
public LinkedList<String> getCommandLabels()
|
||||
{
|
||||
return new LinkedList<>(Collections.singletonList("avatar"));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<Permission> getPermissions() {
|
||||
public List<Permission> getPermissions()
|
||||
{
|
||||
return null; // anyone can use it
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passRawArgs() {
|
||||
public boolean passRawArgs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDescription() {
|
||||
public String getDescription()
|
||||
{
|
||||
return "Get someone's avatar, or your own. You can additionally specify a resolution.";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUsage() {
|
||||
public String getUsage()
|
||||
{
|
||||
return "[mentioned user] [resolution]";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandCategory getCategory() {
|
||||
public CommandCategory getCategory()
|
||||
{
|
||||
return CommandCategory.TOOLS;
|
||||
}
|
||||
|
||||
@@ -63,23 +69,26 @@ public class AvatarCommand implements MessageCommand
|
||||
// (mentions are handled differently by a specific method)
|
||||
boolean resFound = false;
|
||||
|
||||
for (String arg : args) {
|
||||
try {
|
||||
for (String arg : args)
|
||||
{
|
||||
try
|
||||
{
|
||||
int givenRes = Integer.parseInt(arg);
|
||||
resolution = ProfileImage.parseResolution(givenRes);
|
||||
resFound = true;
|
||||
break;
|
||||
} catch (NumberFormatException ignored) {
|
||||
} catch (NumberFormatException ignored)
|
||||
{
|
||||
// ignored because we're running a check after this block
|
||||
}
|
||||
}
|
||||
|
||||
// fallback in case we didn't find any specified resolution
|
||||
if(!resFound) resolution = ProfileImage.parseResolution(512);
|
||||
if (!resFound) resolution = ProfileImage.parseResolution(512);
|
||||
|
||||
// check if someone is mentioned
|
||||
Mentions mentions = event.getMessage().getMentions();
|
||||
if(mentions.getMentions().isEmpty())
|
||||
if (mentions.getMentions().isEmpty())
|
||||
{
|
||||
user = event.getAuthor();
|
||||
} else
|
||||
@@ -89,14 +98,14 @@ public class AvatarCommand implements MessageCommand
|
||||
}
|
||||
|
||||
// in case of issues, fallback to the sender
|
||||
if(user == null) user = event.getAuthor();
|
||||
if (user == null) user = event.getAuthor();
|
||||
|
||||
// send a response
|
||||
MessageResponse response = ProfileImage.buildResponse(resolution, user, ProfileImage.ImageType.AVATAR);
|
||||
if(response.content() != null)
|
||||
if (response.content() != null)
|
||||
{
|
||||
event.getMessage().reply(response.content()).queue();
|
||||
} else if(response.embed() != null)
|
||||
} else if (response.embed() != null)
|
||||
{
|
||||
event.getMessage().replyEmbeds(response.embed()).queue();
|
||||
}
|
||||
|
||||
@@ -17,36 +17,42 @@ public class BanCommand implements MessageCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public LinkedList<String> getCommandLabels() {
|
||||
public LinkedList<String> getCommandLabels()
|
||||
{
|
||||
return new LinkedList<>(Collections.singletonList("ban"));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<Permission> getPermissions() {
|
||||
public List<Permission> getPermissions()
|
||||
{
|
||||
return new ArrayList<Permission>(Collections.singletonList(Permission.BAN_MEMBERS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passRawArgs() {
|
||||
public boolean passRawArgs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandCategory getCategory() {
|
||||
public CommandCategory getCategory()
|
||||
{
|
||||
return CommandCategory.MODERATION;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDescription() {
|
||||
public String getDescription()
|
||||
{
|
||||
return "Ban the mentioned user.";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUsage() {
|
||||
public String getUsage()
|
||||
{
|
||||
return "<mentioned user> [reason]";
|
||||
}
|
||||
|
||||
|
||||
@@ -20,36 +20,42 @@ public class BannerCommand implements MessageCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public LinkedList<String> getCommandLabels() {
|
||||
public LinkedList<String> getCommandLabels()
|
||||
{
|
||||
return new LinkedList<>(Collections.singletonList("banner"));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<Permission> getPermissions() {
|
||||
public List<Permission> getPermissions()
|
||||
{
|
||||
return null; // anyone can use it
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passRawArgs() {
|
||||
public boolean passRawArgs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDescription() {
|
||||
public String getDescription()
|
||||
{
|
||||
return "Get someone's profile banner, or your own.";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUsage() {
|
||||
public String getUsage()
|
||||
{
|
||||
return "[mentioned user] [resolution]";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandCategory getCategory() {
|
||||
public CommandCategory getCategory()
|
||||
{
|
||||
return CommandCategory.TOOLS;
|
||||
}
|
||||
|
||||
@@ -63,23 +69,26 @@ public class BannerCommand implements MessageCommand
|
||||
// (mentions are handled differently by a specific method)
|
||||
boolean resFound = false;
|
||||
|
||||
for (String arg : args) {
|
||||
try {
|
||||
for (String arg : args)
|
||||
{
|
||||
try
|
||||
{
|
||||
int givenRes = Integer.parseInt(arg);
|
||||
resolution = ProfileImage.parseResolution(givenRes);
|
||||
resFound = true;
|
||||
break;
|
||||
} catch (NumberFormatException ignored) {
|
||||
} catch (NumberFormatException ignored)
|
||||
{
|
||||
// ignored because we're running a check after this block
|
||||
}
|
||||
}
|
||||
|
||||
// fallback in case we didn't find any specified resolution
|
||||
if(!resFound) resolution = ProfileImage.parseResolution(512);
|
||||
if (!resFound) resolution = ProfileImage.parseResolution(512);
|
||||
|
||||
// check if someone is mentioned
|
||||
Mentions mentions = event.getMessage().getMentions();
|
||||
if(mentions.getMentions().isEmpty())
|
||||
if (mentions.getMentions().isEmpty())
|
||||
{
|
||||
user = event.getAuthor();
|
||||
} else
|
||||
@@ -89,14 +98,14 @@ public class BannerCommand implements MessageCommand
|
||||
}
|
||||
|
||||
// in case of issues, fallback to the sender
|
||||
if(user == null) user = event.getAuthor();
|
||||
if (user == null) user = event.getAuthor();
|
||||
|
||||
// send a response
|
||||
MessageResponse response = ProfileImage.buildResponse(resolution, user, ProfileImage.ImageType.BANNER);
|
||||
if(response.content() != null)
|
||||
if (response.content() != null)
|
||||
{
|
||||
event.getMessage().reply(response.content()).queue();
|
||||
} else if(response.embed() != null)
|
||||
} else if (response.embed() != null)
|
||||
{
|
||||
event.getMessage().replyEmbeds(response.embed()).queue();
|
||||
}
|
||||
|
||||
@@ -18,46 +18,54 @@ public class BotInfoCommand implements MessageCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public LinkedList<String> getCommandLabels() {
|
||||
public LinkedList<String> getCommandLabels()
|
||||
{
|
||||
return new LinkedList<>(Arrays.asList("botinfo", "info"));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<Permission> getPermissions() {
|
||||
public List<Permission> getPermissions()
|
||||
{
|
||||
return null; // anyone can use it
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passRawArgs() {
|
||||
public boolean passRawArgs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDescription() {
|
||||
public String getDescription()
|
||||
{
|
||||
return "Get general info about the bot.";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUsage() {
|
||||
public String getUsage()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandCategory getCategory() {
|
||||
public CommandCategory getCategory()
|
||||
{
|
||||
return CommandCategory.TOOLS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(MessageReceivedEvent event, String label, String[] args) {
|
||||
public void runCommand(MessageReceivedEvent event, String label, String[] args)
|
||||
{
|
||||
|
||||
// get a list of message commands
|
||||
LinkedList<MessageCommand> messageCommands = Cache.getMessageCommandListener().getRegisteredCommands();
|
||||
LinkedList<String> commandNames = new LinkedList<>();
|
||||
for (MessageCommand command : messageCommands) {
|
||||
for (MessageCommand command : messageCommands)
|
||||
{
|
||||
commandNames.add(command.getCommandLabels().get(0));
|
||||
}
|
||||
|
||||
|
||||
@@ -19,33 +19,41 @@ public class ClearCommand implements MessageCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public LinkedList<String> getCommandLabels() {
|
||||
public LinkedList<String> getCommandLabels()
|
||||
{
|
||||
return new LinkedList<>(Collections.singletonList(ClearChat.getLabel()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Permission> getPermissions() { return Collections.singletonList(ClearChat.getPermission()); }
|
||||
public List<Permission> getPermissions()
|
||||
{
|
||||
return Collections.singletonList(ClearChat.getPermission());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passRawArgs() {
|
||||
public boolean passRawArgs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandCategory getCategory() {
|
||||
public CommandCategory getCategory()
|
||||
{
|
||||
return CommandCategory.MODERATION;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDescription() {
|
||||
public String getDescription()
|
||||
{
|
||||
return "Clear the current channel's chat history.";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUsage() {
|
||||
public String getUsage()
|
||||
{
|
||||
return "[amount]";
|
||||
}
|
||||
|
||||
@@ -54,7 +62,8 @@ public class ClearCommand implements MessageCommand
|
||||
{
|
||||
// check if user is trying to run command in dms.
|
||||
String error = ClearChat.checkDMs(event.getChannel());
|
||||
if (error != null) {
|
||||
if (error != null)
|
||||
{
|
||||
event.getMessage().reply(error).queue();
|
||||
return;
|
||||
}
|
||||
@@ -64,7 +73,8 @@ public class ClearCommand implements MessageCommand
|
||||
if (args.length == 0) toDeleteAmount = 1;
|
||||
else
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
toDeleteAmount = Integer.parseInt(args[0]);
|
||||
} catch (NumberFormatException e)
|
||||
{
|
||||
@@ -73,10 +83,11 @@ public class ClearCommand implements MessageCommand
|
||||
}
|
||||
|
||||
// cap the amount to avoid abuse.
|
||||
if(toDeleteAmount > ClearChat.getMaxAmount()) toDeleteAmount = 0;
|
||||
if (toDeleteAmount > ClearChat.getMaxAmount()) toDeleteAmount = 0;
|
||||
|
||||
error = ClearChat.checkDeleteAmount(toDeleteAmount);
|
||||
if (error != null) {
|
||||
if (error != null)
|
||||
{
|
||||
event.getMessage().reply(error).queue();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -16,41 +16,48 @@ public class CoinFlipCommand implements MessageCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public LinkedList<String> getCommandLabels() {
|
||||
public LinkedList<String> getCommandLabels()
|
||||
{
|
||||
return new LinkedList<>(Arrays.asList("coinflip", "flip", "flipcoin"));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<Permission> getPermissions() {
|
||||
public List<Permission> getPermissions()
|
||||
{
|
||||
return null; // null because it can be used anywhere
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passRawArgs() {
|
||||
public boolean passRawArgs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDescription() {
|
||||
public String getDescription()
|
||||
{
|
||||
return "Flip a coin.";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUsage() {
|
||||
public String getUsage()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandCategory getCategory() {
|
||||
public CommandCategory getCategory()
|
||||
{
|
||||
return CommandCategory.FUN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(MessageReceivedEvent event, String label, String[] args) {
|
||||
public void runCommand(MessageReceivedEvent event, String label, String[] args)
|
||||
{
|
||||
|
||||
// perform coin flip
|
||||
event.getMessage().reply(CoinFlip.genRandom())
|
||||
@@ -59,6 +66,7 @@ public class CoinFlipCommand implements MessageCommand
|
||||
{
|
||||
// set the command as expiring and restrict it to the user who ran it
|
||||
CoinFlip.trackAndRestrict(message, event.getAuthor());
|
||||
}, (error) -> {});
|
||||
}, (error) -> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,18 +16,21 @@ import java.util.List;
|
||||
public class DiceRollCommand implements MessageCommand
|
||||
{
|
||||
@Override
|
||||
public LinkedList<String> getCommandLabels() {
|
||||
public LinkedList<String> getCommandLabels()
|
||||
{
|
||||
return new LinkedList<>(Arrays.asList("diceroll", "droll", "roll"));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<Permission> getPermissions() {
|
||||
public List<Permission> getPermissions()
|
||||
{
|
||||
return null; // anyone can use it
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passRawArgs() {
|
||||
public boolean passRawArgs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -47,13 +50,15 @@ public class DiceRollCommand implements MessageCommand
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUsage() {
|
||||
public String getUsage()
|
||||
{
|
||||
return "[dice size] [rolls]";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandCategory getCategory() {
|
||||
public CommandCategory getCategory()
|
||||
{
|
||||
return CommandCategory.FUN;
|
||||
}
|
||||
|
||||
@@ -63,10 +68,10 @@ public class DiceRollCommand implements MessageCommand
|
||||
|
||||
MessageResponse response = DiceRoll.buildResponse(event.getAuthor(), args);
|
||||
|
||||
if(response.content() != null)
|
||||
if (response.content() != null)
|
||||
{
|
||||
event.getMessage().reply(response.content()).queue();
|
||||
} else if(response.embed() != null)
|
||||
} else if (response.embed() != null)
|
||||
{
|
||||
event.getMessage().replyEmbeds(response.embed()).queue();
|
||||
}
|
||||
|
||||
@@ -15,33 +15,41 @@ public class HelloCommand implements MessageCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public LinkedList<String> getCommandLabels() {
|
||||
public LinkedList<String> getCommandLabels()
|
||||
{
|
||||
return new LinkedList<>(Arrays.asList("hi", "hello", "heya"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Permission> getPermissions() { return null; }
|
||||
public List<Permission> getPermissions()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passRawArgs() {
|
||||
public boolean passRawArgs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDescription() {
|
||||
public String getDescription()
|
||||
{
|
||||
return "Get pinged by the bot.";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUsage() {
|
||||
public String getUsage()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandCategory getCategory() {
|
||||
public CommandCategory getCategory()
|
||||
{
|
||||
return CommandCategory.FUN;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,34 +18,42 @@ public class HelpCommand implements MessageCommand
|
||||
|
||||
|
||||
@Override
|
||||
public LinkedList<String> getCommandLabels() {
|
||||
public LinkedList<String> getCommandLabels()
|
||||
{
|
||||
return new LinkedList<>(Collections.singletonList("help"));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<Permission> getPermissions() { return null; }
|
||||
public List<Permission> getPermissions()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passRawArgs() {
|
||||
public boolean passRawArgs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDescription() {
|
||||
public String getDescription()
|
||||
{
|
||||
return "Get general help on the bot. Specify a command if you want specific help about that command.";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUsage() {
|
||||
public String getUsage()
|
||||
{
|
||||
return "[command]";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandCategory getCategory() {
|
||||
public CommandCategory getCategory()
|
||||
{
|
||||
return CommandCategory.TOOLS;
|
||||
}
|
||||
|
||||
@@ -54,14 +62,14 @@ public class HelpCommand implements MessageCommand
|
||||
{
|
||||
LinkedHashMap<CommandCategory, LinkedList<MessageCommand>> commandCategories = new LinkedHashMap<>();
|
||||
|
||||
if(args.length == 0)
|
||||
if (args.length == 0)
|
||||
{
|
||||
for(CommandCategory category : CommandCategory.values())
|
||||
for (CommandCategory category : CommandCategory.values())
|
||||
{
|
||||
LinkedList<MessageCommand> commandsOfThisCategory = new LinkedList<>();
|
||||
for (MessageCommand command : Cache.getMessageCommandListener().getRegisteredCommands())
|
||||
{
|
||||
if(command.getCategory().equals(category))
|
||||
if (command.getCategory().equals(category))
|
||||
{
|
||||
commandsOfThisCategory.add(command);
|
||||
}
|
||||
@@ -79,18 +87,18 @@ public class HelpCommand implements MessageCommand
|
||||
"\nYou will find a list of commands organized in categories below.",
|
||||
false);
|
||||
|
||||
for(Map.Entry<CommandCategory, LinkedList<MessageCommand>> entry : commandCategories.entrySet())
|
||||
for (Map.Entry<CommandCategory, LinkedList<MessageCommand>> entry : commandCategories.entrySet())
|
||||
{
|
||||
StringBuilder commandsList = new StringBuilder();
|
||||
CommandCategory category = entry.getKey();
|
||||
LinkedList<MessageCommand> commandsOfThisCategory = entry.getValue();
|
||||
|
||||
for(int pos = 0; pos < commandsOfThisCategory.size(); pos++)
|
||||
for (int pos = 0; pos < commandsOfThisCategory.size(); pos++)
|
||||
{
|
||||
MessageCommand command = commandsOfThisCategory.get(pos);
|
||||
commandsList.append("`").append(command.getCommandLabels().get(0)).append("`");
|
||||
|
||||
if(pos + 1 != commandsOfThisCategory.size())
|
||||
if (pos + 1 != commandsOfThisCategory.size())
|
||||
commandsList.append(", "); // separate with comma except on last run
|
||||
}
|
||||
|
||||
@@ -102,11 +110,12 @@ public class HelpCommand implements MessageCommand
|
||||
}
|
||||
|
||||
event.getMessage().replyEmbeds(embedBuilder.build()).queue();
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
|
||||
String commandLabel = args[0].toLowerCase();
|
||||
MessageCommand command = Cache.getMessageCommandListener().getRegisteredCommand(commandLabel);
|
||||
if(command == null)
|
||||
if (command == null)
|
||||
{
|
||||
event.getMessage().reply("Unrecognized command: `" + commandLabel + "`!").queue(); // todo prettier
|
||||
return;
|
||||
@@ -115,23 +124,24 @@ public class HelpCommand implements MessageCommand
|
||||
commandLabel = command.getCommandLabels().get(0);
|
||||
String usage = "`" + Cache.getBotPrefix() + " " + commandLabel;
|
||||
String internalUsage = command.getUsage();
|
||||
if(internalUsage != null) usage += " " + internalUsage;
|
||||
if (internalUsage != null) usage += " " + internalUsage;
|
||||
usage += "`";
|
||||
|
||||
String aliases = Alias.generateNiceAliases(command);
|
||||
|
||||
List<Permission> permissions = command.getPermissions();
|
||||
StringBuilder permissionsStringBuilder = new StringBuilder();
|
||||
if(permissions == null)
|
||||
if (permissions == null)
|
||||
{
|
||||
permissionsStringBuilder = new StringBuilder("Available to everyone");
|
||||
} else {
|
||||
for(int i = 0; i < permissions.size(); i++)
|
||||
} else
|
||||
{
|
||||
for (int i = 0; i < permissions.size(); i++)
|
||||
{
|
||||
Permission permission = permissions.get(i);
|
||||
permissionsStringBuilder.append("**").append(permission.getName()).append("**");
|
||||
|
||||
if(i + 1 != permissions.size())
|
||||
if (i + 1 != permissions.size())
|
||||
permissionsStringBuilder.append(", "); // separate with comma expect on last iteration
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,36 +19,42 @@ public class InviteCommand implements MessageCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public LinkedList<String> getCommandLabels() {
|
||||
public LinkedList<String> getCommandLabels()
|
||||
{
|
||||
return new LinkedList<>(Collections.singletonList("invite"));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<Permission> getPermissions() {
|
||||
public List<Permission> getPermissions()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passRawArgs() {
|
||||
public boolean passRawArgs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDescription() {
|
||||
public String getDescription()
|
||||
{
|
||||
return "Get the bot's invite link.";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUsage() {
|
||||
public String getUsage()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandCategory getCategory() {
|
||||
public CommandCategory getCategory()
|
||||
{
|
||||
return CommandCategory.MODERATION;
|
||||
}
|
||||
|
||||
@@ -61,7 +67,7 @@ public class InviteCommand implements MessageCommand
|
||||
Button inviteButton = Invite.getInviteButton();
|
||||
|
||||
// if this is a guild, don't spam the invite in public but DM it
|
||||
if(event.getChannelType().isGuild())
|
||||
if (event.getChannelType().isGuild())
|
||||
{
|
||||
event.getAuthor().openPrivateChannel().queue(privateChannel ->
|
||||
{
|
||||
@@ -70,7 +76,8 @@ public class InviteCommand implements MessageCommand
|
||||
.queue();
|
||||
event.getMessage().addReaction(Emoji.fromUnicode("✅")).queue();
|
||||
}, error -> event.getMessage().addReaction(Emoji.fromUnicode("❌")).queue());
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
event.getMessage()
|
||||
.replyEmbeds(inviteEmbed)
|
||||
.addActionRow(inviteButton)
|
||||
|
||||
@@ -17,36 +17,42 @@ public class KickCommand implements MessageCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public LinkedList<String> getCommandLabels() {
|
||||
public LinkedList<String> getCommandLabels()
|
||||
{
|
||||
return new LinkedList<>(Collections.singletonList("kick"));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<Permission> getPermissions() {
|
||||
public List<Permission> getPermissions()
|
||||
{
|
||||
return new ArrayList<Permission>(Collections.singletonList(Permission.KICK_MEMBERS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passRawArgs() {
|
||||
public boolean passRawArgs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandCategory getCategory() {
|
||||
public CommandCategory getCategory()
|
||||
{
|
||||
return CommandCategory.MODERATION;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDescription() {
|
||||
public String getDescription()
|
||||
{
|
||||
return "Kick the mentioned user from the guild.";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUsage() {
|
||||
public String getUsage()
|
||||
{
|
||||
return "<mentioned user> [reason]";
|
||||
}
|
||||
|
||||
|
||||
@@ -29,30 +29,35 @@ public class LoveCalculatorCommand implements MessageCommand
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<Permission> getPermissions() {
|
||||
public List<Permission> getPermissions()
|
||||
{
|
||||
return null; //anyone can use it
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passRawArgs() {
|
||||
public boolean passRawArgs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDescription() {
|
||||
public String getDescription()
|
||||
{
|
||||
return "Calculate how much two people love each other. You can mention two people or just one.";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUsage() {
|
||||
public String getUsage()
|
||||
{
|
||||
return "<person 1> [person 2]";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandCategory getCategory() {
|
||||
public CommandCategory getCategory()
|
||||
{
|
||||
return CommandCategory.FUN;
|
||||
}
|
||||
|
||||
@@ -64,7 +69,7 @@ public class LoveCalculatorCommand implements MessageCommand
|
||||
List<IMentionable> mentions = mentionsObj.getMentions();
|
||||
|
||||
|
||||
if(args.length == 0 || mentions.isEmpty())
|
||||
if (args.length == 0 || mentions.isEmpty())
|
||||
{
|
||||
event.getMessage()
|
||||
.reply("\uD83D\uDE22 I need to know who to check! Please mention them.")
|
||||
@@ -77,10 +82,11 @@ public class LoveCalculatorCommand implements MessageCommand
|
||||
String mentionedUserId = mentions.get(0).getId();
|
||||
user1 = HidekoBot.getAPI().retrieveUserById(mentionedUserId).complete();
|
||||
|
||||
if(mentions.size() == 1)
|
||||
if (mentions.size() == 1)
|
||||
{
|
||||
user2 = event.getAuthor();
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
mentionedUserId = mentions.get(1).getId();
|
||||
user2 = HidekoBot.getAPI().retrieveUserById(mentionedUserId).complete();
|
||||
}
|
||||
|
||||
@@ -15,58 +15,64 @@ public class MagicBallCommand implements MessageCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public LinkedList<String> getCommandLabels() {
|
||||
public LinkedList<String> getCommandLabels()
|
||||
{
|
||||
return MagicBall.getLabels();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<Permission> getPermissions() {
|
||||
public List<Permission> getPermissions()
|
||||
{
|
||||
return null; // anyone can use it
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passRawArgs() {
|
||||
public boolean passRawArgs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDescription() {
|
||||
public String getDescription()
|
||||
{
|
||||
return "Ask a question to the Magic Ball.";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUsage() {
|
||||
public String getUsage()
|
||||
{
|
||||
return "<question>";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandCategory getCategory() {
|
||||
public CommandCategory getCategory()
|
||||
{
|
||||
return CommandCategory.FUN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(MessageReceivedEvent event, String label, String[] args)
|
||||
{
|
||||
if(args.length == 0)
|
||||
if (args.length == 0)
|
||||
{
|
||||
event.getMessage().reply("You need to specify a question!").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder questionBuilder = new StringBuilder();
|
||||
for(int i = 0; i < args.length; i++)
|
||||
for (int i = 0; i < args.length; i++)
|
||||
{
|
||||
String arg = args[i];
|
||||
questionBuilder.append(arg);
|
||||
if(i + 1 != args.length) // don't add a separator on the last iteration
|
||||
if (i + 1 != args.length) // don't add a separator on the last iteration
|
||||
questionBuilder.append(" ");
|
||||
}
|
||||
|
||||
String question = questionBuilder.toString();
|
||||
String question = questionBuilder.toString();
|
||||
|
||||
|
||||
event.getChannel().sendMessageEmbeds(MagicBall.generateEmbed(question, event.getAuthor())).queue();
|
||||
|
||||
@@ -18,34 +18,42 @@ public class SayCommand implements MessageCommand
|
||||
|
||||
|
||||
@Override
|
||||
public LinkedList<String> getCommandLabels() {
|
||||
public LinkedList<String> getCommandLabels()
|
||||
{
|
||||
return new LinkedList<>(Collections.singletonList("say"));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<Permission> getPermissions() { return Collections.singletonList(Say.getPermission()); }
|
||||
public List<Permission> getPermissions()
|
||||
{
|
||||
return Collections.singletonList(Say.getPermission());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passRawArgs() {
|
||||
public boolean passRawArgs()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDescription() {
|
||||
public String getDescription()
|
||||
{
|
||||
return "Make the bot say something for you.";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUsage() {
|
||||
public String getUsage()
|
||||
{
|
||||
return "<text>";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandCategory getCategory() {
|
||||
public CommandCategory getCategory()
|
||||
{
|
||||
return CommandCategory.TOOLS;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,36 +17,42 @@ public class TimeoutCommand implements MessageCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public LinkedList<String> getCommandLabels() {
|
||||
public LinkedList<String> getCommandLabels()
|
||||
{
|
||||
return new LinkedList<>(Collections.singletonList("timeout"));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<Permission> getPermissions() {
|
||||
public List<Permission> getPermissions()
|
||||
{
|
||||
return new ArrayList<Permission>(Collections.singletonList(Permission.MODERATE_MEMBERS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passRawArgs() {
|
||||
public boolean passRawArgs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandCategory getCategory() {
|
||||
public CommandCategory getCategory()
|
||||
{
|
||||
return CommandCategory.MODERATION;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDescription() {
|
||||
public String getDescription()
|
||||
{
|
||||
return "Timeout the mentioned user.";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUsage() {
|
||||
public String getUsage()
|
||||
{
|
||||
return "<mentioned user> <duration> [reason]";
|
||||
}
|
||||
|
||||
|
||||
@@ -23,36 +23,42 @@ public class TriviaCommand implements MessageCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public LinkedList<String> getCommandLabels() {
|
||||
public LinkedList<String> getCommandLabels()
|
||||
{
|
||||
return new LinkedList<>(Collections.singletonList("trivia"));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<Permission> getPermissions() {
|
||||
public List<Permission> getPermissions()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passRawArgs() {
|
||||
public boolean passRawArgs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandCategory getCategory() {
|
||||
public CommandCategory getCategory()
|
||||
{
|
||||
return CommandCategory.FUN;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDescription() {
|
||||
public String getDescription()
|
||||
{
|
||||
return "Start a Trivia session and play with others!";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUsage() {
|
||||
public String getUsage()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -61,13 +67,13 @@ public class TriviaCommand implements MessageCommand
|
||||
{
|
||||
MessageChannel channel = event.getChannel();
|
||||
|
||||
if(!(channel instanceof TextChannel))
|
||||
if (!(channel instanceof TextChannel))
|
||||
{
|
||||
channel.sendMessage(Trivia.getNoDMsError()).queue();
|
||||
return;
|
||||
}
|
||||
|
||||
if(Trivia.channelsRunningTrivia.contains(channel.getId()))
|
||||
if (Trivia.channelsRunningTrivia.contains(channel.getId()))
|
||||
{
|
||||
// todo: also what if the bot stops (database...?)
|
||||
// todo: also what if the message is already deleted
|
||||
@@ -80,11 +86,12 @@ public class TriviaCommand implements MessageCommand
|
||||
|
||||
Message recvMessage = event.getMessage();
|
||||
MessageCreateAction responseAction = null;
|
||||
if(response.content() != null) responseAction = recvMessage.reply(response.content());
|
||||
else if(response.embed() != null) responseAction = recvMessage.replyEmbeds(response.embed());
|
||||
if (response.content() != null) responseAction = recvMessage.reply(response.content());
|
||||
else if (response.embed() != null) responseAction = recvMessage.replyEmbeds(response.embed());
|
||||
|
||||
if(responseAction != null) {
|
||||
if(response.components() != null) responseAction = responseAction.addActionRow(response.components());
|
||||
if (responseAction != null)
|
||||
{
|
||||
if (response.components() != null) responseAction = responseAction.addActionRow(response.components());
|
||||
|
||||
responseAction.queue(message -> {
|
||||
Cache.getDatabaseSource().trackRanCommandReply(message, event.getAuthor());
|
||||
|
||||
@@ -21,36 +21,42 @@ public class UrbanDictionaryCommand implements MessageCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public LinkedList<String> getCommandLabels() {
|
||||
public LinkedList<String> getCommandLabels()
|
||||
{
|
||||
return UrbanDictionary.getCommandLabels();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<Permission> getPermissions() {
|
||||
public List<Permission> getPermissions()
|
||||
{
|
||||
return null; //anyone can use it
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passRawArgs() {
|
||||
public boolean passRawArgs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDescription() {
|
||||
public String getDescription()
|
||||
{
|
||||
return "Look something up in the Urban Dictionary.";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUsage() {
|
||||
public String getUsage()
|
||||
{
|
||||
return "<query>";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandCategory getCategory() {
|
||||
public CommandCategory getCategory()
|
||||
{
|
||||
return CommandCategory.FUN;
|
||||
}
|
||||
|
||||
@@ -58,7 +64,7 @@ public class UrbanDictionaryCommand implements MessageCommand
|
||||
@Override
|
||||
public void runCommand(MessageReceivedEvent event, String label, String[] args)
|
||||
{
|
||||
if(args.length == 0)
|
||||
if (args.length == 0)
|
||||
{
|
||||
event.getMessage().reply(UrbanDictionary.getNoArgsError()).queue();
|
||||
return;
|
||||
@@ -66,11 +72,12 @@ public class UrbanDictionaryCommand implements MessageCommand
|
||||
|
||||
// sanitize args by only keeping letters and numbers, and adding "+" instead of spaces for HTML parsing
|
||||
StringBuilder termBuilder = new StringBuilder();
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
for (int i = 0; i < args.length; i++)
|
||||
{
|
||||
String arg = args[i];
|
||||
termBuilder.append(arg);
|
||||
|
||||
if(i + 1 != args.length) // add spaces between args, but not on the last run
|
||||
if (i + 1 != args.length) // add spaces between args, but not on the last run
|
||||
termBuilder.append(" ");
|
||||
}
|
||||
|
||||
@@ -79,9 +86,11 @@ public class UrbanDictionaryCommand implements MessageCommand
|
||||
|
||||
Document doc;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
doc = Jsoup.connect(url).get();
|
||||
} catch (IOException e) {
|
||||
} catch (IOException e)
|
||||
{
|
||||
event.getMessage().reply(UrbanDictionary.getTermNotFoundError()).queue();
|
||||
return;
|
||||
}
|
||||
@@ -92,7 +101,7 @@ public class UrbanDictionaryCommand implements MessageCommand
|
||||
|
||||
// disable next page if we only have one result
|
||||
Button nextPageBtnLocal = UrbanDictionary.getNextPageButton();
|
||||
if(search.getPages() == 1) nextPageBtnLocal = nextPageBtnLocal.asDisabled();
|
||||
if (search.getPages() == 1) nextPageBtnLocal = nextPageBtnLocal.asDisabled();
|
||||
|
||||
event.getChannel()
|
||||
.sendMessageEmbeds(embed)
|
||||
|
||||
@@ -14,7 +14,8 @@ import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl;
|
||||
public class AvatarCommand extends SlashCommandImpl
|
||||
{
|
||||
@Override
|
||||
public CommandData getSlashCommandData() {
|
||||
public CommandData getSlashCommandData()
|
||||
{
|
||||
return Commands.slash("avatar", "Get someone's profile picture.")
|
||||
.addOption(OptionType.USER, "user", "User you want to grab the avatar of.")
|
||||
.addOption(OptionType.INTEGER, "size", "The size of the returned image.",
|
||||
@@ -32,26 +33,28 @@ public class AvatarCommand extends SlashCommandImpl
|
||||
int resolution;
|
||||
|
||||
OptionMapping userArg = event.getOption("user");
|
||||
if(userArg != null)
|
||||
if (userArg != null)
|
||||
{
|
||||
user = userArg.getAsUser();
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
user = event.getUser();
|
||||
}
|
||||
|
||||
OptionMapping sizeArg = event.getOption("size");
|
||||
if(sizeArg != null)
|
||||
if (sizeArg != null)
|
||||
{
|
||||
resolution = ProfileImage.parseResolution(sizeArg.getAsInt());
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
resolution = ProfileImage.parseResolution(512);
|
||||
}
|
||||
|
||||
MessageResponse response = ProfileImage.buildResponse(resolution, user, ProfileImage.ImageType.AVATAR);
|
||||
if(response.content() != null)
|
||||
if (response.content() != null)
|
||||
{
|
||||
event.getHook().editOriginal(response.content()).queue();
|
||||
} else if(response.embed() != null)
|
||||
} else if (response.embed() != null)
|
||||
{
|
||||
event.getHook().editOriginalEmbeds(response.embed()).queue();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@ import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl;
|
||||
public class BannerCommand extends SlashCommandImpl
|
||||
{
|
||||
@Override
|
||||
public CommandData getSlashCommandData() {
|
||||
public CommandData getSlashCommandData()
|
||||
{
|
||||
return Commands.slash("banner", "Get someone's profile banner.")
|
||||
.addOption(OptionType.USER, "user", "User you want to grab the banner of.")
|
||||
.addOption(OptionType.INTEGER, "size", "The size of the returned image.",
|
||||
@@ -32,26 +33,28 @@ public class BannerCommand extends SlashCommandImpl
|
||||
int resolution;
|
||||
|
||||
OptionMapping userArg = event.getOption("user");
|
||||
if(userArg != null)
|
||||
if (userArg != null)
|
||||
{
|
||||
user = userArg.getAsUser();
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
user = event.getUser();
|
||||
}
|
||||
|
||||
OptionMapping sizeArg = event.getOption("size");
|
||||
if(sizeArg != null)
|
||||
if (sizeArg != null)
|
||||
{
|
||||
resolution = ProfileImage.parseResolution(sizeArg.getAsInt());
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
resolution = ProfileImage.parseResolution(512);
|
||||
}
|
||||
|
||||
MessageResponse response = ProfileImage.buildResponse(resolution, user, ProfileImage.ImageType.BANNER);
|
||||
if(response.content() != null)
|
||||
if (response.content() != null)
|
||||
{
|
||||
event.getHook().editOriginal(response.content()).queue();
|
||||
} else if(response.embed() != null)
|
||||
} else if (response.embed() != null)
|
||||
{
|
||||
event.getHook().editOriginalEmbeds(response.embed()).queue();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@ import java.util.List;
|
||||
public class BotInfoCommand extends SlashCommandImpl
|
||||
{
|
||||
@Override
|
||||
public CommandData getSlashCommandData() {
|
||||
public CommandData getSlashCommandData()
|
||||
{
|
||||
return Commands.slash("botinfo", "Get info about the bot.");
|
||||
}
|
||||
|
||||
@@ -29,7 +30,7 @@ public class BotInfoCommand extends SlashCommandImpl
|
||||
// get a list of slash commands
|
||||
List<SlashCommand> registeredCommands = Cache.getSlashCommandListener().getRegisteredCommands();
|
||||
LinkedList<String> registeredCommandNames = new LinkedList<>();
|
||||
for(SlashCommand command : registeredCommands)
|
||||
for (SlashCommand command : registeredCommands)
|
||||
{
|
||||
// node: adding slash so people realize that this is specific about slash commands.
|
||||
registeredCommandNames.add("/" + command.getCommandName());
|
||||
|
||||
@@ -17,7 +17,8 @@ public class ClearCommand extends SlashCommandImpl
|
||||
{
|
||||
|
||||
@Override
|
||||
public CommandData getSlashCommandData() {
|
||||
public CommandData getSlashCommandData()
|
||||
{
|
||||
return Commands.slash(ClearChat.getLabel(),
|
||||
ClearChat.getDescription())
|
||||
.addOption(OptionType.INTEGER, "amount", "The amount of messages to delete.")
|
||||
@@ -32,7 +33,7 @@ public class ClearCommand extends SlashCommandImpl
|
||||
|
||||
// check if user is trying to run command in dms.
|
||||
String error = ClearChat.checkDMs(event.getChannel());
|
||||
if(error != null)
|
||||
if (error != null)
|
||||
{
|
||||
event.getHook().editOriginal(error).queue();
|
||||
return;
|
||||
@@ -45,10 +46,10 @@ public class ClearCommand extends SlashCommandImpl
|
||||
int toDeleteAmount = amountOption == null ? 1 : amountOption.getAsInt();
|
||||
|
||||
// cap the amount to avoid abuse.
|
||||
if(toDeleteAmount > ClearChat.getMaxAmount()) toDeleteAmount = 0;
|
||||
if (toDeleteAmount > ClearChat.getMaxAmount()) toDeleteAmount = 0;
|
||||
|
||||
error = ClearChat.checkDeleteAmount(toDeleteAmount);
|
||||
if(error != null)
|
||||
if (error != null)
|
||||
{
|
||||
event.getHook().editOriginal(error).queue();
|
||||
return;
|
||||
|
||||
@@ -29,12 +29,11 @@ public class CoinFlipCommand extends SlashCommandImpl
|
||||
interaction.retrieveOriginal().queue((message) ->
|
||||
{
|
||||
CoinFlip.trackAndRestrict(message, event.getUser());
|
||||
}, (error) -> {});
|
||||
}, (error) -> {});
|
||||
}, (error) -> {
|
||||
});
|
||||
}, (error) -> {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -30,19 +30,19 @@ public class DiceRollCommand extends SlashCommandImpl
|
||||
|
||||
OptionMapping textOption = event.getOption("query");
|
||||
String messageContent = "";
|
||||
if(textOption != null)
|
||||
if (textOption != null)
|
||||
{
|
||||
messageContent = textOption.getAsString();
|
||||
messageContent = textOption.getAsString();
|
||||
}
|
||||
|
||||
String[] args = messageContent.split("\\s");
|
||||
|
||||
MessageResponse response = DiceRoll.buildResponse(event.getUser(), args);
|
||||
|
||||
if(response.content() != null)
|
||||
if (response.content() != null)
|
||||
{
|
||||
event.getHook().editOriginal(response.content()).queue();
|
||||
} else if(response.embed() != null)
|
||||
} else if (response.embed() != null)
|
||||
{
|
||||
event.getHook().editOriginalEmbeds(response.embed()).queue();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@ import java.util.concurrent.TimeUnit;
|
||||
public class DieCommand extends SlashCommandImpl
|
||||
{
|
||||
@Override
|
||||
public CommandData getSlashCommandData() {
|
||||
public CommandData getSlashCommandData()
|
||||
{
|
||||
return Commands.slash("die", "Stop the bot's process.")
|
||||
.setDefaultPermissions(DefaultMemberPermissions.DISABLED);
|
||||
}
|
||||
@@ -24,12 +25,14 @@ public class DieCommand extends SlashCommandImpl
|
||||
@Override
|
||||
public void runSlashCommand(@NotNull SlashCommandInteractionEvent event)
|
||||
{
|
||||
if(Cache.getBotOwnerId() != event.getUser().getIdLong())
|
||||
if (Cache.getBotOwnerId() != event.getUser().getIdLong())
|
||||
{
|
||||
event.reply("Sorry, only the bot owner can run this command!").setEphemeral(true).queue();
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
event.reply("Going to sleep! Cya ✨").queue();
|
||||
try (ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor()) {
|
||||
try (ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor())
|
||||
{
|
||||
executor.schedule(HidekoBot::shutdown, 3, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class InviteCommand extends SlashCommandImpl
|
||||
ReplyCallbackAction replyCallbackAction = event.deferReply();
|
||||
|
||||
// only make message permanent in DMs
|
||||
if(event.getChannelType() != ChannelType.PRIVATE)
|
||||
if (event.getChannelType() != ChannelType.PRIVATE)
|
||||
{
|
||||
replyCallbackAction = replyCallbackAction.setEphemeral(true);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class LoveCalculatorCommand extends SlashCommandImpl
|
||||
{
|
||||
|
||||
return Commands.slash("lovecalc",
|
||||
"Calculate how much two people love each other.")
|
||||
"Calculate how much two people love each other.")
|
||||
|
||||
.addOption(OptionType.MENTIONABLE,
|
||||
"first",
|
||||
@@ -37,10 +37,11 @@ public class LoveCalculatorCommand extends SlashCommandImpl
|
||||
User firstUser, secondUser;
|
||||
|
||||
OptionMapping firsUserArg = event.getOption("first");
|
||||
if(firsUserArg != null)
|
||||
if (firsUserArg != null)
|
||||
{
|
||||
firstUser = firsUserArg.getAsUser(); //todo null check?
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
event.reply("\uD83D\uDE22 I need to know who to check! Please mention them.")
|
||||
.setEphemeral(true)
|
||||
.queue();
|
||||
@@ -48,10 +49,11 @@ public class LoveCalculatorCommand extends SlashCommandImpl
|
||||
}
|
||||
|
||||
OptionMapping secondUserArg = event.getOption("second");
|
||||
if(secondUserArg != null)
|
||||
if (secondUserArg != null)
|
||||
{
|
||||
secondUser = secondUserArg.getAsUser(); //todo null check?
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
secondUser = event.getUser();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public class MagicBallCommand extends SlashCommandImpl
|
||||
{
|
||||
|
||||
return Commands.slash(MagicBall.getLabels().get(0),
|
||||
"Ask a question to the magic ball.")
|
||||
"Ask a question to the magic ball.")
|
||||
.addOption(OptionType.STRING, "question",
|
||||
"The question to ask.",
|
||||
true,
|
||||
@@ -30,12 +30,12 @@ public class MagicBallCommand extends SlashCommandImpl
|
||||
// get the asked question
|
||||
OptionMapping textOption = event.getOption("question");
|
||||
String question = "";
|
||||
if(textOption != null)
|
||||
if (textOption != null)
|
||||
{
|
||||
question = textOption.getAsString();
|
||||
}
|
||||
|
||||
if(textOption == null || question.isEmpty())
|
||||
if (textOption == null || question.isEmpty())
|
||||
{
|
||||
event.reply("\uD83D\uDE20 Hey, you have to ask me a question!")
|
||||
.setEphemeral(true)
|
||||
|
||||
@@ -33,12 +33,12 @@ public class SayCommand extends SlashCommandImpl
|
||||
// get the text to send
|
||||
OptionMapping textOption = event.getOption("text");
|
||||
String messageContent = "";
|
||||
if(textOption != null)
|
||||
if (textOption != null)
|
||||
{
|
||||
messageContent = textOption.getAsString();
|
||||
messageContent = textOption.getAsString();
|
||||
}
|
||||
|
||||
if(textOption == null || messageContent.isEmpty())
|
||||
if (textOption == null || messageContent.isEmpty())
|
||||
{
|
||||
event.reply("\uD83D\uDE20 Hey, you have to tell me what to say!")
|
||||
.setEphemeral(true)
|
||||
|
||||
@@ -26,13 +26,13 @@ public class TriviaCommand extends SlashCommandImpl
|
||||
{
|
||||
MessageChannel channel = event.getChannel();
|
||||
|
||||
if(!(channel instanceof TextChannel))
|
||||
if (!(channel instanceof TextChannel))
|
||||
{
|
||||
event.reply(Trivia.getNoDMsError()).queue();
|
||||
return;
|
||||
}
|
||||
|
||||
if(Trivia.channelsRunningTrivia.contains(channel.getId()))
|
||||
if (Trivia.channelsRunningTrivia.contains(channel.getId()))
|
||||
{
|
||||
event.reply(Trivia.getTriviaAlreadyRunningError()).setEphemeral(true).queue();
|
||||
return;
|
||||
|
||||
@@ -24,7 +24,7 @@ public class UrbanDictionaryCommand extends SlashCommandImpl
|
||||
{
|
||||
|
||||
return Commands.slash(UrbanDictionary.getCommandLabels().get(0),
|
||||
"Look up a term on Urban Dictionary.")
|
||||
"Look up a term on Urban Dictionary.")
|
||||
.addOption(OptionType.STRING, "term", "The term to look up", true);
|
||||
}
|
||||
|
||||
@@ -36,12 +36,12 @@ public class UrbanDictionaryCommand extends SlashCommandImpl
|
||||
// get the term to look up
|
||||
OptionMapping textOption = event.getOption("term");
|
||||
String term = "";
|
||||
if(textOption != null)
|
||||
if (textOption != null)
|
||||
{
|
||||
term = textOption.getAsString();
|
||||
}
|
||||
|
||||
if(textOption == null || term.isEmpty())
|
||||
if (textOption == null || term.isEmpty())
|
||||
{
|
||||
event.reply(UrbanDictionary.getNoArgsError())
|
||||
.setEphemeral(true)
|
||||
@@ -54,9 +54,11 @@ public class UrbanDictionaryCommand extends SlashCommandImpl
|
||||
|
||||
Document doc;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
doc = Jsoup.connect(url).get();
|
||||
} catch (IOException e) {
|
||||
} catch (IOException e)
|
||||
{
|
||||
event.reply(UrbanDictionary.getTermNotFoundError())
|
||||
.setEphemeral(true)
|
||||
.queue();
|
||||
@@ -69,7 +71,7 @@ public class UrbanDictionaryCommand extends SlashCommandImpl
|
||||
|
||||
// disable next page if we only have one result
|
||||
Button nextPageBtnLocal = UrbanDictionary.getNextPageButton();
|
||||
if(search.getPages() == 1) nextPageBtnLocal = nextPageBtnLocal.asDisabled();
|
||||
if (search.getPages() == 1) nextPageBtnLocal = nextPageBtnLocal.asDisabled();
|
||||
|
||||
ActionRow actionRow = ActionRow.of(UrbanDictionary.getPreviousPageButton().asDisabled(),
|
||||
//disabled by default because we're on page 0
|
||||
|
||||
Reference in New Issue
Block a user