Let there be bugs
This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
|||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea/modules.xml
|
||||||
|
.idea/jarRepositories.xml
|
||||||
|
.idea/compiler.xml
|
||||||
|
.idea/libraries/
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
### Mac OS ###
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
noted.properties
|
||||||
Generated
+8
@@ -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
|
||||||
Generated
+14
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="graalvm-ce-21" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>me.youhavetrouble.noted</groupId>
|
||||||
|
<artifactId>Noted</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
|
<maven.compiler.target>21</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.6.0</version>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-transform-maven-shade-plugin-extensions</artifactId>
|
||||||
|
<version>0.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
<shadedArtifactAttached>true</shadedArtifactAttached>
|
||||||
|
<transformers>
|
||||||
|
<transformer implementation="org.apache.logging.log4j.maven.plugins.shade.transformer.Log4j2PluginCacheFileTransformer"/>
|
||||||
|
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
|
||||||
|
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
|
<mainClass>me.youhavetrouble.noted.Main</mainClass>
|
||||||
|
<manifestEntries>
|
||||||
|
<Multi-Release>true</Multi-Release>
|
||||||
|
</manifestEntries>
|
||||||
|
</transformer>
|
||||||
|
</transformers>
|
||||||
|
<finalName>Noted</finalName>
|
||||||
|
<filters>
|
||||||
|
<filter>
|
||||||
|
<artifact>*:*</artifact>
|
||||||
|
<excludes>
|
||||||
|
<exclude>META-INF/*.SF</exclude>
|
||||||
|
<exclude>META-INF/*.DSA</exclude>
|
||||||
|
<exclude>META-INF/*.RSA</exclude>
|
||||||
|
</excludes>
|
||||||
|
</filter>
|
||||||
|
</filters>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.dv8tion</groupId>
|
||||||
|
<artifactId>JDA</artifactId>
|
||||||
|
<version>5.0.1</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>club.minnced</groupId>
|
||||||
|
<artifactId>opus-java</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package me.youhavetrouble.noted;
|
||||||
|
|
||||||
|
import net.dv8tion.jda.api.JDA;
|
||||||
|
import net.dv8tion.jda.api.JDABuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.Activity;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.Commands;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||||
|
import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
private static final Properties properties = new Properties();
|
||||||
|
public static JDA jda;
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
loadProperties();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
jda = JDABuilder.createLight(properties.getProperty("DISCORD_TOKEN"), Collections.emptyList())
|
||||||
|
.setCallbackPool(Executors.newVirtualThreadPerTaskExecutor())
|
||||||
|
.setActivity(Activity.customStatus("Notekeeping..."))
|
||||||
|
.addEventListeners(new SlashCommandListener())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
jda.awaitReady();
|
||||||
|
|
||||||
|
CommandListUpdateAction commands = jda.updateCommands();
|
||||||
|
commands = commands.addCommands(
|
||||||
|
Commands.slash("note", "Get a note")
|
||||||
|
.addOptions(
|
||||||
|
new OptionData(OptionType.STRING, "note-id", "The ID of the note").setRequired(true),
|
||||||
|
new OptionData(OptionType.BOOLEAN, "ephermeal", "Whether the note should be ephermal").setRequired(false)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
commands.queue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void loadProperties() {
|
||||||
|
saveDefaultProperties();
|
||||||
|
try (InputStream inputStream = new FileInputStream("noted.properties")) {
|
||||||
|
properties.load(inputStream);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void saveDefaultProperties() {
|
||||||
|
File file = new File("noted.properties");
|
||||||
|
if (file.exists()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try (InputStream resource = Main.class.getClassLoader().getResourceAsStream("noted.properites");
|
||||||
|
OutputStream outputStream = new FileOutputStream(file)) {
|
||||||
|
if (resource == null) {
|
||||||
|
System.err.println("Default noted.properties missing.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
outputStream.write(resource.readAllBytes());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package me.youhavetrouble.noted;
|
||||||
|
|
||||||
|
import me.youhavetrouble.noted.note.Note;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
||||||
|
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction;
|
||||||
|
|
||||||
|
public class SlashCommandListener extends ListenerAdapter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
|
||||||
|
switch (event.getName()) {
|
||||||
|
case "note" -> {
|
||||||
|
OptionMapping noteIdOption = event.getOption("content");
|
||||||
|
OptionMapping ephemeralOption = event.getOption("ephemeral");
|
||||||
|
if (noteIdOption == null) {
|
||||||
|
event.reply("Please provide a note ID.").setEphemeral(true).queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Note note = new Note(
|
||||||
|
"Note Title",
|
||||||
|
null,
|
||||||
|
"Test Note content",
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
ReplyCallbackAction action = event.replyEmbeds(note.toEmbed());
|
||||||
|
if (ephemeralOption != null && ephemeralOption.getAsBoolean()) {
|
||||||
|
action = action.setEphemeral(true);
|
||||||
|
}
|
||||||
|
action.queue();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
default -> {
|
||||||
|
event.reply("Unknown command.").setEphemeral(true).queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package me.youhavetrouble.noted.note;
|
||||||
|
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import java.awt.Color;
|
||||||
|
|
||||||
|
public record Note(
|
||||||
|
@NotNull String title,
|
||||||
|
@Nullable String titleUrl,
|
||||||
|
@NotNull String content,
|
||||||
|
@Nullable String imageUrl,
|
||||||
|
@Nullable String thumbnailUrl,
|
||||||
|
@Nullable Color color,
|
||||||
|
@Nullable String author,
|
||||||
|
@Nullable String authorUrl,
|
||||||
|
@Nullable String footer,
|
||||||
|
@Nullable String footerUrl
|
||||||
|
) {
|
||||||
|
|
||||||
|
public MessageEmbed toEmbed() {
|
||||||
|
return new EmbedBuilder()
|
||||||
|
.setTitle(title, titleUrl)
|
||||||
|
.setDescription(content)
|
||||||
|
.setImage(imageUrl)
|
||||||
|
.setThumbnail(thumbnailUrl)
|
||||||
|
.setAuthor(author, authorUrl)
|
||||||
|
.setFooter(footer, footerUrl)
|
||||||
|
.setColor(color)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
DISCORD_TOKEN=your_bot_token_here
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
${artifactId}-${version}
|
||||||
Reference in New Issue
Block a user