-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0a4134f
Showing
16 changed files
with
660 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea/modules.xml | ||
.idea/jarRepositories.xml | ||
.idea/compiler.xml | ||
.idea/discord.xml | ||
.idea/encodings.xml | ||
.idea/misc.xml | ||
.idea/vcs.xml | ||
.idea/libraries/ | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### Intellij ### | ||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider | ||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 | ||
|
||
# User-specific stuff | ||
.idea/**/workspace.xml | ||
.idea/**/tasks.xml | ||
.idea/**/usage.statistics.xml | ||
.idea/**/dictionaries | ||
.idea/**/shelf | ||
|
||
# AWS User-specific | ||
.idea/**/aws.xml | ||
|
||
# Generated files | ||
.idea/**/contentModel.xml | ||
|
||
# Sensitive or high-churn files | ||
.idea/**/dataSources/ | ||
.idea/**/dataSources.ids | ||
.idea/**/dataSources.local.xml | ||
.idea/**/sqlDataSources.xml | ||
.idea/**/dynamic.xml | ||
.idea/**/uiDesigner.xml | ||
.idea/**/dbnavigator.xml | ||
|
||
# Gradle | ||
.idea/**/gradle.xml | ||
.idea/**/libraries | ||
|
||
# Gradle and Maven with auto-import | ||
# When using Gradle or Maven with auto-import, you should exclude module files, | ||
# since they will be recreated, and may cause churn. Uncomment if using | ||
# auto-import. | ||
# .idea/artifacts | ||
# .idea/compiler.xml | ||
# .idea/jarRepositories.xml | ||
# .idea/modules.xml | ||
# .idea/*.iml | ||
# .idea/modules | ||
# *.iml | ||
# *.ipr | ||
|
||
# CMake | ||
cmake-build-*/ | ||
|
||
# Mongo Explorer plugin | ||
.idea/**/mongoSettings.xml | ||
|
||
# File-based project format | ||
*.iws | ||
|
||
# IntelliJ | ||
out/ | ||
|
||
# mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
# JIRA plugin | ||
atlassian-ide-plugin.xml | ||
|
||
# Cursive Clojure plugin | ||
.idea/replstate.xml | ||
|
||
# SonarLint plugin | ||
.idea/sonarlint/ | ||
|
||
# Crashlytics plugin (for Android Studio and IntelliJ) | ||
com_crashlytics_export_strings.xml | ||
crashlytics.properties | ||
crashlytics-build.properties | ||
fabric.properties | ||
|
||
# Editor-based Rest Client | ||
.idea/httpRequests | ||
|
||
# Android studio 3.1+ serialized cache file | ||
.idea/caches/build_file_checksums.ser | ||
|
||
### Intellij Patch ### | ||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 | ||
|
||
# *.iml | ||
# modules.xml | ||
# .idea/misc.xml | ||
# *.ipr | ||
|
||
# Sonarlint plugin | ||
# https://plugins.jetbrains.com/plugin/7973-sonarlint | ||
.idea/**/sonarlint/ | ||
|
||
# SonarQube Plugin | ||
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin | ||
.idea/**/sonarIssues.xml | ||
|
||
# Markdown Navigator plugin | ||
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced | ||
.idea/**/markdown-navigator.xml | ||
.idea/**/markdown-navigator-enh.xml | ||
.idea/**/markdown-navigator/ | ||
|
||
# Cache file creation bug | ||
# See https://youtrack.jetbrains.com/issue/JBR-2257 | ||
.idea/$CACHE_FILE$ | ||
|
||
# CodeStream plugin | ||
# https://plugins.jetbrains.com/plugin/12206-codestream | ||
.idea/codestream.xml | ||
|
||
# Azure Toolkit for IntelliJ plugin | ||
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij | ||
.idea/**/azureSettings.xml | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
|
||
# Neptune | ||
|
||
An annotation-based slash command framework for JDA. | ||
|
||
## How to Use | ||
|
||
To start the framework, run: | ||
|
||
```java | ||
Neptune.start(jda, this); | ||
``` | ||
|
||
Slash commands can take up to an hour to update globally. If you'd prefer to update a specific guild (which is instant), start Neptune like this instead: | ||
|
||
```java | ||
Neptune.start(jda, guild, this); | ||
``` | ||
Or for multiple guilds: | ||
```java | ||
Neptune.start(jda, new Guild[]{guild1, guild2}, this); | ||
``` | ||
|
||
Below is a working example of how to register a slash command. Use the @Command annotation and specify the command name, description and the required permissions. | ||
|
||
Attach a method, with any name, with SlashCommandInteractionEvent as the first parameter. This holds all of the slash command event data and where you can respond to the event hook. The following parameters will define the command arguments and their order. Allowed parameter types are Integer, String, Boolean, Double, User, Role, Channel and Attachment. For an optional argument, annotate with @Optional, and ensure to null check the value when returned. | ||
|
||
> This example will register "/ban <user> [reason]". | ||
```java | ||
@Command( | ||
name = "ban", | ||
description = "Ban a member", | ||
permissions = {Permission.MANAGE_CHANNEL, Permission.ADMINISTRATOR} | ||
) | ||
public void onBan(SlashCommandInteractionEvent event, User user, @Optional String reason) { | ||
|
||
} | ||
``` | ||
Once a command is run, the method will return all values. As default slash command behaviour dictates, you will have 3 seconds to respond to the command through SlashCommandInteractionEvent. See the JDA wiki for [more info](https://github.com/DV8FromTheWorld/JDA/wiki/Interactions). | ||
|
||
To unregister a command, simply remove any @Command reference to it and restart your Bot. It will automatically unregister globally/on the guild(s). | ||
|
||
You can place your commands in any class within your package. It is important to **not instantiate classes which contain @Command** (except your main class, which we know exists), Neptune will do it. If you need data or outside variables in your command classes, we offer a similar system to Spring Boot. In your main class (the one you passed into Neptune#start) you can setup a variable to be accessable across your project using: | ||
|
||
```java | ||
@Instantiate | ||
public TestClass testClass() { return new TestClass(); } | ||
``` | ||
That object will then be accessible across your whole project. To use it elsewhere, create a variable with an identical name to the method and Neptune will beam the value through, as seen below: | ||
```java | ||
@Inject | ||
private TestClass testClass; | ||
``` | ||
|
||
To stop Neptune, you can run: | ||
```java | ||
Neptune.terminate(); | ||
``` | ||
|
||
If you struggle with anything, there is a working example in the test folder. | ||
|
||
## Installation | ||
|
||
Maven | ||
|
||
Gradle | ||
|
||
## Contributing | ||
|
||
Contributions are always welcome. Please open a pull request and try to maintain a similar code quality and style. | ||
|
||
|
||
## Authors | ||
|
||
This framework was made for the team at [Virtual Ventures](https://virtualventures.io), but I decided to release it in case anyone found any use from it. | ||
|
||
|
||
|
||
- Created by [Stephen (sttephen)](https://www.github.com/sttephen) | ||
|
||
|
||
## License | ||
|
||
Do what you want, I don't care. Good luck on your projects. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?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>gg.stephen</groupId> | ||
<artifactId>Neptune</artifactId> | ||
<version>1.0</version> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>net.dv8tion</groupId> | ||
<artifactId>JDA</artifactId> | ||
<version>5.0.0-alpha.22</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.reflections</groupId> | ||
<artifactId>reflections</artifactId> | ||
<version>0.9.11</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.thoughtworks.paranamer</groupId> | ||
<artifactId>paranamer</artifactId> | ||
<version>2.8</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
<version>31.1-jre</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package gg.stephen.neptune; | ||
|
||
import gg.stephen.neptune.command.CommandDispatcher; | ||
import gg.stephen.neptune.command.CommandManager; | ||
import net.dv8tion.jda.api.JDA; | ||
import net.dv8tion.jda.api.entities.Guild; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
|
||
public class Neptune { | ||
|
||
private static JDA jda; | ||
private static CommandManager manager; | ||
|
||
private Neptune(JDA jda, Guild[] guilds, Object clazz) { | ||
this.jda = jda; | ||
jda.addEventListener(manager = new CommandManager()); | ||
try { | ||
new CommandDispatcher(jda, guilds, clazz, manager); | ||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException x) { | ||
System.out.println("[Neptune] Error registering commands. Did you read the README.md?"); | ||
x.printStackTrace(); | ||
} | ||
} | ||
|
||
public static Neptune start(JDA jda, Object clazz) { return new Neptune(jda, null, clazz); } | ||
|
||
public static Neptune start(JDA jda, Guild guild, Object clazz) { return new Neptune(jda, new Guild[]{guild}, clazz); } | ||
|
||
public static Neptune start(JDA jda, Guild[] guilds, Object clazz) { return new Neptune(jda, guilds, clazz); } | ||
|
||
public static void terminate() { | ||
jda.removeEventListener(manager); | ||
manager.terminate(); | ||
System.gc(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package gg.stephen.neptune.annotation; | ||
|
||
import net.dv8tion.jda.api.Permission; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Command { | ||
|
||
String name(); | ||
|
||
String description() default ""; | ||
|
||
Permission[] permissions() default {}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package gg.stephen.neptune.annotation; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@SuppressWarnings("unused") | ||
public @interface Inject { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package gg.stephen.neptune.annotation; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Instantiate { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package gg.stephen.neptune.annotation; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Optional { | ||
} |
Oops, something went wrong.