diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/discord.xml b/.idea/discord.xml new file mode 100644 index 0000000..d8e9561 --- /dev/null +++ b/.idea/discord.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..82dbec8 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..529c817 --- /dev/null +++ b/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + + net.hypr + doki + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + + + net.dv8tion + JDA + 5.0.1 + + + io.github.freya022 + BotCommands + 2.10.4 + + + org.json + json + 20231013 + + + \ No newline at end of file diff --git a/src/main/java/net/hypr/doki/Config.java b/src/main/java/net/hypr/doki/Config.java new file mode 100644 index 0000000..dd9e7af --- /dev/null +++ b/src/main/java/net/hypr/doki/Config.java @@ -0,0 +1,71 @@ +package net.hypr.doki; + +import com.google.gson.Gson; + +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.nio.file.Path; + +//You can add more fields in this class, if your input json matches the structure +//You will need a valid config.json in the package com.freya02.bot for this to work +public class Config { + @SuppressWarnings("unused") private String token; + @SuppressWarnings("unused") private DBConfig dbConfig; + + /** + * Returns the configuration object for this bot + * + * @return The config + * @throws IOException if the config JSON could not be read + */ + public static Config readConfig() throws IOException { + System.out.println(Path.of("config.json")); + try (InputStream in=Thread.currentThread().getContextClassLoader().getResourceAsStream("config.json")) { + assert in != null; + Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8); + return new Gson().fromJson(reader, Config.class); + } catch (IOException e) { + throw new IOException(""" + config.json was not found in the root folder (of the project), did you forget to put it ? + Example structure: + + { + "token": "[your_bot_token_here]" + } + """, e); + } + } + + public String getToken() { + return token; + } + + public DBConfig getDbConfig() { + return dbConfig; + } + + public static class DBConfig { + @SuppressWarnings("unused") private String serverName, user, password, dbName; + @SuppressWarnings("unused") private int portNumber; + + public String getServerName() { + return serverName; + } + + public String getUser() { + return user; + } + + public String getPassword() { + return password; + } + + public String getDbName() { + return dbName; + } + + public int getPortNumber() { + return portNumber; + } + } +} \ No newline at end of file diff --git a/src/main/java/net/hypr/doki/Doki.java b/src/main/java/net/hypr/doki/Doki.java new file mode 100644 index 0000000..0ff45d9 --- /dev/null +++ b/src/main/java/net/hypr/doki/Doki.java @@ -0,0 +1,57 @@ +package net.hypr.doki; + +import com.freya02.botcommands.api.CommandsBuilder; +import com.freya02.botcommands.api.Logging; +import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.JDABuilder; +import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.requests.GatewayIntent; +import org.slf4j.Logger; + +import java.io.IOException; + +public class Doki { + private static final Logger LOGGER = Logging.getLogger(); + private static JDA jda; + private static Config config; + + private Doki(JDA jda, Config config) { + Doki.jda = jda; + Doki.config = config; + } + + public JDA getJDA() { + return jda; + } + + public static Doki start() throws IOException, InterruptedException { + config = Config.readConfig(); + + final JDA jda = JDABuilder.createLight(config.getToken()) + .setActivity(Activity.customStatus("Banned from everywhere")) + .enableIntents(GatewayIntent.MESSAGE_CONTENT) + .build() + .awaitReady(); + + //Print some information about the bot + LOGGER.info("Bot connected as {}", jda.getSelfUser().getAsTag()); + LOGGER.info("The bot is present on these guilds :"); + for (Guild guild : jda.getGuildCache()) { + LOGGER.info("\t- {} ({})", guild.getName(), guild.getId()); + } + + return new Doki(jda, config); + } + + public static void main(String[] args) { + try { + jda = start().getJDA(); + CommandsBuilder.newBuilder(437970062922612737L) + .textCommandBuilder(textCommandsBuilder -> textCommandsBuilder.addPrefix("oki!")) + .build(jda, "net.hypr.doki.commands"); //Registering listeners is taken care of by the lib + } catch (Exception e) { + LOGGER.error("Unable to start the bot", e); + System.exit(-1); + } + } +} diff --git a/src/main/java/net/hypr/doki/commands/About.java b/src/main/java/net/hypr/doki/commands/About.java new file mode 100644 index 0000000..af744ec --- /dev/null +++ b/src/main/java/net/hypr/doki/commands/About.java @@ -0,0 +1,43 @@ +package net.hypr.doki.commands; + +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.*; + +@Category("Misc") +@Description("Get about info") +public class About extends TextCommand { + @JDATextCommand(name = "about") + 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(); + } +} diff --git a/src/main/java/net/hypr/doki/commands/Ping.java b/src/main/java/net/hypr/doki/commands/Ping.java new file mode 100644 index 0000000..a6f464c --- /dev/null +++ b/src/main/java/net/hypr/doki/commands/Ping.java @@ -0,0 +1,19 @@ +package net.hypr.doki.commands; + +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; + +@Category("Misc") +@Description("Pong!") +public class Ping extends TextCommand { + @JDATextCommand(name = "ping") + public void execute(CommandEvent event) { + final long gatewayPing = event.getJDA().getGatewayPing(); + + event.getJDA().getRestPing() + .queue(restPing -> event.respondFormat("Gateway ping: **%d ms**\nRest ping: **%d ms**", gatewayPing, restPing).queue()); + } +} diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000..23480c4 --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,45 @@ + + + + + + + + + + %d{HH:mm:ss.SSS} %boldCyan(%-26.-26thread) %boldYellow(%-20.-20logger{0}) %highlight(%-6level) %msg%n%throwable + + + + + logs/latest.log + + + logs/logs-%d{yyyy-MM-dd}.log + + + 90 + 3GB + + + + %d{HH:mm:ss.SSS} %-26.-26thread %-36.-36class{36} #%-24.-24method{24} L%-5.-5line %-20.-20logger{0} %-6level %msg%n%throwable + + + + + + + + + + + + + + + + + + + \ No newline at end of file