Compare commits
4 Commits
b421d033c8
...
main
Author | SHA1 | Date | |
---|---|---|---|
fd2970fa59 | |||
14b54501fd | |||
1928cfe858 | |||
0b7880af88 |
@@ -5,6 +5,7 @@ data:
|
||||
os: linux
|
||||
build_branches:
|
||||
- main
|
||||
- develop
|
||||
build_events:
|
||||
- push
|
||||
- pull_request
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
target/
|
||||
.idea/
|
||||
scripts/
|
||||
*.sqlite
|
88
.pipelines/java-build-deploy.yaml
Normal file
88
.pipelines/java-build-deploy.yaml
Normal file
@@ -0,0 +1,88 @@
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: build
|
||||
platform:
|
||||
os: {{ .input.os }}
|
||||
arch: {{ .input.arch }}
|
||||
|
||||
trigger:
|
||||
branch:
|
||||
{{- range .input.build_branches }}
|
||||
- {{ . }}
|
||||
{{- end }}
|
||||
event:
|
||||
{{- range .input.build_events }}
|
||||
- {{ . }}
|
||||
{{- end }}
|
||||
|
||||
# Global project-specific environment variables
|
||||
environment:
|
||||
{{- range .input.envs }}
|
||||
{{ .name }}: {{ .value }}
|
||||
{{- end }}
|
||||
|
||||
steps:
|
||||
# Test if it compiles correctly
|
||||
- name: build
|
||||
image: maven:3-eclipse-temurin-21
|
||||
commands:
|
||||
- mvn verify --no-transfer-progress -DskipTests=true -Dmaven.javadoc.skip=true -B -V
|
||||
|
||||
# Run unit tests
|
||||
- name: test
|
||||
image: maven:3-eclipse-temurin-21
|
||||
commands:
|
||||
- mvn test --no-transfer-progress -B -V
|
||||
|
||||
# Check maven dependencies
|
||||
- name: dependency-check
|
||||
image: owasp/dependency-check:latest
|
||||
commands:
|
||||
- dependency-check --scan /src --format ALL --out /src/target --nvdApiKey $NVD_API_KEY
|
||||
environment:
|
||||
NVD_API_KEY:
|
||||
from_secret: nvd_api_key
|
||||
|
||||
# Run code analysis
|
||||
- name: code-analysis
|
||||
when:
|
||||
event:
|
||||
- push
|
||||
image: maven:3-eclipse-temurin-21
|
||||
commands:
|
||||
- mvn sonar:sonar --no-transfer-progress -Dsonar.projectKey={{ .input.sonar_project_key }} -Dsonar.host.url=$SONAR_INSTANCE_URL -Dsonar.token=$SONAR_LOGIN_KEY -B -V
|
||||
environment:
|
||||
SONAR_INSTANCE_URL:
|
||||
from_secret: sonar_instance_url
|
||||
SONAR_LOGIN_KEY:
|
||||
from_secret: sonar_login_key
|
||||
---
|
||||
kind: pipeline
|
||||
type: kubernetes
|
||||
name: deploy
|
||||
trigger:
|
||||
event:
|
||||
- promote
|
||||
target:
|
||||
{{- range .input.deploy_targets }}
|
||||
- {{ . }}
|
||||
{{- end }}
|
||||
|
||||
# Global project-specific environment variables
|
||||
environment:
|
||||
{{- range .input.envs }}
|
||||
{{ .name }}: {{ .value }}
|
||||
{{- end }}
|
||||
|
||||
steps:
|
||||
# Upload to Maven repository
|
||||
- name: maven-deploy
|
||||
image: maven:3-eclipse-temurin-21
|
||||
commands:
|
||||
- mvn deploy --no-transfer-progress -DskipTests=true -Dmaven.javadoc.skip=true -B -V -gs settings.xml -Dmaven.repo.username=$MAVEN_REPO_USERNAME -Dmaven.repo.password=$MAVEN_REPO_PASSWORD
|
||||
environment:
|
||||
MAVEN_REPO_USERNAME:
|
||||
from_secret: maven_repo_username
|
||||
MAVEN_REPO_PASSWORD:
|
||||
from_secret: maven_repo_password
|
@@ -2,7 +2,7 @@
|
||||
[](https://sonar.beatrice.wtf/dashboard?id=HidekoBot)
|
||||
[](https://sonar.beatrice.wtf/dashboard?id=HidekoBot)
|
||||
[](https://sonar.beatrice.wtf/dashboard?id=HidekoBot)
|
||||
[](https://drone.prod.panic.haus/bea/HidekoBot)
|
||||
[](https://drone.beatrice.wtf/bea/HidekoBot)
|
||||
[](https://sonar.beatrice.wtf/dashboard?id=HidekoBot)
|
||||
|
||||
Hideko is a general-purpose Discord bot.
|
||||
|
2
pom.xml
2
pom.xml
@@ -91,7 +91,7 @@
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.13.2</version>
|
||||
<version>5.13.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@@ -22,7 +22,8 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
public class Cache
|
||||
{
|
||||
|
||||
private Cache() {
|
||||
private Cache()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
@@ -78,7 +79,10 @@ public class Cache
|
||||
*
|
||||
* @return array of supported resolutions.
|
||||
*/
|
||||
public static int[] getSupportedAvatarResolutions() { return supportedAvatarResolutions; }
|
||||
public static int[] getSupportedAvatarResolutions()
|
||||
{
|
||||
return supportedAvatarResolutions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -86,7 +90,10 @@ public class Cache
|
||||
*
|
||||
* @return a boolean which is true if the bot is in verbose-mode
|
||||
*/
|
||||
public static synchronized boolean isVerbose() { return verbose; }
|
||||
public static synchronized boolean isVerbose()
|
||||
{
|
||||
return verbose;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the bot's verbosity status at runtime.
|
||||
@@ -116,7 +123,8 @@ public class Cache
|
||||
*
|
||||
* @return a long of the account's id
|
||||
*/
|
||||
public static long getBotOwnerId() {
|
||||
public static long getBotOwnerId()
|
||||
{
|
||||
return configurationSource == null ? 0L : (Long) configurationSource.getConfigValue(ConfigurationEntry.BOT_OWNER_ID);
|
||||
}
|
||||
|
||||
@@ -126,7 +134,8 @@ public class Cache
|
||||
*
|
||||
* @return a String of the bot's token.
|
||||
*/
|
||||
public static String getBotToken() {
|
||||
public static String getBotToken()
|
||||
{
|
||||
return configurationSource == null ? null : (String) configurationSource.getConfigValue(ConfigurationEntry.BOT_TOKEN);
|
||||
}
|
||||
|
||||
@@ -137,7 +146,10 @@ public class Cache
|
||||
* @return a long of the account's id
|
||||
*/
|
||||
|
||||
public static long getBotMaintainerId() { return BOT_MAINTAINER_ID; }
|
||||
public static long getBotMaintainerId()
|
||||
{
|
||||
return BOT_MAINTAINER_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the bot's application id.
|
||||
@@ -154,14 +166,18 @@ public class Cache
|
||||
*
|
||||
* @return a string of the bot's application id
|
||||
*/
|
||||
public static String getBotApplicationId() { return botApplicationId; }
|
||||
public static String getBotApplicationId()
|
||||
{
|
||||
return botApplicationId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to generate an invite link for the bot
|
||||
*
|
||||
* @return a string containing the invite link
|
||||
*/
|
||||
public static String getInviteUrl() {
|
||||
public static String getInviteUrl()
|
||||
{
|
||||
return DEFAULT_INVITE_LINK.replace("%userid%", botApplicationId);
|
||||
}
|
||||
|
||||
@@ -180,7 +196,10 @@ public class Cache
|
||||
*
|
||||
* @return the DatabaseSource instance.
|
||||
*/
|
||||
public static @Nullable DatabaseSource getDatabaseSource() { return databaseSource; }
|
||||
public static @Nullable DatabaseSource getDatabaseSource()
|
||||
{
|
||||
return databaseSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the properties source instance loaded from the JAR archive.
|
||||
@@ -197,24 +216,34 @@ public class Cache
|
||||
*
|
||||
* @return the String of the DateTimeFormatter format.
|
||||
*/
|
||||
public static String getExpiryTimestampFormat(){ return EXPIRY_TIMESTAMP_FORMAT; }
|
||||
public static String getExpiryTimestampFormat()
|
||||
{
|
||||
return EXPIRY_TIMESTAMP_FORMAT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount of seconds after which a message expires.
|
||||
*
|
||||
* @return long value of the expiry seconds.
|
||||
*/
|
||||
public static long getExpiryTimeSeconds() { return EXPIRY_TIME_SECONDS; }
|
||||
public static long getExpiryTimeSeconds()
|
||||
{
|
||||
return EXPIRY_TIME_SECONDS;
|
||||
}
|
||||
|
||||
|
||||
public static String getBotName() { return BOT_NAME; }
|
||||
public static String getBotName()
|
||||
{
|
||||
return BOT_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bot's version.
|
||||
*
|
||||
* @return a String of the bot version.
|
||||
*/
|
||||
public static String getBotVersion() {
|
||||
public static String getBotVersion()
|
||||
{
|
||||
return propertiesSource.getProperty("bot.version");
|
||||
}
|
||||
|
||||
@@ -223,7 +252,8 @@ public class Cache
|
||||
*
|
||||
* @return a String containing the base URL of the repository, including a <b>trailing slash</b>.
|
||||
*/
|
||||
public static String getRepositoryUrl() {
|
||||
public static String getRepositoryUrl()
|
||||
{
|
||||
String url = propertiesSource.getProperty("repo.base_url");
|
||||
return url.endsWith("/") ? url : url + "/";
|
||||
}
|
||||
@@ -233,16 +263,19 @@ public class Cache
|
||||
*
|
||||
* @return the Color object.
|
||||
*/
|
||||
public static Color getBotColor() {
|
||||
public static Color getBotColor()
|
||||
{
|
||||
Color defaultColor = Color.PINK;
|
||||
if (configurationSource == null) return defaultColor;
|
||||
String colorName = (String) configurationSource.getConfigValue(ConfigurationEntry.BOT_COLOR);
|
||||
|
||||
Color color = null;
|
||||
try {
|
||||
try
|
||||
{
|
||||
Field field = Color.class.getField(colorName);
|
||||
color = (Color) field.get(null);
|
||||
} catch (RuntimeException | NoSuchFieldException | IllegalAccessException e) {
|
||||
} catch (RuntimeException | NoSuchFieldException | IllegalAccessException e)
|
||||
{
|
||||
LOGGER.error("Unknown color: {}", colorName);
|
||||
}
|
||||
return color == null ? defaultColor : color;
|
||||
@@ -251,21 +284,36 @@ public class Cache
|
||||
|
||||
//todo javadocs
|
||||
public static void setSlashCommandListener(SlashCommandListener commandListener)
|
||||
{ slashCommandListener = commandListener; }
|
||||
{
|
||||
slashCommandListener = commandListener;
|
||||
}
|
||||
|
||||
public static SlashCommandListener getSlashCommandListener() { return slashCommandListener; }
|
||||
public static SlashCommandListener getSlashCommandListener()
|
||||
{
|
||||
return slashCommandListener;
|
||||
}
|
||||
|
||||
|
||||
public static void setSlashCommandCompletionListener(SlashCommandCompletionListener commandCompletionListener)
|
||||
{ slashCommandCompletionListener = commandCompletionListener; }
|
||||
{
|
||||
slashCommandCompletionListener = commandCompletionListener;
|
||||
}
|
||||
|
||||
public static SlashCommandCompletionListener getSlashCommandCompletionListener() { return slashCommandCompletionListener; }
|
||||
public static SlashCommandCompletionListener getSlashCommandCompletionListener()
|
||||
{
|
||||
return slashCommandCompletionListener;
|
||||
}
|
||||
|
||||
|
||||
public static void setMessageCommandListener(MessageCommandListener commandListener)
|
||||
{ messageCommandListener = commandListener; }
|
||||
{
|
||||
messageCommandListener = commandListener;
|
||||
}
|
||||
|
||||
public static MessageCommandListener getMessageCommandListener() { return messageCommandListener; }
|
||||
public static MessageCommandListener getMessageCommandListener()
|
||||
{
|
||||
return messageCommandListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the bot's startup time. Generally only used at boot time.
|
||||
@@ -273,7 +321,9 @@ public class Cache
|
||||
* @param time a LocalDateTime of the startup moment.
|
||||
*/
|
||||
public static void setStartupTime(LocalDateTime time)
|
||||
{ startupTime = time; }
|
||||
{
|
||||
startupTime = time;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -281,37 +331,54 @@ public class Cache
|
||||
*
|
||||
* @return a LocalDateTime object of the startup instant.
|
||||
*/
|
||||
public static LocalDateTime getStartupTime() { return startupTime; }
|
||||
public static LocalDateTime getStartupTime()
|
||||
{
|
||||
return startupTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time of when the bot was created.
|
||||
*
|
||||
* @return a LocalDateTime object of the first commit's instant.
|
||||
*/
|
||||
public static LocalDateTime getBotBirthDate() { return botBirthDate; }
|
||||
public static LocalDateTime getBotBirthDate()
|
||||
{
|
||||
return botBirthDate;
|
||||
}
|
||||
|
||||
public static String getFullHeartBeatLink() {
|
||||
public static String getFullHeartBeatLink()
|
||||
{
|
||||
return configurationSource == null ? null : (String) configurationSource.getConfigValue(ConfigurationEntry.HEARTBEAT_LINK);
|
||||
}
|
||||
|
||||
//todo javadocs
|
||||
public static String getExecPath() { return EXEC_PATH; }
|
||||
public static String getExecPath()
|
||||
{
|
||||
return EXEC_PATH;
|
||||
}
|
||||
|
||||
/*private static ConfigurationSource getConfigurationSource()
|
||||
{ return configurationSource; }*/
|
||||
|
||||
public static String getRandomOrgApiKey() {
|
||||
public static String getRandomOrgApiKey()
|
||||
{
|
||||
return configurationSource == null ? null : (String) configurationSource.getConfigValue(ConfigurationEntry.RANDOM_ORG_API_KEY);
|
||||
}
|
||||
|
||||
public static void setConfigurationSource(ConfigurationSource configurationSource)
|
||||
{ Cache.configurationSource = configurationSource; }
|
||||
{
|
||||
Cache.configurationSource = configurationSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bot's prefix
|
||||
*
|
||||
* @return a String of the bot's prefix.
|
||||
*/
|
||||
public static String getBotPrefix() { return BOT_PREFIX; }
|
||||
public static String getBotPrefix()
|
||||
{
|
||||
return BOT_PREFIX;
|
||||
}
|
||||
|
||||
public static void cacheLoveCalculatorValue(String userId1, String userId2, int value)
|
||||
{
|
||||
@@ -336,7 +403,8 @@ public class Cache
|
||||
loveCalculatorValues.remove(userId2 + "|" + userId1);
|
||||
}
|
||||
|
||||
public static ScheduledExecutorService getTaskScheduler() {
|
||||
public static ScheduledExecutorService getTaskScheduler()
|
||||
{
|
||||
return taskScheduler;
|
||||
}
|
||||
|
||||
|
@@ -76,12 +76,12 @@ public class HidekoBot
|
||||
);
|
||||
|
||||
jda = jdaBuilder.build().awaitReady();
|
||||
} catch (InterruptedException e) {
|
||||
} catch (InterruptedException e)
|
||||
{
|
||||
LOGGER.error(e.getMessage()); // print the error message, omit the stack trace.
|
||||
Thread.currentThread().interrupt(); // send interrupt to the thread.
|
||||
shutdown(); // if we failed connecting and authenticating, then quit.
|
||||
}
|
||||
catch (Exception e)
|
||||
} catch (Exception e)
|
||||
{
|
||||
LOGGER.error(e.getMessage()); // print the error message, omit the stack trace.
|
||||
shutdown(); // if we failed connecting and authenticating, then quit.
|
||||
@@ -96,7 +96,8 @@ public class HidekoBot
|
||||
|
||||
// if there is at least one arg, then iterate through them because we have additional things to do.
|
||||
// we are doing this at the end because we might need the API to be already initialized for some things.
|
||||
if(args.length > 0) {
|
||||
if (args.length > 0)
|
||||
{
|
||||
List<String> argsList = new ArrayList<>(Arrays.asList(args));
|
||||
|
||||
|
||||
@@ -187,7 +188,8 @@ public class HidekoBot
|
||||
|
||||
// update slash commands (delayed)
|
||||
final boolean finalForceUpdateCommands = forceUpdateCommands;
|
||||
try (ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor()) {
|
||||
try (ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor())
|
||||
{
|
||||
executor.schedule(() -> CommandUtil.updateSlashCommands(finalForceUpdateCommands),
|
||||
1, TimeUnit.SECONDS);
|
||||
}
|
||||
@@ -207,7 +209,8 @@ public class HidekoBot
|
||||
// load data here...
|
||||
|
||||
LOGGER.info("Database data loaded into memory!");
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
LOGGER.error("Error initializing database connection!");
|
||||
}
|
||||
|
||||
@@ -240,6 +243,7 @@ public class HidekoBot
|
||||
LOGGER.info("Invite Link: {}", Cache.getInviteUrl());
|
||||
|
||||
}
|
||||
|
||||
public static JDA getAPI()
|
||||
{
|
||||
return jda;
|
||||
|
@@ -6,7 +6,8 @@ import java.util.LinkedList;
|
||||
|
||||
public class Alias
|
||||
{
|
||||
private Alias() {
|
||||
private Alias()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
|
@@ -13,7 +13,8 @@ import java.util.List;
|
||||
|
||||
public class BotInfo
|
||||
{
|
||||
private BotInfo() {
|
||||
private BotInfo()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
@@ -57,7 +58,8 @@ public class BotInfo
|
||||
String messageCommandsInfo;
|
||||
if (Cache.getMessageCommandListener() == null)
|
||||
messageCommandsInfo = "❌ disabled";
|
||||
else {
|
||||
else
|
||||
{
|
||||
messageCommandsInfo = "✅ available";
|
||||
commandsCount += Cache.getMessageCommandListener().getRegisteredCommands().size();
|
||||
}
|
||||
@@ -67,7 +69,8 @@ public class BotInfo
|
||||
String slashCommandsInfo;
|
||||
if (Cache.getMessageCommandListener() == null)
|
||||
slashCommandsInfo = "❌ disabled";
|
||||
else {
|
||||
else
|
||||
{
|
||||
slashCommandsInfo = "✅ available";
|
||||
commandsCount += Cache.getSlashCommandListener().getRegisteredCommands().size();
|
||||
}
|
||||
@@ -78,7 +81,8 @@ public class BotInfo
|
||||
if (RandomUtil.isRandomOrgKeyValid())
|
||||
{
|
||||
randomOrgInfo = "✅ connected";
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
randomOrgInfo = "❌ disabled";
|
||||
}
|
||||
embedBuilder.addField("Random.org", randomOrgInfo, true);
|
||||
|
@@ -14,26 +14,32 @@ 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."; }
|
||||
{
|
||||
return "\uD83D\uDE22 Sorry! I can't delete messages here.";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -41,7 +47,9 @@ public class ClearChat
|
||||
public static String checkDeleteAmount(int toDeleteAmount)
|
||||
{
|
||||
if (toDeleteAmount <= 0)
|
||||
{ return "\uD83D\uDE22 Sorry, I can't delete that amount of messages!"; }
|
||||
{
|
||||
return "\uD83D\uDE22 Sorry, I can't delete that amount of messages!";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -82,7 +90,8 @@ public class ClearChat
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -95,7 +104,8 @@ public class ClearChat
|
||||
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.
|
||||
@@ -108,7 +118,8 @@ public class ClearChat
|
||||
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);
|
||||
|
||||
@@ -123,10 +134,10 @@ public class ClearChat
|
||||
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
|
||||
@@ -162,12 +173,16 @@ public class ClearChat
|
||||
} 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"));
|
||||
}
|
||||
@@ -31,7 +33,8 @@ public class CoinFlip
|
||||
if (rand == 1)
|
||||
{
|
||||
msg = ":coin: It's **Heads**!";
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
msg = "It's **Tails**! :coin:";
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -44,7 +45,8 @@ public class DiceRoll
|
||||
if (currentDice == null)
|
||||
{
|
||||
currentDice = new Dice(6);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
currentDice = new Dice(currentDice);
|
||||
}
|
||||
|
||||
@@ -56,8 +58,7 @@ 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));
|
||||
|
||||
@@ -138,13 +139,16 @@ public class DiceRoll
|
||||
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(", ");
|
||||
}
|
||||
|
||||
|
@@ -10,7 +10,8 @@ import wtf.beatrice.hidekobot.HidekoBot;
|
||||
public class Invite
|
||||
{
|
||||
|
||||
private Invite() {
|
||||
private Invite()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
|
@@ -11,7 +11,8 @@ import java.util.concurrent.TimeUnit;
|
||||
public class LoveCalculator
|
||||
{
|
||||
|
||||
private LoveCalculator() {
|
||||
private LoveCalculator()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
|
@@ -14,7 +14,8 @@ import java.util.List;
|
||||
public class MagicBall
|
||||
{
|
||||
|
||||
private MagicBall() {
|
||||
private MagicBall()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
@@ -44,7 +47,8 @@ public class ProfileImage
|
||||
{
|
||||
resolutionString = resolution + " × " + resolution;
|
||||
imageLink = user.getEffectiveAvatar().getUrl(resolution);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
int verticalRes = 361 * resolution / 1024;
|
||||
resolutionString = resolution + " × " + verticalRes;
|
||||
if (bannerProxy != null)
|
||||
@@ -72,7 +76,8 @@ public class ProfileImage
|
||||
if (imageType == ImageType.AVATAR)
|
||||
{
|
||||
currLink = user.getEffectiveAvatar().getUrl(currSize);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
if (bannerProxy == null) break;
|
||||
currLink = bannerProxy.getUrl(currSize);
|
||||
}
|
||||
@@ -87,15 +92,16 @@ public class ProfileImage
|
||||
embedBuilder.addField("Available resolutions", links.toString(), false);
|
||||
|
||||
|
||||
|
||||
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!";
|
||||
}
|
||||
@@ -102,7 +112,8 @@ 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()));
|
||||
@@ -115,7 +126,8 @@ public class Trivia
|
||||
}
|
||||
bufferedReader.close();
|
||||
return new JSONObject(jsonStrBuilder.toString());
|
||||
} catch (IOException e) {
|
||||
} catch (IOException e)
|
||||
{
|
||||
LOGGER.error("JSON Parsing Exception", e);
|
||||
}
|
||||
|
||||
@@ -198,14 +210,16 @@ public class Trivia
|
||||
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(() ->
|
||||
@@ -230,7 +244,8 @@ public class Trivia
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -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!";
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -156,14 +162,16 @@ public class UrbanDictionary
|
||||
if (page > 0)
|
||||
{
|
||||
components.add(UrbanDictionary.getPreviousPageButton().asEnabled());
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
components.add(UrbanDictionary.getPreviousPageButton().asDisabled());
|
||||
}
|
||||
|
||||
if (page + 1 == search.getPages())
|
||||
{
|
||||
components.add(UrbanDictionary.getNextPageButton().asDisabled());
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
components.add(UrbanDictionary.getNextPageButton().asEnabled());
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
@@ -172,11 +174,14 @@ 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 -> {
|
||||
case TIMEOUT ->
|
||||
{
|
||||
if (args != null)
|
||||
{
|
||||
String durationStr = args[1];
|
||||
@@ -201,7 +206,8 @@ public class UserPunishment
|
||||
punishmentAction = guild.timeoutFor(mentioned, duration);
|
||||
}
|
||||
}
|
||||
} catch (RuntimeException ignored) {
|
||||
} catch (RuntimeException ignored)
|
||||
{
|
||||
impossible = true;
|
||||
}
|
||||
|
||||
@@ -218,7 +224,8 @@ public class UserPunishment
|
||||
if (!reason.isEmpty() && !reasonBuilder.isEmpty())
|
||||
punishmentAction.reason("[" + author.getAsTag() + "] " + reason);
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
punishmentAction.complete();
|
||||
} catch (RuntimeException ignored)
|
||||
{
|
||||
@@ -248,7 +255,8 @@ public class UserPunishment
|
||||
|
||||
}
|
||||
|
||||
public enum PunishmentType {
|
||||
public enum PunishmentType
|
||||
{
|
||||
KICK("kicked"),
|
||||
BAN("banned"),
|
||||
TIMEOUT("timed out"),
|
||||
|
@@ -13,12 +13,14 @@ 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) {
|
||||
public void runCompletion(@NotNull CommandAutoCompleteInteractionEvent event)
|
||||
{
|
||||
if (event.getFocusedOption().getName().equals("size"))
|
||||
{
|
||||
|
||||
|
@@ -17,36 +17,42 @@ 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>";
|
||||
}
|
||||
|
||||
|
@@ -20,36 +20,42 @@ 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,13 +69,16 @@ 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
|
||||
}
|
||||
}
|
||||
|
@@ -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,13 +69,16 @@ 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
|
||||
}
|
||||
}
|
||||
|
@@ -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)
|
||||
{
|
||||
@@ -76,7 +86,8 @@ public class ClearCommand implements MessageCommand
|
||||
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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
@@ -102,7 +110,8 @@ public class HelpCommand implements MessageCommand
|
||||
}
|
||||
|
||||
event.getMessage().replyEmbeds(embedBuilder.build()).queue();
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
|
||||
String commandLabel = args[0].toLowerCase();
|
||||
MessageCommand command = Cache.getMessageCommandListener().getRegisteredCommand(commandLabel);
|
||||
@@ -125,7 +134,8 @@ public class HelpCommand implements MessageCommand
|
||||
if (permissions == null)
|
||||
{
|
||||
permissionsStringBuilder = new StringBuilder("Available to everyone");
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
for (int i = 0; i < permissions.size(); i++)
|
||||
{
|
||||
Permission permission = permissions.get(i);
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -80,7 +85,8 @@ public class LoveCalculatorCommand implements MessageCommand
|
||||
if (mentions.size() == 1)
|
||||
{
|
||||
user2 = event.getAuthor();
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
mentionedUserId = mentions.get(1).getId();
|
||||
user2 = HidekoBot.getAPI().retrieveUserById(mentionedUserId).complete();
|
||||
}
|
||||
|
@@ -15,36 +15,42 @@ 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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
@@ -83,7 +89,8 @@ public class TriviaCommand implements MessageCommand
|
||||
if (response.content() != null) responseAction = recvMessage.reply(response.content());
|
||||
else if (response.embed() != null) responseAction = recvMessage.replyEmbeds(response.embed());
|
||||
|
||||
if(responseAction != null) {
|
||||
if (responseAction != null)
|
||||
{
|
||||
if (response.components() != null) responseAction = responseAction.addActionRow(response.components());
|
||||
|
||||
responseAction.queue(message -> {
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
@@ -66,7 +72,8 @@ 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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
@@ -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.",
|
||||
@@ -35,7 +36,8 @@ public class AvatarCommand extends SlashCommandImpl
|
||||
if (userArg != null)
|
||||
{
|
||||
user = userArg.getAsUser();
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
user = event.getUser();
|
||||
}
|
||||
|
||||
@@ -43,7 +45,8 @@ public class AvatarCommand extends SlashCommandImpl
|
||||
if (sizeArg != null)
|
||||
{
|
||||
resolution = ProfileImage.parseResolution(sizeArg.getAsInt());
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
resolution = ProfileImage.parseResolution(512);
|
||||
}
|
||||
|
||||
|
@@ -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.",
|
||||
@@ -35,7 +36,8 @@ public class BannerCommand extends SlashCommandImpl
|
||||
if (userArg != null)
|
||||
{
|
||||
user = userArg.getAsUser();
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
user = event.getUser();
|
||||
}
|
||||
|
||||
@@ -43,7 +45,8 @@ public class BannerCommand extends SlashCommandImpl
|
||||
if (sizeArg != null)
|
||||
{
|
||||
resolution = ProfileImage.parseResolution(sizeArg.getAsInt());
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
resolution = ProfileImage.parseResolution(512);
|
||||
}
|
||||
|
||||
|
@@ -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.");
|
||||
}
|
||||
|
||||
|
@@ -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.")
|
||||
|
@@ -29,12 +29,11 @@ public class CoinFlipCommand extends SlashCommandImpl
|
||||
interaction.retrieveOriginal().queue((message) ->
|
||||
{
|
||||
CoinFlip.trackAndRestrict(message, event.getUser());
|
||||
}, (error) -> {});
|
||||
}, (error) -> {});
|
||||
}, (error) -> {
|
||||
});
|
||||
}, (error) -> {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
@@ -27,9 +28,11 @@ public class DieCommand extends SlashCommandImpl
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -40,7 +40,8 @@ public class LoveCalculatorCommand extends SlashCommandImpl
|
||||
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();
|
||||
@@ -51,7 +52,8 @@ public class LoveCalculatorCommand extends SlashCommandImpl
|
||||
if (secondUserArg != null)
|
||||
{
|
||||
secondUser = secondUserArg.getAsUser(); //todo null check?
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
secondUser = event.getUser();
|
||||
}
|
||||
|
||||
|
@@ -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();
|
||||
|
@@ -14,12 +14,20 @@ public enum ConfigurationEntry
|
||||
|
||||
private String path;
|
||||
private Object defaultValue;
|
||||
|
||||
ConfigurationEntry(String path, Object defaultValue)
|
||||
{
|
||||
this.path = path;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public String getPath() { return path; }
|
||||
public Object getDefaultValue() { return defaultValue; }
|
||||
public String getPath()
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
public Object getDefaultValue()
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
@@ -49,15 +49,16 @@ public class ConfigurationSource
|
||||
if (!fsConfigFile.exists())
|
||||
{
|
||||
// try to create config file
|
||||
try {
|
||||
try
|
||||
{
|
||||
if (!fsConfigFile.createNewFile())
|
||||
{
|
||||
LOGGER.error("We tried creating a file that already exists!");
|
||||
HidekoBot.shutdown();
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
} catch (IOException e)
|
||||
{
|
||||
LOGGER.error("Error creating configuration file!", e);
|
||||
HidekoBot.shutdown();
|
||||
return;
|
||||
@@ -68,8 +69,12 @@ public class ConfigurationSource
|
||||
Yaml fsConfigYaml = new Yaml(new SafeConstructor(options));
|
||||
LinkedHashMap<String, Object> fsConfigContents = null; // map holding all file entries
|
||||
try (InputStream fsConfigStream = new FileInputStream(fsConfigFile))
|
||||
{ fsConfigContents = fsConfigYaml.load(fsConfigStream); }
|
||||
catch (IOException e) { LOGGER.error(e.getMessage()); }
|
||||
{
|
||||
fsConfigContents = fsConfigYaml.load(fsConfigStream);
|
||||
} catch (IOException e)
|
||||
{
|
||||
LOGGER.error(e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
if (fsConfigContents == null) // if file contents are empty or corrupted...
|
||||
@@ -106,13 +111,15 @@ public class ConfigurationSource
|
||||
{
|
||||
// if the key already exists, copy the original value
|
||||
filledEntries.put(key, fsConfigContents.get(key));
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
// else, copy the value from the example config file
|
||||
filledEntries.put(key, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
// new writer to actually write the contents to the file
|
||||
PrintWriter missingKeysWriter = new PrintWriter(fsConfigFile);
|
||||
|
||||
@@ -125,7 +132,8 @@ public class ConfigurationSource
|
||||
// create the yaml object and dump the values to filesystem
|
||||
Yaml yaml = new Yaml(dumperOptions);
|
||||
yaml.dump(filledEntries, missingKeysWriter);
|
||||
} catch (FileNotFoundException e) {
|
||||
} catch (FileNotFoundException e)
|
||||
{
|
||||
LOGGER.error(e.getMessage());
|
||||
HidekoBot.shutdown();
|
||||
return;
|
||||
@@ -133,7 +141,8 @@ public class ConfigurationSource
|
||||
|
||||
// finally, dump all entries to cache.
|
||||
loadConfig(filledEntries);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
// if no key is missing, just cache all entries and values from filesystem.
|
||||
loadConfig(fsConfigContents);
|
||||
}
|
||||
@@ -144,6 +153,7 @@ public class ConfigurationSource
|
||||
{
|
||||
this.configurationEntries.putAll(configurationEntries);
|
||||
}
|
||||
|
||||
public Object getConfigValue(ConfigurationEntry key)
|
||||
{
|
||||
return configurationEntries.get(key.getPath());
|
||||
|
@@ -12,31 +12,37 @@ import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DatabaseSource {
|
||||
public class DatabaseSource
|
||||
{
|
||||
|
||||
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(DatabaseSource.class);
|
||||
private static final String JDBC_URL = "jdbc:sqlite:%path%";
|
||||
private Connection dbConnection = null;
|
||||
private final String dbPath;
|
||||
|
||||
public DatabaseSource(String dbPath) {
|
||||
public DatabaseSource(String dbPath)
|
||||
{
|
||||
this.dbPath = dbPath;
|
||||
}
|
||||
|
||||
private void logException(SQLException e) {
|
||||
private void logException(SQLException e)
|
||||
{
|
||||
LOGGER.error("Database Exception", e);
|
||||
}
|
||||
|
||||
public boolean connect() {
|
||||
public boolean connect()
|
||||
{
|
||||
String url = JDBC_URL.replace("%path%", dbPath);
|
||||
|
||||
if (!close()) return false;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
dbConnection = DriverManager.getConnection(url);
|
||||
LOGGER.info("Database connection established!");
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logException(e);
|
||||
return false;
|
||||
}
|
||||
@@ -44,13 +50,18 @@ public class DatabaseSource {
|
||||
}
|
||||
|
||||
|
||||
public boolean close() {
|
||||
if (dbConnection != null) {
|
||||
try {
|
||||
if (!dbConnection.isClosed()) {
|
||||
public boolean close()
|
||||
{
|
||||
if (dbConnection != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!dbConnection.isClosed())
|
||||
{
|
||||
dbConnection.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logException(e);
|
||||
return false;
|
||||
}
|
||||
@@ -87,7 +98,8 @@ public class DatabaseSource {
|
||||
*/
|
||||
|
||||
//todo: javadocs
|
||||
public boolean initDb() {
|
||||
public boolean initDb()
|
||||
{
|
||||
List<String> newTables = new ArrayList<>();
|
||||
|
||||
newTables.add("""
|
||||
@@ -119,11 +131,14 @@ public class DatabaseSource {
|
||||
);
|
||||
""");
|
||||
|
||||
for (String sql : newTables) {
|
||||
try (Statement stmt = dbConnection.createStatement()) {
|
||||
for (String sql : newTables)
|
||||
{
|
||||
try (Statement stmt = dbConnection.createStatement())
|
||||
{
|
||||
// execute the statement
|
||||
stmt.execute(sql);
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logException(e);
|
||||
return false;
|
||||
}
|
||||
@@ -132,14 +147,17 @@ public class DatabaseSource {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean trackRanCommandReply(Message message, User user) {
|
||||
public boolean trackRanCommandReply(Message message, User user)
|
||||
{
|
||||
String userId = user.getId();
|
||||
String guildId;
|
||||
|
||||
ChannelType channelType = message.getChannelType();
|
||||
if (!(channelType.isGuild())) {
|
||||
if (!(channelType.isGuild()))
|
||||
{
|
||||
guildId = userId;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
guildId = message.getGuild().getId();
|
||||
}
|
||||
|
||||
@@ -153,7 +171,8 @@ public class DatabaseSource {
|
||||
(?, ?, ?, ?, ?);
|
||||
""";
|
||||
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
||||
{
|
||||
preparedStatement.setString(1, guildId);
|
||||
preparedStatement.setString(2, channelId);
|
||||
preparedStatement.setString(3, messageId);
|
||||
@@ -163,36 +182,42 @@ public class DatabaseSource {
|
||||
preparedStatement.executeUpdate();
|
||||
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logException(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isUserTrackedFor(String userId, String messageId) {
|
||||
public boolean isUserTrackedFor(String userId, String messageId)
|
||||
{
|
||||
String trackedUserId = getTrackedReplyUserId(messageId);
|
||||
if (trackedUserId == null) return false;
|
||||
return userId.equals(trackedUserId);
|
||||
}
|
||||
|
||||
public ChannelType getTrackedMessageChannelType(String messageId) {
|
||||
public ChannelType getTrackedMessageChannelType(String messageId)
|
||||
{
|
||||
String query = """
|
||||
SELECT channel_type
|
||||
FROM command_runners
|
||||
WHERE message_id = ?;
|
||||
""";
|
||||
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
||||
{
|
||||
preparedStatement.setString(1, messageId);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.isClosed()) return null;
|
||||
while (resultSet.next()) {
|
||||
while (resultSet.next())
|
||||
{
|
||||
String channelTypeName = resultSet.getString("channel_type");
|
||||
return ChannelType.valueOf(channelTypeName);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logException(e);
|
||||
}
|
||||
|
||||
@@ -200,37 +225,44 @@ public class DatabaseSource {
|
||||
|
||||
}
|
||||
|
||||
public String getTrackedReplyUserId(String messageId) {
|
||||
public String getTrackedReplyUserId(String messageId)
|
||||
{
|
||||
String query = """
|
||||
SELECT user_id
|
||||
FROM command_runners
|
||||
WHERE message_id = ?;
|
||||
""";
|
||||
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
||||
{
|
||||
preparedStatement.setString(1, messageId);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.isClosed()) return null;
|
||||
while (resultSet.next()) {
|
||||
while (resultSet.next())
|
||||
{
|
||||
return resultSet.getString("user_id");
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logException(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean queueDisabling(Message message) {
|
||||
public boolean queueDisabling(Message message)
|
||||
{
|
||||
String messageId = message.getId();
|
||||
String channelId = message.getChannel().getId();
|
||||
String guildId;
|
||||
|
||||
ChannelType channelType = message.getChannelType();
|
||||
if (!(channelType.isGuild())) {
|
||||
if (!(channelType.isGuild()))
|
||||
{
|
||||
guildId = "PRIVATE";
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
guildId = message.getGuild().getId();
|
||||
}
|
||||
|
||||
@@ -245,7 +277,8 @@ public class DatabaseSource {
|
||||
(?, ?, ?, ?);
|
||||
""";
|
||||
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
||||
{
|
||||
preparedStatement.setString(1, guildId);
|
||||
preparedStatement.setString(2, channelId);
|
||||
preparedStatement.setString(3, messageId);
|
||||
@@ -254,14 +287,16 @@ public class DatabaseSource {
|
||||
preparedStatement.executeUpdate();
|
||||
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logException(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<String> getQueuedExpiringMessages() {
|
||||
public List<String> getQueuedExpiringMessages()
|
||||
{
|
||||
List<String> messages = new ArrayList<>();
|
||||
|
||||
String query = """
|
||||
@@ -269,44 +304,54 @@ public class DatabaseSource {
|
||||
FROM pending_disabled_messages;
|
||||
""";
|
||||
|
||||
try (Statement statement = dbConnection.createStatement()) {
|
||||
try (Statement statement = dbConnection.createStatement())
|
||||
{
|
||||
ResultSet resultSet = statement.executeQuery(query);
|
||||
if (resultSet.isClosed()) return messages;
|
||||
while (resultSet.next()) {
|
||||
while (resultSet.next())
|
||||
{
|
||||
messages.add(resultSet.getString("message_id"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logException(e);
|
||||
}
|
||||
|
||||
return messages;
|
||||
}
|
||||
|
||||
public boolean untrackExpiredMessage(String messageId) {
|
||||
public boolean untrackExpiredMessage(String messageId)
|
||||
{
|
||||
String query = "DELETE FROM pending_disabled_messages WHERE message_id = ?;";
|
||||
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
||||
{
|
||||
preparedStatement.setString(1, messageId);
|
||||
preparedStatement.execute();
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logException(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
query = "DELETE FROM command_runners WHERE message_id = ?;";
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
||||
{
|
||||
preparedStatement.setString(1, messageId);
|
||||
preparedStatement.execute();
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logException(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
query = "DELETE FROM urban_dictionary WHERE message_id = ?;";
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
||||
{
|
||||
preparedStatement.setString(1, messageId);
|
||||
preparedStatement.execute();
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logException(e);
|
||||
return false;
|
||||
}
|
||||
@@ -314,66 +359,78 @@ public class DatabaseSource {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getQueuedExpiringMessageExpiryDate(String messageId) {
|
||||
public String getQueuedExpiringMessageExpiryDate(String messageId)
|
||||
{
|
||||
String query = """
|
||||
SELECT expiry_timestamp
|
||||
FROM pending_disabled_messages
|
||||
WHERE message_id = ?;
|
||||
""";
|
||||
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
||||
{
|
||||
preparedStatement.setString(1, messageId);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.isClosed()) return null;
|
||||
while (resultSet.next()) {
|
||||
while (resultSet.next())
|
||||
{
|
||||
return resultSet.getString("expiry_timestamp");
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logException(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getQueuedExpiringMessageChannel(String messageId) {
|
||||
public String getQueuedExpiringMessageChannel(String messageId)
|
||||
{
|
||||
String query = """
|
||||
SELECT channel_id
|
||||
FROM pending_disabled_messages
|
||||
WHERE message_id = ?;
|
||||
""";
|
||||
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
||||
{
|
||||
preparedStatement.setString(1, messageId);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.isClosed()) return null;
|
||||
while (resultSet.next()) {
|
||||
while (resultSet.next())
|
||||
{
|
||||
return resultSet.getString("channel_id");
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logException(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getQueuedExpiringMessageGuild(String messageId) {
|
||||
public String getQueuedExpiringMessageGuild(String messageId)
|
||||
{
|
||||
String query = """
|
||||
SELECT guild_id
|
||||
FROM pending_disabled_messages
|
||||
WHERE message_id = ?;
|
||||
""";
|
||||
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
||||
{
|
||||
preparedStatement.setString(1, messageId);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.isClosed()) return null;
|
||||
while (resultSet.next()) {
|
||||
while (resultSet.next())
|
||||
{
|
||||
return resultSet.getString("guild_id");
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logException(e);
|
||||
}
|
||||
|
||||
@@ -382,7 +439,8 @@ public class DatabaseSource {
|
||||
|
||||
public boolean trackUrban(String meanings, String examples,
|
||||
String contributors, String dates,
|
||||
Message message, String term) {
|
||||
Message message, String term)
|
||||
{
|
||||
|
||||
String query = """
|
||||
INSERT INTO urban_dictionary
|
||||
@@ -390,7 +448,8 @@ public class DatabaseSource {
|
||||
(?, ?, ?, ?, ?, ?, ?);
|
||||
""";
|
||||
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
||||
{
|
||||
preparedStatement.setString(1, message.getId());
|
||||
preparedStatement.setInt(2, 0);
|
||||
preparedStatement.setString(3, meanings);
|
||||
@@ -402,167 +461,196 @@ public class DatabaseSource {
|
||||
preparedStatement.executeUpdate();
|
||||
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logException(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getUrbanPage(String messageId) {
|
||||
public int getUrbanPage(String messageId)
|
||||
{
|
||||
String query = """
|
||||
SELECT page
|
||||
FROM urban_dictionary
|
||||
WHERE message_id = ?;
|
||||
""";
|
||||
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
||||
{
|
||||
preparedStatement.setString(1, messageId);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.isClosed()) return 0;
|
||||
while (resultSet.next()) {
|
||||
while (resultSet.next())
|
||||
{
|
||||
return resultSet.getInt("page");
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logException(e);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getUrbanMeanings(String messageId) {
|
||||
public String getUrbanMeanings(String messageId)
|
||||
{
|
||||
String query = """
|
||||
SELECT meanings
|
||||
FROM urban_dictionary
|
||||
WHERE message_id = ?;
|
||||
""";
|
||||
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
||||
{
|
||||
preparedStatement.setString(1, messageId);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.isClosed()) return null;
|
||||
while (resultSet.next()) {
|
||||
while (resultSet.next())
|
||||
{
|
||||
return resultSet.getString("meanings");
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logException(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getUrbanExamples(String messageId) {
|
||||
public String getUrbanExamples(String messageId)
|
||||
{
|
||||
String query = """
|
||||
SELECT examples
|
||||
FROM urban_dictionary
|
||||
WHERE message_id = ?;
|
||||
""";
|
||||
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
||||
{
|
||||
preparedStatement.setString(1, messageId);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.isClosed()) return null;
|
||||
while (resultSet.next()) {
|
||||
while (resultSet.next())
|
||||
{
|
||||
return resultSet.getString("examples");
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logException(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getUrbanContributors(String messageId) {
|
||||
public String getUrbanContributors(String messageId)
|
||||
{
|
||||
String query = """
|
||||
SELECT contributors
|
||||
FROM urban_dictionary
|
||||
WHERE message_id = ?;
|
||||
""";
|
||||
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
||||
{
|
||||
preparedStatement.setString(1, messageId);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.isClosed()) return null;
|
||||
while (resultSet.next()) {
|
||||
while (resultSet.next())
|
||||
{
|
||||
return resultSet.getString("contributors");
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logException(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getUrbanDates(String messageId) {
|
||||
public String getUrbanDates(String messageId)
|
||||
{
|
||||
String query = """
|
||||
SELECT dates
|
||||
FROM urban_dictionary
|
||||
WHERE message_id = ?;
|
||||
""";
|
||||
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
||||
{
|
||||
preparedStatement.setString(1, messageId);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.isClosed()) return null;
|
||||
while (resultSet.next()) {
|
||||
while (resultSet.next())
|
||||
{
|
||||
return resultSet.getString("dates");
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logException(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getUrbanTerm(String messageId) {
|
||||
public String getUrbanTerm(String messageId)
|
||||
{
|
||||
String query = """
|
||||
SELECT term
|
||||
FROM urban_dictionary
|
||||
WHERE message_id = ?;
|
||||
""";
|
||||
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
||||
{
|
||||
preparedStatement.setString(1, messageId);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.isClosed()) return null;
|
||||
while (resultSet.next()) {
|
||||
while (resultSet.next())
|
||||
{
|
||||
return resultSet.getString("term");
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logException(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean setUrbanPage(String messageId, int page) {
|
||||
public boolean setUrbanPage(String messageId, int page)
|
||||
{
|
||||
String query = """
|
||||
UPDATE urban_dictionary
|
||||
SET page = ?
|
||||
WHERE message_id = ?;
|
||||
""";
|
||||
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
||||
{
|
||||
preparedStatement.setInt(1, page);
|
||||
preparedStatement.setString(2, messageId);
|
||||
preparedStatement.executeUpdate();
|
||||
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logException(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean resetExpiryTimestamp(String messageId) {
|
||||
public boolean resetExpiryTimestamp(String messageId)
|
||||
{
|
||||
LocalDateTime expiryTime = LocalDateTime.now().plusSeconds(Cache.getExpiryTimeSeconds());
|
||||
|
||||
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(Cache.getExpiryTimestampFormat());
|
||||
@@ -574,14 +662,16 @@ public class DatabaseSource {
|
||||
WHERE message_id = ?;
|
||||
""";
|
||||
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
||||
{
|
||||
preparedStatement.setString(1, expiryTimeFormatted);
|
||||
preparedStatement.setString(2, messageId);
|
||||
preparedStatement.executeUpdate();
|
||||
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logException(e);
|
||||
}
|
||||
|
||||
|
@@ -25,8 +25,8 @@ public class PropertiesSource
|
||||
{
|
||||
properties.load(internalPropertiesStream);
|
||||
|
||||
}
|
||||
catch (IOException e) {
|
||||
} catch (IOException e)
|
||||
{
|
||||
LOGGER.error(e.getMessage());
|
||||
HidekoBot.shutdown();
|
||||
return;
|
||||
@@ -34,5 +34,7 @@ public class PropertiesSource
|
||||
}
|
||||
|
||||
public String getProperty(String property)
|
||||
{ return properties == null ? "" : properties.getProperty(property); }
|
||||
{
|
||||
return properties == null ? "" : properties.getProperty(property);
|
||||
}
|
||||
}
|
||||
|
@@ -18,7 +18,8 @@ public class ButtonInteractionListener extends ListenerAdapter
|
||||
public void onButtonInteraction(ButtonInteractionEvent event)
|
||||
{
|
||||
|
||||
switch (event.getComponentId().toLowerCase()) {
|
||||
switch (event.getComponentId().toLowerCase())
|
||||
{
|
||||
|
||||
// coinflip
|
||||
case "coinflip_reflip" -> CoinFlip.buttonReFlip(event);
|
||||
|
@@ -45,7 +45,9 @@ public class MessageCommandListener extends ListenerAdapter
|
||||
for (String currentAlias : aliases)
|
||||
{
|
||||
if (label.equals(currentAlias))
|
||||
{ return entry.getValue(); }
|
||||
{
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +55,9 @@ public class MessageCommandListener extends ListenerAdapter
|
||||
}
|
||||
|
||||
public LinkedList<MessageCommand> getRegisteredCommands()
|
||||
{ return new LinkedList<>(registeredCommands.values()); }
|
||||
{
|
||||
return new LinkedList<>(registeredCommands.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(@NotNull MessageReceivedEvent event)
|
||||
@@ -133,8 +137,7 @@ public class MessageCommandListener extends ListenerAdapter
|
||||
argsString = argsString.replaceAll("^[\\S]+\\s*", "");
|
||||
// pass all other arguments as a single argument as the first array element
|
||||
commandArgs = new String[]{argsString};
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
// copy all split arguments to the array, except from the command label
|
||||
commandArgs = Arrays.copyOfRange(argsRaw, 1, argsRaw.length);
|
||||
|
@@ -33,8 +33,7 @@ public class MessageLogger extends ListenerAdapter
|
||||
toLog = GUILD_MESSAGE_LOG_FORMAT
|
||||
.replace("%guild%", guildName)
|
||||
.replace("%channel%", channelName);
|
||||
}
|
||||
else if(event.getChannel() instanceof PrivateChannel)
|
||||
} else if (event.getChannel() instanceof PrivateChannel)
|
||||
{
|
||||
toLog = DIRECT_MESSAGE_LOG_FORMAT;
|
||||
}
|
||||
|
@@ -14,7 +14,8 @@ public class SelectMenuInteractionListener extends ListenerAdapter
|
||||
@Override
|
||||
public void onStringSelectInteraction(StringSelectInteractionEvent event)
|
||||
{
|
||||
switch (event.getComponentId().toLowerCase()) {
|
||||
switch (event.getComponentId().toLowerCase())
|
||||
{
|
||||
|
||||
// trivia
|
||||
case "trivia_categories" -> Trivia.handleMenuSelection(event);
|
||||
|
@@ -21,10 +21,15 @@ public class SlashCommandCompletionListener extends ListenerAdapter
|
||||
}
|
||||
|
||||
public SlashArgumentsCompleter getRegisteredCompleter(String label)
|
||||
{ return registeredCompleters.get(label); }
|
||||
{
|
||||
return registeredCompleters.get(label);
|
||||
}
|
||||
|
||||
public LinkedList<SlashArgumentsCompleter> getRegisteredCompleters()
|
||||
{ return new LinkedList<>(registeredCompleters.values()); }
|
||||
{
|
||||
return new LinkedList<>(registeredCompleters.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommandAutoCompleteInteraction(CommandAutoCompleteInteractionEvent event)
|
||||
{
|
||||
|
@@ -21,10 +21,14 @@ public class SlashCommandListener extends ListenerAdapter
|
||||
}
|
||||
|
||||
public SlashCommand getRegisteredCommand(String label)
|
||||
{ return registeredCommands.get(label); }
|
||||
{
|
||||
return registeredCommands.get(label);
|
||||
}
|
||||
|
||||
public LinkedList<SlashCommand> getRegisteredCommands()
|
||||
{ return new LinkedList<>(registeredCommands.values()); }
|
||||
{
|
||||
return new LinkedList<>(registeredCommands.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event)
|
||||
|
@@ -9,10 +9,12 @@ import java.util.Objects;
|
||||
|
||||
public record MessageResponse(@Nullable String content,
|
||||
@Nullable MessageEmbed embed,
|
||||
@Nullable ItemComponent... components) {
|
||||
@Nullable ItemComponent... components)
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
MessageResponse response = (MessageResponse) o;
|
||||
@@ -22,14 +24,16 @@ public record MessageResponse(@Nullable String content,
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
public int hashCode()
|
||||
{
|
||||
int result = Objects.hash(content, embed);
|
||||
result = 31 * result + Arrays.hashCode(components);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
public String toString()
|
||||
{
|
||||
return "MessageResponse{" +
|
||||
"content=" + content +
|
||||
", embed=" + embed +
|
||||
|
@@ -9,10 +9,14 @@ public enum CommandCategory
|
||||
;
|
||||
|
||||
private String emoji;
|
||||
|
||||
CommandCategory(String emoji)
|
||||
{
|
||||
this.emoji = emoji;
|
||||
}
|
||||
|
||||
public String getEmoji() { return emoji; }
|
||||
public String getEmoji()
|
||||
{
|
||||
return emoji;
|
||||
}
|
||||
}
|
||||
|
@@ -70,9 +70,7 @@ public interface MessageCommand
|
||||
*
|
||||
* @param event the received message event. It should not be used for parsing message contents data as
|
||||
* the arguments already account for it in a better way.
|
||||
*
|
||||
* @param label the command label that was used, taken from all available command aliases.
|
||||
*
|
||||
* @param args a pre-formatted list of arguments, excluding the bot prefix and the command name.
|
||||
* This is useful because command logic won't have to change in case the bot prefix is changed,
|
||||
* removed, or we switch to another method of triggering commands (ping, trigger words, ...).
|
||||
|
@@ -12,6 +12,7 @@ public interface SlashArgumentsCompleter
|
||||
* @return the command object.
|
||||
*/
|
||||
SlashCommand getCommand();
|
||||
|
||||
/**
|
||||
* Run the argument-completion logic by parsing the event and replying accordingly.
|
||||
*
|
||||
|
@@ -6,13 +6,16 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class SlashArgumentsCompleterImpl implements SlashArgumentsCompleter
|
||||
{
|
||||
private final SlashCommand parentCommand;
|
||||
|
||||
public SlashArgumentsCompleterImpl(SlashCommand parentCommand)
|
||||
{
|
||||
this.parentCommand = parentCommand;
|
||||
}
|
||||
|
||||
public SlashCommand getCommand()
|
||||
{ return parentCommand; }
|
||||
{
|
||||
return parentCommand;
|
||||
}
|
||||
|
||||
public void runCompletion(@NotNull CommandAutoCompleteInteractionEvent event)
|
||||
{
|
||||
|
@@ -21,6 +21,7 @@ public interface SlashCommand
|
||||
* @return the command data object.
|
||||
*/
|
||||
CommandData getSlashCommandData();
|
||||
|
||||
/**
|
||||
* Run the command logic by parsing the event and replying accordingly.
|
||||
*
|
||||
|
@@ -8,17 +8,20 @@ public class SlashCommandImpl implements SlashCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
public String getCommandName()
|
||||
{
|
||||
return getSlashCommandData().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandData getSlashCommandData() {
|
||||
public CommandData getSlashCommandData()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runSlashCommand(@NotNull SlashCommandInteractionEvent event) {
|
||||
public void runSlashCommand(@NotNull SlashCommandInteractionEvent event)
|
||||
{
|
||||
event.reply("Base command implementation").queue();
|
||||
}
|
||||
}
|
||||
|
@@ -6,10 +6,12 @@ import java.util.LinkedList;
|
||||
/**
|
||||
* This class gets two linked lists, and compares their first value alphabetically.
|
||||
*/
|
||||
public class MessageCommandAliasesComparator implements Comparator<LinkedList<String>> {
|
||||
public class MessageCommandAliasesComparator implements Comparator<LinkedList<String>>
|
||||
{
|
||||
|
||||
@Override
|
||||
public int compare(LinkedList<String> linkedList, LinkedList<String> t1) {
|
||||
public int compare(LinkedList<String> linkedList, LinkedList<String> t1)
|
||||
{
|
||||
|
||||
if (linkedList.isEmpty()) return 0;
|
||||
if (t1.isEmpty()) return 0;
|
||||
|
@@ -7,10 +7,12 @@ import java.util.Comparator;
|
||||
/**
|
||||
* This class gets two trivia categories, and compares them by their name.
|
||||
*/
|
||||
public class TriviaCategoryComparator implements Comparator<TriviaCategory> {
|
||||
public class TriviaCategoryComparator implements Comparator<TriviaCategory>
|
||||
{
|
||||
|
||||
@Override
|
||||
public int compare(TriviaCategory o1, TriviaCategory o2) {
|
||||
public int compare(TriviaCategory o1, TriviaCategory o2)
|
||||
{
|
||||
return CharSequence.compare(o1.categoryName(), o2.categoryName());
|
||||
}
|
||||
}
|
||||
|
@@ -7,10 +7,12 @@ import java.util.Comparator;
|
||||
/**
|
||||
* This class gets two trivia scores, and compares their score.
|
||||
*/
|
||||
public class TriviaScoreComparator implements Comparator<TriviaScore> {
|
||||
public class TriviaScoreComparator implements Comparator<TriviaScore>
|
||||
{
|
||||
|
||||
@Override
|
||||
public int compare(TriviaScore o1, TriviaScore o2) {
|
||||
public int compare(TriviaScore o1, TriviaScore o2)
|
||||
{
|
||||
return Integer.compare(o2.getScore(), o1.getScore()); // inverted, because higher number should come first
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package wtf.beatrice.hidekobot.objects.fun;
|
||||
|
||||
public record TriviaCategory(String categoryName, int categoryId) {
|
||||
public record TriviaCategory(String categoryName, int categoryId)
|
||||
{
|
||||
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package wtf.beatrice.hidekobot.objects.fun;
|
||||
import java.util.List;
|
||||
|
||||
public record TriviaQuestion(String question, String correctAnswer,
|
||||
List<String> wrongAnswers) {
|
||||
List<String> wrongAnswers)
|
||||
{
|
||||
|
||||
}
|
||||
|
@@ -18,9 +18,15 @@ public class TriviaScore
|
||||
score += add;
|
||||
}
|
||||
|
||||
public int getScore() { return score; }
|
||||
public int getScore()
|
||||
{
|
||||
return score;
|
||||
}
|
||||
|
||||
public User getUser() { return user; }
|
||||
public User getUser()
|
||||
{
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
|
@@ -10,7 +10,8 @@ import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
public class ExpiredMessageTask implements Runnable {
|
||||
public class ExpiredMessageTask implements Runnable
|
||||
{
|
||||
|
||||
private final DateTimeFormatter formatter;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ExpiredMessageTask.class);
|
||||
@@ -26,7 +27,8 @@ public class ExpiredMessageTask implements Runnable {
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
public void run()
|
||||
{
|
||||
|
||||
databaseSource = Cache.getDatabaseSource();
|
||||
if (databaseSource == null) return;
|
||||
|
@@ -18,7 +18,8 @@ public class HeartBeatTask implements Runnable
|
||||
String urlString = Cache.getFullHeartBeatLink();
|
||||
if (urlString == null || urlString.isEmpty()) return;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
|
||||
URL heartbeatUrl = new URL(urlString);
|
||||
|
||||
@@ -32,13 +33,13 @@ public class HeartBeatTask implements Runnable
|
||||
{
|
||||
// only log ok response codes when verbosity is enabled
|
||||
if (Cache.isVerbose()) LOGGER.info("Heartbeat response code: {}", responseCode);
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
LOGGER.error("Heartbeat returned problematic response code: {}", responseCode);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
} catch (IOException e)
|
||||
{
|
||||
LOGGER.error("Error while trying to push heartbeat", e);
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,8 @@ public class StatusUpdateTask implements Runnable
|
||||
);
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
public void run()
|
||||
{
|
||||
int randomPos = RandomUtil.getRandomNumber(0, statuses.size() - 1);
|
||||
String status = statuses.get(randomPos) + " | " + Cache.getBotPrefix() + " help";
|
||||
HidekoBot.getAPI().getPresence().setActivity(Activity.playing(status));
|
||||
|
@@ -93,12 +93,14 @@ public class TriviaTask implements Runnable
|
||||
previousScore = score;
|
||||
topScore = score;
|
||||
pos = 1;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
if (score != previousScore) pos++;
|
||||
}
|
||||
|
||||
if (pos == 1) winners.add(user);
|
||||
else {
|
||||
else
|
||||
{
|
||||
othersBuilder.append("\n").append(pos)
|
||||
.append(" | ").append(user)
|
||||
.append(": ").append(score).append(" points");
|
||||
@@ -113,7 +115,8 @@ public class TriviaTask implements Runnable
|
||||
if (i + 1 != winners.size())
|
||||
{
|
||||
winnersBuilder.append(", "); // separate with comma except on last run
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
winnersBuilder.append(": ").append(topScore).append(" points \uD83C\uDF89");
|
||||
}
|
||||
}
|
||||
|
@@ -27,7 +27,8 @@ public class CommandUtil
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CommandUtil.class);
|
||||
|
||||
private CommandUtil() {
|
||||
private CommandUtil()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
@@ -40,7 +41,8 @@ public class CommandUtil
|
||||
public static void delete(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;
|
||||
}
|
||||
@@ -64,7 +66,9 @@ public class CommandUtil
|
||||
// populate commands list from registered commands
|
||||
List<CommandData> allCommands = new ArrayList<>();
|
||||
for (SlashCommand cmd : Cache.getSlashCommandListener().getRegisteredCommands())
|
||||
{ allCommands.add(cmd.getSlashCommandData()); }
|
||||
{
|
||||
allCommands.add(cmd.getSlashCommandData());
|
||||
}
|
||||
|
||||
JDA jdaInstance = HidekoBot.getAPI();
|
||||
|
||||
@@ -189,8 +193,7 @@ public class CommandUtil
|
||||
}
|
||||
|
||||
textChannel = user.openPrivateChannel().complete();
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
String guildId = databaseSource.getQueuedExpiringMessageGuild(messageId);
|
||||
Guild guild = guildId == null ? null : HidekoBot.getAPI().getGuildById(guildId);
|
||||
|
@@ -12,7 +12,8 @@ import java.util.Arrays;
|
||||
public class FormatUtil
|
||||
{
|
||||
|
||||
private FormatUtil() {
|
||||
private FormatUtil()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
@@ -60,21 +61,25 @@ public class FormatUtil
|
||||
*
|
||||
* @return the formatted String
|
||||
*/
|
||||
public static String getNiceDuration(Duration duration) {
|
||||
public static String getNiceDuration(Duration duration)
|
||||
{
|
||||
long days = duration.toDays();
|
||||
long hours = duration.toHoursPart();
|
||||
long minutes = duration.toMinutesPart();
|
||||
long seconds = duration.toSecondsPart();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (days > 0) {
|
||||
if (days > 0)
|
||||
{
|
||||
sb.append(days).append("d ");
|
||||
sb.append(hours).append("h ");
|
||||
sb.append(minutes).append("m ");
|
||||
} else if (hours > 0) {
|
||||
} else if (hours > 0)
|
||||
{
|
||||
sb.append(hours).append("h ");
|
||||
sb.append(minutes).append("m ");
|
||||
} else if (minutes > 0) {
|
||||
} else if (minutes > 0)
|
||||
{
|
||||
sb.append(minutes).append("m ");
|
||||
}
|
||||
sb.append(seconds).append("s");
|
||||
|
@@ -50,7 +50,8 @@ public class Logger<T>
|
||||
{
|
||||
// create a new scheduled executor with an anonymous runnable...
|
||||
//... after waiting <delay> seconds.
|
||||
try (ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor()) {
|
||||
try (ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor())
|
||||
{
|
||||
executor.schedule(() -> log(message), delay, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
@@ -10,7 +10,8 @@ import java.util.Random;
|
||||
public class RandomUtil
|
||||
{
|
||||
|
||||
private RandomUtil() {
|
||||
private RandomUtil()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
@@ -47,7 +48,8 @@ public class RandomUtil
|
||||
}
|
||||
|
||||
|
||||
public static Random getRandom() {
|
||||
public static Random getRandom()
|
||||
{
|
||||
return randomInstance;
|
||||
}
|
||||
|
||||
|
@@ -10,33 +10,38 @@ import java.util.List;
|
||||
public class SerializationUtil
|
||||
{
|
||||
|
||||
private SerializationUtil() {
|
||||
private SerializationUtil()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static <T> String serializeBase64(List<T> dataList) {
|
||||
public static <T> String serializeBase64(List<T> dataList)
|
||||
{
|
||||
|
||||
try (ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||
ObjectOutputStream so = new ObjectOutputStream(bo)) {
|
||||
ObjectOutputStream so = new ObjectOutputStream(bo))
|
||||
{
|
||||
so.writeObject(dataList);
|
||||
so.flush();
|
||||
return Base64.getEncoder().encodeToString(bo.toByteArray());
|
||||
}
|
||||
catch (IOException e) {
|
||||
} catch (IOException e)
|
||||
{
|
||||
throw new SerializationException("Error during serialization", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> LinkedList<T> deserializeBase64(String dataStr) {
|
||||
public static <T> LinkedList<T> deserializeBase64(String dataStr)
|
||||
{
|
||||
|
||||
byte[] b = Base64.getDecoder().decode(dataStr);
|
||||
ByteArrayInputStream bi = new ByteArrayInputStream(b);
|
||||
ObjectInputStream si;
|
||||
try {
|
||||
try
|
||||
{
|
||||
si = new ObjectInputStream(bi);
|
||||
return LinkedList.class.cast(si.readObject());
|
||||
}
|
||||
catch (IOException | ClassNotFoundException e) {
|
||||
} catch (IOException | ClassNotFoundException e)
|
||||
{
|
||||
throw new SerializationException("Error during deserialization", e);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user