Compare commits
No commits in common. "master" and "v1.0.1" have entirely different histories.
17 changed files with 191 additions and 363 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -40,7 +40,7 @@ build/
|
||||||
|
|
||||||
### Other Stuff ###
|
### Other Stuff ###
|
||||||
config*.json
|
config*.json
|
||||||
!config.example.json
|
config.example.json
|
||||||
!**/resources/config.schema.json
|
!**/resources/config.schema.json
|
||||||
|
|
||||||
### why would this not be here already ###
|
### why would this not be here already ###
|
||||||
|
|
|
@ -1,14 +1,7 @@
|
||||||
<component name="InspectionProjectProfileManager">
|
<component name="InspectionProjectProfileManager">
|
||||||
<profile version="1.0">
|
<profile version="1.0">
|
||||||
<option name="myName" value="Project Default" />
|
<option name="myName" value="Project Default" />
|
||||||
<inspection_tool class="GrazieInspection" enabled="false" level="GRAMMAR_ERROR" enabled_by_default="false" />
|
|
||||||
<inspection_tool class="InstantiationOfUtilityClass" enabled="false" level="WARNING" enabled_by_default="false" />
|
<inspection_tool class="InstantiationOfUtilityClass" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
<inspection_tool class="LanguageDetectionInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
|
||||||
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
|
|
||||||
<option name="processCode" value="true" />
|
|
||||||
<option name="processLiterals" value="true" />
|
|
||||||
<option name="processComments" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="XmlHighlighting" enabled="false" level="ERROR" enabled_by_default="false" />
|
<inspection_tool class="XmlHighlighting" enabled="false" level="ERROR" enabled_by_default="false" />
|
||||||
</profile>
|
</profile>
|
||||||
</component>
|
</component>
|
|
@ -1,9 +1,4 @@
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="EntryPointsManager">
|
|
||||||
<list size="1">
|
|
||||||
<item index="0" class="java.lang.String" itemvalue="com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand" />
|
|
||||||
</list>
|
|
||||||
</component>
|
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="MavenProjectsManager">
|
<component name="MavenProjectsManager">
|
||||||
<option name="originalFiles">
|
<option name="originalFiles">
|
||||||
|
|
31
README.md
31
README.md
|
@ -1,20 +1,14 @@
|
||||||
<img src="https://git.frzn.dev/fwoppydwisk/doki/raw/branch/master/assets/logo.svg" alt="" height="100"/>
|
<img src="https://git.frzn.dev/fwoppydwisk/doki/raw/branch/master/assets/logo.svg" alt="" height="100"/>
|
||||||
<hr>
|
<hr>
|
||||||
<a href="https://git.frzn.dev/fwoppydwisk/doki/releases/latest">
|
|
||||||
<img src="https://git.frzn.dev/fwoppydwisk/doki/badges/release.svg?style=for-the-badge" alt="">
|
|
||||||
</a>
|
|
||||||
<img src="https://git.frzn.dev/fwoppydwisk/doki/badges/stars.svg?style=for-the-badge" alt="">
|
|
||||||
<br>
|
|
||||||
A multipurpose Discord bot written in Java.
|
A multipurpose Discord bot written in Java.
|
||||||
|
|
||||||
## Required Environment
|
## Tested Environments
|
||||||
- Java 17+ (May work on older versions but untested)
|
- Java 21+ (May work on older versions but untested)
|
||||||
- Maven
|
- Maven
|
||||||
|
|
||||||
### Tested Operating Systems
|
### Tested Operating Systems
|
||||||
- macOS 14 & 15 (arm64)
|
- macOS 14.4.1
|
||||||
- Windows 10 22H2 (x86_64)
|
- Windows 10 (22H2)
|
||||||
- Debian 12 (x86_64)
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -22,7 +16,7 @@ A multipurpose Discord bot written in Java.
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"token": "your_token",
|
"token": "your_token",
|
||||||
"warningChannel": 0
|
"prefix": "oki!"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -30,12 +24,9 @@ A multipurpose Discord bot written in Java.
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
| Command | Description | Arguments |
|
| Command | Description | Arguments | Aliases |
|
||||||
|-------------------|------------------------------------------------------------------------------|-----------------------------------------------------------|
|
|---------|------------------------------------------------------------------------------|-------------------------------------|---------|
|
||||||
| `/ping` | Gets the bot's gateway & rest ping | None |
|
| `about` | Gets information about the bot | None | None |
|
||||||
| `/whois` | Gets information about the specified user (message author if none specified) | `[member]` |
|
| `ping` | Gets the bot's gateway & rest ping | None | None |
|
||||||
| `/timeout set` | Times out a member for a specified amount of time | `[member]`, `[duration]`, `(reason)` |
|
| `whois` | Gets information about the specified user (message author if none specified) | `[user ping]` | None |
|
||||||
| `/timeout get` | Gets the current timeout status of the specified member | `[member]` |
|
| `mute` | Mutes a member for a specified amount of time | `[user ping]`, `[timeout duration]` | None |
|
||||||
| `/timeout cancel` | Cancels the specified users timeout | `[member]`, `(reason)` |
|
|
||||||
| `/poll` | Creates a poll | `[title]`, `[duration]`, `[options]`, `(multiple-choice)` |
|
|
||||||
| `/warn` | Warns a user | `[member]`, `[reason]` |
|
|
|
@ -1,4 +0,0 @@
|
||||||
{
|
|
||||||
"token": "CHANGEME",
|
|
||||||
"warningChannel": 0
|
|
||||||
}
|
|
16
pom.xml
16
pom.xml
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<groupId>net.hypr</groupId>
|
<groupId>net.hypr</groupId>
|
||||||
<artifactId>doki</artifactId>
|
<artifactId>doki</artifactId>
|
||||||
<version>1.0.8</version>
|
<version>1.0.0</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.dv8tion</groupId>
|
<groupId>net.dv8tion</groupId>
|
||||||
<artifactId>JDA</artifactId>
|
<artifactId>JDA</artifactId>
|
||||||
<version>5.2.1</version>
|
<version>5.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.github.freya022</groupId>
|
<groupId>io.github.freya022</groupId>
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ch.qos.logback</groupId>
|
<groupId>ch.qos.logback</groupId>
|
||||||
<artifactId>logback-classic</artifactId>
|
<artifactId>logback-classic</artifactId>
|
||||||
<version>1.5.13</version>
|
<version>1.5.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mariadb.jdbc</groupId>
|
<groupId>org.mariadb.jdbc</groupId>
|
||||||
|
@ -56,15 +56,5 @@
|
||||||
<artifactId>commons-dbutils</artifactId>
|
<artifactId>commons-dbutils</artifactId>
|
||||||
<version>1.8.1</version>
|
<version>1.8.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>ch.qos.logback</groupId>
|
|
||||||
<artifactId>logback-core</artifactId>
|
|
||||||
<version>1.5.13</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.protobuf</groupId>
|
|
||||||
<artifactId>protobuf-java</artifactId>
|
|
||||||
<version>4.28.2</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
|
@ -11,7 +11,8 @@ import java.nio.charset.StandardCharsets;
|
||||||
//You will need a valid config.json in the resources folder for this to work
|
//You will need a valid config.json in the resources folder for this to work
|
||||||
public class Config {
|
public class Config {
|
||||||
@SuppressWarnings("unused") private String token;
|
@SuppressWarnings("unused") private String token;
|
||||||
@SuppressWarnings("unused") private long warningChannel;
|
@SuppressWarnings("unused") private String prefix;
|
||||||
|
@SuppressWarnings("unused") private DBConfig mariadb;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the configuration object for this bot
|
* Returns the configuration object for this bot
|
||||||
|
@ -34,7 +35,29 @@ public class Config {
|
||||||
public String getToken() {
|
public String getToken() {
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
public long getWarningChannel() {
|
public String getPrefix() { return prefix; }
|
||||||
return warningChannel;
|
|
||||||
|
public DBConfig getDbConfig() {
|
||||||
|
return mariadb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DBConfig {
|
||||||
|
@SuppressWarnings("unused") private String host, user, password, database;
|
||||||
|
@SuppressWarnings("unused") private int portNumber;
|
||||||
|
|
||||||
|
public String getHost() { return host; }
|
||||||
|
|
||||||
|
public String getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDatabase() { return database; }
|
||||||
|
public int getPortNumber() {
|
||||||
|
return portNumber;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,6 +5,7 @@ import com.freya02.botcommands.api.Logging;
|
||||||
import net.dv8tion.jda.api.JDA;
|
import net.dv8tion.jda.api.JDA;
|
||||||
import net.dv8tion.jda.api.JDABuilder;
|
import net.dv8tion.jda.api.JDABuilder;
|
||||||
import net.dv8tion.jda.api.entities.*;
|
import net.dv8tion.jda.api.entities.*;
|
||||||
|
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -22,16 +23,14 @@ public class Doki {
|
||||||
public static JDA getJDA() {
|
public static JDA getJDA() {
|
||||||
return jda;
|
return jda;
|
||||||
}
|
}
|
||||||
public static Config getConfig() { return config; }
|
public static String getPrefix() { return config.getPrefix(); }
|
||||||
public static Logger getLogger() {
|
|
||||||
return log;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void start() throws IOException, InterruptedException {
|
public static void start() throws IOException, InterruptedException {
|
||||||
config = Config.readConfig();
|
config = Config.readConfig();
|
||||||
|
|
||||||
final JDA jda = JDABuilder.createLight(config.getToken())
|
final JDA jda = JDABuilder.createLight(config.getToken())
|
||||||
.setActivity(Activity.customStatus("Banned from everywhere"))
|
.setActivity(Activity.customStatus("Banned from everywhere"))
|
||||||
|
.enableIntents(GatewayIntent.MESSAGE_CONTENT)
|
||||||
.build()
|
.build()
|
||||||
.awaitReady();
|
.awaitReady();
|
||||||
|
|
||||||
|
@ -50,7 +49,7 @@ public class Doki {
|
||||||
start();
|
start();
|
||||||
jda = getJDA();
|
jda = getJDA();
|
||||||
CommandsBuilder.newBuilder(437970062922612737L)
|
CommandsBuilder.newBuilder(437970062922612737L)
|
||||||
.textCommandBuilder(textCommandsBuilder -> textCommandsBuilder.disableHelpCommand(true))
|
.textCommandBuilder(textCommandsBuilder -> textCommandsBuilder.addPrefix(getPrefix()))
|
||||||
.build(jda, "net.hypr.doki.commands"); //Registering listeners is taken care of by the lib
|
.build(jda, "net.hypr.doki.commands"); //Registering listeners is taken care of by the lib
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Failed to start the bot", e);
|
log.error("Failed to start the bot", e);
|
||||||
|
|
48
src/main/java/net/hypr/doki/commands/moderation/Mute.java
Normal file
48
src/main/java/net/hypr/doki/commands/moderation/Mute.java
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
package net.hypr.doki.commands.moderation;
|
||||||
|
|
||||||
|
import com.freya02.botcommands.api.annotations.CommandMarker;
|
||||||
|
import com.freya02.botcommands.api.prefixed.BaseCommandEvent;
|
||||||
|
import com.freya02.botcommands.api.prefixed.CommandEvent;
|
||||||
|
import com.freya02.botcommands.api.prefixed.TextCommand;
|
||||||
|
import com.freya02.botcommands.api.prefixed.annotations.Category;
|
||||||
|
import com.freya02.botcommands.api.prefixed.annotations.Description;
|
||||||
|
import com.freya02.botcommands.api.prefixed.annotations.JDATextCommand;
|
||||||
|
import com.freya02.botcommands.api.prefixed.annotations.TextOption;
|
||||||
|
import net.dv8tion.jda.api.Permission;
|
||||||
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.Command;
|
||||||
|
import net.hypr.doki.utils.DurationUtils;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
@CommandMarker
|
||||||
|
@Category("Moderation")
|
||||||
|
@Description("Mutes a user for a specified amount of time")
|
||||||
|
public class Mute extends TextCommand {
|
||||||
|
@JDATextCommand(name = "mute", order = 1)
|
||||||
|
public void execute(BaseCommandEvent event, @TextOption(example = "<@437970062922612737>") Member member, @TextOption(example = "30m") String duration) {
|
||||||
|
Member commandExecutor = event.getMember();
|
||||||
|
if (!commandExecutor.hasPermission(Permission.KICK_MEMBERS)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Duration timeoutDuration;
|
||||||
|
try {
|
||||||
|
timeoutDuration = DurationUtils.parseDuration(duration);
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
event.reply("Invalid duration format!").queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Math.abs(timeoutDuration.toDays()) > 28) {
|
||||||
|
event.reply("Duration must be less than 28 days!").queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
member.timeoutFor(timeoutDuration).queue();
|
||||||
|
event.reply("Muted " + member.getAsMention() + " (" + member.getEffectiveName() + ") for " + duration).queue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@JDATextCommand(name = "mute", order = 2)
|
||||||
|
public void execute(CommandEvent event) {
|
||||||
|
event.reply("You must specify a user and duration!").queue();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,82 +0,0 @@
|
||||||
package net.hypr.doki.commands.moderation;
|
|
||||||
|
|
||||||
import com.freya02.botcommands.api.annotations.BotPermissions;
|
|
||||||
import com.freya02.botcommands.api.annotations.CommandMarker;
|
|
||||||
import com.freya02.botcommands.api.annotations.Optional;
|
|
||||||
import com.freya02.botcommands.api.annotations.UserPermissions;
|
|
||||||
import com.freya02.botcommands.api.application.ApplicationCommand;
|
|
||||||
import com.freya02.botcommands.api.application.annotations.AppOption;
|
|
||||||
import com.freya02.botcommands.api.application.slash.GuildSlashEvent;
|
|
||||||
import com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand;
|
|
||||||
import net.dv8tion.jda.api.Permission;
|
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
|
||||||
import net.dv8tion.jda.api.exceptions.HierarchyException;
|
|
||||||
import net.hypr.doki.utils.DurationUtils;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.time.OffsetDateTime;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@CommandMarker
|
|
||||||
@BotPermissions(Permission.MODERATE_MEMBERS)
|
|
||||||
@UserPermissions(Permission.MODERATE_MEMBERS)
|
|
||||||
public class Timeout extends ApplicationCommand {
|
|
||||||
@JDASlashCommand(
|
|
||||||
name = "timeout",
|
|
||||||
subcommand = "set",
|
|
||||||
description = "Times out a member"
|
|
||||||
)
|
|
||||||
public void timeout(GuildSlashEvent event,
|
|
||||||
@AppOption(name = "member") Member member,
|
|
||||||
@AppOption(name = "duration", description = "ex: 2h5m, must be between 1m and 7d") String duration,
|
|
||||||
@Optional @AppOption(name = "reason") String reason) {
|
|
||||||
Duration timeoutDuration = DurationUtils.parseDuration(duration);
|
|
||||||
if (!DurationUtils.isDurationBetween(timeoutDuration, Duration.ofMinutes(1), Duration.ofDays(7))) {
|
|
||||||
event.replyFormat("Invalid duration %s!, must be between 1m and 7d", duration).queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
member.timeoutFor(timeoutDuration)
|
|
||||||
.reason(Objects.requireNonNullElse(reason, "No reason provided")).queue();
|
|
||||||
} catch (HierarchyException ex) {
|
|
||||||
event.replyFormat("Failed to time out %s (member has roles above me!)", member.getAsMention()).setEphemeral(true).queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
event.replyFormat("Timed out %s for %s", member.getAsMention(), duration).queue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@JDASlashCommand(
|
|
||||||
name = "timeout",
|
|
||||||
subcommand = "cancel",
|
|
||||||
description = "Cancels the specified users timeout"
|
|
||||||
)
|
|
||||||
public void cancelTimeout(GuildSlashEvent event,
|
|
||||||
@AppOption(name = "member") Member member,
|
|
||||||
@Optional @AppOption(name = "reason") String reason) {
|
|
||||||
OffsetDateTime timeoutEnd = member.getTimeOutEnd();
|
|
||||||
try {
|
|
||||||
member.removeTimeout()
|
|
||||||
.reason(Objects.requireNonNullElse(reason, "No reason provided")).queue();
|
|
||||||
} catch (HierarchyException ex) {
|
|
||||||
event.replyFormat("Failed to remove %s's timeout (member has roles above me!)", member.getAsMention()).setEphemeral(true).queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
event.replyFormat("Removed %s's timeout (%s remaining)", member.getAsMention(), DurationUtils.getTimeDifference(timeoutEnd)).queue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@JDASlashCommand(
|
|
||||||
name = "timeout",
|
|
||||||
subcommand = "get",
|
|
||||||
description = "Gets the specified users timeout status"
|
|
||||||
)
|
|
||||||
public void getTimeout(GuildSlashEvent event,
|
|
||||||
@AppOption(name = "member") Member member) {
|
|
||||||
if (member.isTimedOut()) {
|
|
||||||
OffsetDateTime timeoutEnd = member.getTimeOutEnd();
|
|
||||||
event.replyFormat("%s is timed out for another %s", member.getAsMention(), DurationUtils.getTimeDifference(timeoutEnd)).setEphemeral(true).queue();
|
|
||||||
} else {
|
|
||||||
event.replyFormat("%s isn't timed out!", member.getAsMention()).setEphemeral(true).queue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,55 +0,0 @@
|
||||||
package net.hypr.doki.commands.moderation;
|
|
||||||
|
|
||||||
import com.freya02.botcommands.api.annotations.BotPermissions;
|
|
||||||
import com.freya02.botcommands.api.annotations.CommandMarker;
|
|
||||||
import com.freya02.botcommands.api.annotations.UserPermissions;
|
|
||||||
import com.freya02.botcommands.api.application.ApplicationCommand;
|
|
||||||
import com.freya02.botcommands.api.application.annotations.AppOption;
|
|
||||||
import com.freya02.botcommands.api.application.slash.GuildSlashEvent;
|
|
||||||
import com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand;
|
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
|
||||||
import net.dv8tion.jda.api.Permission;
|
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
|
||||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
|
||||||
import net.hypr.doki.Doki;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
@CommandMarker
|
|
||||||
@BotPermissions(Permission.MODERATE_MEMBERS)
|
|
||||||
@UserPermissions(Permission.MODERATE_MEMBERS)
|
|
||||||
public class Warn extends ApplicationCommand {
|
|
||||||
@JDASlashCommand(
|
|
||||||
name = "warn",
|
|
||||||
description = "Warns a member"
|
|
||||||
)
|
|
||||||
public void warn(GuildSlashEvent event,
|
|
||||||
@AppOption(name = "member", description = "The member to warn") Member member,
|
|
||||||
@AppOption(name = "reason", description = "The reason for warning them") String reason) {
|
|
||||||
Logger log = Doki.getLogger();
|
|
||||||
Member actingMod = event.getMember();
|
|
||||||
EmbedBuilder warnEmbed = new EmbedBuilder()
|
|
||||||
.setTitle(String.format("You were warned in %s", event.getGuild().getName()))
|
|
||||||
.setDescription(String.format("**Reason:** %s", reason))
|
|
||||||
.setFooter(String.format("Warned by %s (%s)", actingMod.getEffectiveName(), actingMod.getId()), actingMod.getEffectiveAvatarUrl())
|
|
||||||
.setColor(new Color(239, 148, 60));
|
|
||||||
log.debug(String.format("%s", Doki.getConfig().getWarningChannel()));
|
|
||||||
TextChannel warningChannel = Doki.getJDA().getTextChannelById(Doki.getConfig().getWarningChannel());
|
|
||||||
member.getUser().openPrivateChannel().queue(
|
|
||||||
(dm) -> dm.sendMessageEmbeds(warnEmbed.build()).queue(
|
|
||||||
success -> event.replyFormat("Warned %s for %s", member.getAsMention(), reason).setEphemeral(true).queue(),
|
|
||||||
// User has blocked bot or disabled DMs
|
|
||||||
error -> event.replyFormat("Warned %s for %s\n-# (Unable to DM user)", member.getAsMention(), reason).queue()
|
|
||||||
),
|
|
||||||
error -> event.replyFormat("Warned %s for %s\n-# (Unable to DM user)", member.getAsMention(), reason).queue()
|
|
||||||
);
|
|
||||||
warnEmbed.setTitle(String.format("%s (%s) was warned", member.getEffectiveName(), member.getId()));
|
|
||||||
try {
|
|
||||||
assert warningChannel != null;
|
|
||||||
warningChannel.sendMessage(member.getAsMention()).addEmbeds(warnEmbed.build()).queue();
|
|
||||||
} catch (NullPointerException ex) {
|
|
||||||
log.warn("Failed to send message to warning log channel");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
45
src/main/java/net/hypr/doki/commands/utils/About.java
Normal file
45
src/main/java/net/hypr/doki/commands/utils/About.java
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
package net.hypr.doki.commands.utils;
|
||||||
|
|
||||||
|
import com.freya02.botcommands.api.annotations.CommandMarker;
|
||||||
|
import com.freya02.botcommands.api.prefixed.CommandEvent;
|
||||||
|
import com.freya02.botcommands.api.prefixed.TextCommand;
|
||||||
|
import com.freya02.botcommands.api.prefixed.annotations.Category;
|
||||||
|
import com.freya02.botcommands.api.prefixed.annotations.Description;
|
||||||
|
import com.freya02.botcommands.api.prefixed.annotations.JDATextCommand;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.JDA;
|
||||||
|
import net.dv8tion.jda.api.entities.SelfUser;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
@CommandMarker
|
||||||
|
@Category("Utils")
|
||||||
|
@Description("Get about info")
|
||||||
|
public class About extends TextCommand {
|
||||||
|
@JDATextCommand(name = "about", aliases = {"doki"})
|
||||||
|
public void execute(CommandEvent event) {
|
||||||
|
JDA jda = event.getJDA();
|
||||||
|
SelfUser selfUser = jda.getSelfUser();
|
||||||
|
String jdaVersion = "";
|
||||||
|
try {
|
||||||
|
Class<?> jdaClass = Class.forName("net.dv8tion.jda.api.JDA");
|
||||||
|
Package jdaPackage = jdaClass.getPackage();
|
||||||
|
if (jdaPackage != null) {
|
||||||
|
// Attempt to get Implementation-Version from the manifest
|
||||||
|
String version = jdaPackage.getImplementationVersion();
|
||||||
|
jdaVersion = version != null ? version : "Unknown";
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
jdaVersion = "UNKNOWN";
|
||||||
|
}
|
||||||
|
EmbedBuilder aboutEmbed = new EmbedBuilder()
|
||||||
|
.setTitle("About " + selfUser.getName())
|
||||||
|
.setThumbnail(selfUser.getAvatarUrl())
|
||||||
|
.setDescription("Banned from every deli nationwide")
|
||||||
|
.addField("Guilds", String.valueOf(jda.getGuildCache().stream().count()), true)
|
||||||
|
.addField("JDA Version", jdaVersion, true)
|
||||||
|
.addField("Owner", "fwoppydwisk", true)
|
||||||
|
.setColor(new Color(210,138,39));
|
||||||
|
event.reply(aboutEmbed.build()).queue();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,27 +1,21 @@
|
||||||
package net.hypr.doki.commands.utils;
|
package net.hypr.doki.commands.utils;
|
||||||
|
|
||||||
import com.freya02.botcommands.api.annotations.CommandMarker;
|
import com.freya02.botcommands.api.annotations.CommandMarker;
|
||||||
import com.freya02.botcommands.api.application.ApplicationCommand;
|
import com.freya02.botcommands.api.prefixed.CommandEvent;
|
||||||
import com.freya02.botcommands.api.application.slash.GuildSlashEvent;
|
import com.freya02.botcommands.api.prefixed.TextCommand;
|
||||||
import com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand;
|
|
||||||
import com.freya02.botcommands.api.prefixed.annotations.Category;
|
import com.freya02.botcommands.api.prefixed.annotations.Category;
|
||||||
import com.freya02.botcommands.api.prefixed.annotations.Description;
|
import com.freya02.botcommands.api.prefixed.annotations.Description;
|
||||||
|
import com.freya02.botcommands.api.prefixed.annotations.JDATextCommand;
|
||||||
|
|
||||||
@CommandMarker
|
@CommandMarker
|
||||||
@Category("Utils")
|
@Category("Utils")
|
||||||
@Description("Pong!")
|
@Description("Pong!")
|
||||||
public class Ping extends ApplicationCommand {
|
public class Ping extends TextCommand {
|
||||||
@JDASlashCommand(
|
@JDATextCommand(name = "ping")
|
||||||
name = "ping",
|
public void execute(CommandEvent event) {
|
||||||
description = "Pong!"
|
|
||||||
)
|
|
||||||
public void onPing(GuildSlashEvent event) {
|
|
||||||
event.deferReply().queue();
|
|
||||||
|
|
||||||
final long gatewayPing = event.getJDA().getGatewayPing();
|
final long gatewayPing = event.getJDA().getGatewayPing();
|
||||||
|
|
||||||
event.getJDA().getRestPing()
|
event.getJDA().getRestPing()
|
||||||
.queue(l -> event.getHook()
|
.queue(restPing -> event.respondFormat("Gateway ping: **%d ms**\nRest ping: **%d ms**", gatewayPing, restPing).queue());
|
||||||
.sendMessageFormat("Gateway ping: **%d ms**\nRest ping: **%d ms**", gatewayPing, l)
|
|
||||||
.queue());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
package net.hypr.doki.commands.utils;
|
|
||||||
|
|
||||||
import com.freya02.botcommands.api.annotations.BotPermissions;
|
|
||||||
import com.freya02.botcommands.api.annotations.CommandMarker;
|
|
||||||
import com.freya02.botcommands.api.annotations.Optional;
|
|
||||||
import com.freya02.botcommands.api.annotations.UserPermissions;
|
|
||||||
import com.freya02.botcommands.api.application.ApplicationCommand;
|
|
||||||
import com.freya02.botcommands.api.application.annotations.AppOption;
|
|
||||||
import com.freya02.botcommands.api.application.slash.GuildSlashEvent;
|
|
||||||
import com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand;
|
|
||||||
import net.dv8tion.jda.api.Permission;
|
|
||||||
import net.dv8tion.jda.api.utils.messages.MessagePollBuilder;
|
|
||||||
import net.dv8tion.jda.api.utils.messages.MessagePollData;
|
|
||||||
import net.hypr.doki.utils.DurationUtils;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@CommandMarker
|
|
||||||
@BotPermissions(Permission.MESSAGE_SEND_POLLS)
|
|
||||||
@UserPermissions(Permission.MESSAGE_MANAGE)
|
|
||||||
public class Poll extends ApplicationCommand {
|
|
||||||
@JDASlashCommand(
|
|
||||||
name = "poll",
|
|
||||||
description = "Creates a poll"
|
|
||||||
)
|
|
||||||
public void poll(GuildSlashEvent event,
|
|
||||||
@AppOption(name = "title") String pollTitle,
|
|
||||||
@AppOption(name = "duration", description = "ex: 2h, must be between 1h and 7d") String duration,
|
|
||||||
@AppOption(name = "options", description = "Comma-seperated poll options") String options,
|
|
||||||
@Optional @AppOption(name = "multiple-choice", description = "Allow multiple choices? (defaults to false)") Boolean multiChoice) {
|
|
||||||
Boolean pollMultiChoice = Objects.requireNonNullElse(multiChoice, false);
|
|
||||||
Duration pollDuration = DurationUtils.parseDuration(duration);
|
|
||||||
if (!DurationUtils.isDurationBetween(pollDuration, Duration.ofHours(1), Duration.ofDays(7))) {
|
|
||||||
event.replyFormat("Invalid duration %s!, must be between 1h and 7d", duration).queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String[] pollOptions = options.split(",");
|
|
||||||
MessagePollBuilder poll = MessagePollData.builder(pollTitle)
|
|
||||||
.setDuration(pollDuration);
|
|
||||||
for (String option: pollOptions) {
|
|
||||||
poll.addAnswer(option);
|
|
||||||
}
|
|
||||||
event.getChannel().sendMessagePoll(poll.build()).queue();
|
|
||||||
event.replyFormat("Created %s poll \"%s\" in %s which will last %s",
|
|
||||||
(pollMultiChoice) ? "multi-choice" : "single-choice",
|
|
||||||
pollTitle,
|
|
||||||
event.getChannel().getAsMention(),
|
|
||||||
duration).setEphemeral(true).queue();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,39 +1,45 @@
|
||||||
package net.hypr.doki.commands.utils;
|
package net.hypr.doki.commands.utils;
|
||||||
|
|
||||||
import com.freya02.botcommands.api.annotations.CommandMarker;
|
import com.freya02.botcommands.api.annotations.CommandMarker;
|
||||||
import com.freya02.botcommands.api.annotations.Optional;
|
import com.freya02.botcommands.api.prefixed.BaseCommandEvent;
|
||||||
import com.freya02.botcommands.api.application.ApplicationCommand;
|
import com.freya02.botcommands.api.prefixed.CommandEvent;
|
||||||
import com.freya02.botcommands.api.application.annotations.AppOption;
|
import com.freya02.botcommands.api.prefixed.TextCommand;
|
||||||
import com.freya02.botcommands.api.application.slash.GuildSlashEvent;
|
|
||||||
import com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand;
|
|
||||||
import com.freya02.botcommands.api.prefixed.annotations.Category;
|
import com.freya02.botcommands.api.prefixed.annotations.Category;
|
||||||
import com.freya02.botcommands.api.prefixed.annotations.Description;
|
import com.freya02.botcommands.api.prefixed.annotations.Description;
|
||||||
|
import com.freya02.botcommands.api.prefixed.annotations.JDATextCommand;
|
||||||
|
import com.freya02.botcommands.api.prefixed.annotations.TextOption;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
import net.dv8tion.jda.api.entities.Role;
|
import net.dv8tion.jda.api.entities.Role;
|
||||||
|
import net.dv8tion.jda.api.entities.User;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@CommandMarker
|
@CommandMarker
|
||||||
@Category("Utils")
|
@Category("Utils")
|
||||||
@Description("Get information about a user")
|
@Description("Get information about a user")
|
||||||
public class WhoIs extends ApplicationCommand {
|
public class WhoIs extends TextCommand {
|
||||||
@JDASlashCommand(
|
@JDATextCommand(name = "whois", order = 1)
|
||||||
name = "whois",
|
public void execute(BaseCommandEvent event, @TextOption(example = "<@437970062922612737>") Member user) {
|
||||||
description = "Gets information on a user"
|
EmbedBuilder whoIsEmbed = buildUserEmbed(user, (CommandEvent) event);
|
||||||
)
|
event.reply(whoIsEmbed.build()).queue();
|
||||||
public void whois(GuildSlashEvent event,
|
|
||||||
@Optional @AppOption(name = "member") Member memberParam) {
|
|
||||||
Member member;
|
|
||||||
member = Objects.requireNonNullElseGet(memberParam, event::getMember);
|
|
||||||
EmbedBuilder whoIsEmbed = buildUserEmbed(member, event);
|
|
||||||
event.replyEmbeds(whoIsEmbed.build()).queue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private EmbedBuilder buildUserEmbed(Member user, GuildSlashEvent event) {
|
@JDATextCommand(name = "whois", order = 2)
|
||||||
|
public void execute(BaseCommandEvent event, @TextOption(example = "<@437970062922612737>") User user) {
|
||||||
|
EmbedBuilder whoIsEmbed = buildUserEmbed((Member) user, (CommandEvent) event);
|
||||||
|
event.reply(whoIsEmbed.build()).queue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@JDATextCommand(name = "whois", order = 3)
|
||||||
|
public void execute(CommandEvent event) {
|
||||||
|
EmbedBuilder whoIsEmbed = buildUserEmbed(event.getMember(), event);
|
||||||
|
event.reply(whoIsEmbed.build()).queue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private EmbedBuilder buildUserEmbed(Member user, CommandEvent event) {
|
||||||
return new EmbedBuilder()
|
return new EmbedBuilder()
|
||||||
.setAuthor(user.getUser().getName(), null, user.getEffectiveAvatarUrl())
|
.setAuthor(user.getUser().getName(), null, user.getEffectiveAvatarUrl())
|
||||||
.setThumbnail(user.getEffectiveAvatarUrl())
|
.setThumbnail(user.getEffectiveAvatarUrl())
|
||||||
|
|
|
@ -1,96 +1,27 @@
|
||||||
package net.hypr.doki.utils;
|
package net.hypr.doki.utils;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.OffsetDateTime;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class DurationUtils {
|
public class DurationUtils {
|
||||||
private static final Pattern DURATION_PATTERN = Pattern.compile(
|
private static final Pattern timePattern = Pattern.compile("(\\d+)(?:([dhms]))?");
|
||||||
"(\\d+d\\s*)?(\\d+h\\s*)?(\\d+m\\s*)?(\\d+s\\s*)?");
|
public static Duration parseDuration(String input) throws IllegalArgumentException {
|
||||||
|
Matcher matcher = timePattern.matcher(input);
|
||||||
|
|
||||||
public static Duration parseDuration(String durationString) {
|
if (!matcher.matches()) {
|
||||||
durationString = durationString.trim();
|
throw new IllegalArgumentException("Invalid duration format");
|
||||||
|
|
||||||
Matcher matcher = DURATION_PATTERN.matcher(durationString);
|
|
||||||
long days = 0;
|
|
||||||
long hours = 0;
|
|
||||||
long minutes = 0;
|
|
||||||
long seconds = 0;
|
|
||||||
|
|
||||||
if (matcher.matches()) {
|
|
||||||
// Extract days if present
|
|
||||||
if (matcher.group(1) != null) {
|
|
||||||
days = Long.parseLong(matcher.group(1).replace("d", "").trim());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract hours if present
|
int value = Integer.parseInt(matcher.group(1));
|
||||||
if (matcher.group(2) != null) {
|
String unit = matcher.group(2);
|
||||||
hours = Long.parseLong(matcher.group(2).replace("h", "").trim());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extract minutes if present
|
return switch (unit == null || unit.isEmpty() ? "m" : unit.toLowerCase()) {
|
||||||
if (matcher.group(3) != null) {
|
case "d" -> Duration.ofDays(value);
|
||||||
minutes = Long.parseLong(matcher.group(3).replace("m", "").trim());
|
case "h" -> Duration.ofHours(value);
|
||||||
}
|
case "m" -> Duration.ofMinutes(value);
|
||||||
|
case "s" -> Duration.ofSeconds(value);
|
||||||
// Extract seconds if present
|
default -> throw new IllegalArgumentException("Invalid unit");
|
||||||
if (matcher.group(4) != null) {
|
};
|
||||||
seconds = Long.parseLong(matcher.group(4).replace("s", "").trim());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Duration.ofDays(days)
|
|
||||||
.plusHours(hours)
|
|
||||||
.plusMinutes(minutes)
|
|
||||||
.plusSeconds(seconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
|
||||||
public static boolean isDurationBetween(Duration target, Duration lowerThreshold, Duration upperThreshold) {
|
|
||||||
if (target == lowerThreshold || target == upperThreshold) return true;
|
|
||||||
return !target.isNegative() &&
|
|
||||||
(target.compareTo(lowerThreshold) >= 0) &&
|
|
||||||
(target.compareTo(upperThreshold) <= 0);
|
|
||||||
}
|
|
||||||
public static String getTimeDifference(OffsetDateTime offsetDateTime) {
|
|
||||||
if (offsetDateTime == null) return "0 seconds";
|
|
||||||
|
|
||||||
// Get the current Instant (current time)
|
|
||||||
Instant now = Instant.now();
|
|
||||||
|
|
||||||
// Calculate the duration between the current time and the given OffsetDateTime
|
|
||||||
Duration duration = Duration.between(now, offsetDateTime.toInstant());
|
|
||||||
|
|
||||||
// Get the difference in various units
|
|
||||||
long days = duration.toDays();
|
|
||||||
long hours = duration.toHours() % 24; // Modulo 24 to get hours within a single day
|
|
||||||
long minutes = duration.toMinutes() % 60; // Modulo 60 to get minutes within a single hour
|
|
||||||
long seconds = duration.getSeconds() % 60; // Modulo 60 to get remaining seconds
|
|
||||||
|
|
||||||
// Build the formatted time difference string
|
|
||||||
StringBuilder result = new StringBuilder();
|
|
||||||
|
|
||||||
// Append each time unit if it is non-zero
|
|
||||||
if (days > 0) {
|
|
||||||
result.append(days).append(" day").append(days > 1 ? "s" : "").append(" ");
|
|
||||||
}
|
|
||||||
if (hours > 0) {
|
|
||||||
result.append(hours).append(" hour").append(hours > 1 ? "s" : "").append(" ");
|
|
||||||
}
|
|
||||||
if (minutes > 0) {
|
|
||||||
result.append(minutes).append(" minute").append(minutes > 1 ? "s" : "").append(" ");
|
|
||||||
}
|
|
||||||
if (seconds > 0) {
|
|
||||||
result.append(seconds).append(" second").append(seconds > 1 ? "s" : "");
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the duration is zero, return "0 seconds"
|
|
||||||
if (result.isEmpty()) {
|
|
||||||
result.append("0 second");
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.toString().trim();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,18 @@
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"token": {
|
"token": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"prefix": {
|
||||||
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
"token"
|
"token",
|
||||||
|
"prefix"
|
||||||
]
|
]
|
||||||
}
|
}
|
Loading…
Reference in a new issue