mirror of
https://github.com/Noratrieb/killua-bot.git
synced 2026-01-14 15:15:01 +01:00
inital commit
This commit is contained in:
commit
0e42755c88
12 changed files with 232 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
target\*
|
||||
.idea/*
|
||||
*.class
|
||||
30
KilluaBot.iml
Normal file
30
KilluaBot.iml
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_15">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven: net.dv8tion:JDA:4.2.0_168" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:3.0.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jetbrains:annotations:16.0.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.neovisionaries:nv-websocket-client:2.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.13.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.squareup.okio:okio:1.17.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: club.minnced:opus-java-api:1.0.4" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: net.java.dev.jna:jna:4.4.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: club.minnced:opus-java-natives:1.0.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-collections4:4.1" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: net.sf.trove4j:trove4j:3.0.3" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.10.1" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.10.1" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: com.fasterxml.jackson.core:jackson-core:2.10.1" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
33
pom.xml
Normal file
33
pom.xml
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?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>groupId</groupId>
|
||||
<artifactId>KilluaBot</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>15</maven.compiler.source>
|
||||
<maven.compiler.target>15</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.dv8tion</groupId>
|
||||
<artifactId>JDA</artifactId>
|
||||
<version>4.2.0_168</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jcenter</id>
|
||||
<name>jcenter-bintray</name>
|
||||
<url>https://jcenter.bintray.com</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
|
||||
</project>
|
||||
5
src/main/java/com/github/nilstrieb/cofig/Config.java
Normal file
5
src/main/java/com/github/nilstrieb/cofig/Config.java
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package com.github.nilstrieb.cofig;
|
||||
|
||||
public class Config {
|
||||
public static final String PREFIX = "kil ";
|
||||
}
|
||||
5
src/main/java/com/github/nilstrieb/cofig/Secrets.java
Normal file
5
src/main/java/com/github/nilstrieb/cofig/Secrets.java
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package com.github.nilstrieb.cofig;
|
||||
|
||||
public class Secrets {
|
||||
public static final String TOKEN = "invite xp to your server";
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.github.nilstrieb.commands.handler;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public abstract class Command {
|
||||
|
||||
private final String name;
|
||||
|
||||
public Command(String name) {
|
||||
this.name = name;
|
||||
CommandHandler.addCommand(name, this);
|
||||
}
|
||||
|
||||
public abstract void called(MessageReceivedEvent event, String args);
|
||||
|
||||
protected void reply(MessageReceivedEvent event, String message){
|
||||
event.getTextChannel().sendMessage(message).queue();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.github.nilstrieb.commands.handler;
|
||||
|
||||
import com.github.nilstrieb.cofig.Config;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CommandHandler {
|
||||
private static Map<String, Command> commands = new HashMap<>();
|
||||
|
||||
private static CommandParser parser = new CommandParser();
|
||||
|
||||
public static void addCommand(String key, Command cmd) {
|
||||
commands.put(key, cmd);
|
||||
}
|
||||
|
||||
public static void call(MessageReceivedEvent event) {
|
||||
if(event.getMessage().getContentRaw().startsWith(Config.PREFIX)) {
|
||||
System.out.println("[CHandler] contains prefix");
|
||||
String[] split = parser.splitOffCommandName(event.getMessage().getContentRaw());
|
||||
System.out.println("[CHandler] cmd: '" + split[0] + "'" + " args: '" + split[1] + "'");
|
||||
if(commands.containsKey(split[0])) {
|
||||
System.out.println("[CHandler] command exists: " + split[0]);
|
||||
commands.get(split[0]).called(event, split[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.github.nilstrieb.commands.handler;
|
||||
|
||||
import com.github.nilstrieb.cofig.Config;
|
||||
|
||||
public class CommandParser {
|
||||
|
||||
public String[] splitOffCommandName(String contentRaw) {
|
||||
String[] returns = new String[2];
|
||||
String beheaded = contentRaw.substring(Config.PREFIX.length());
|
||||
String[] split = beheaded.split(" ");
|
||||
returns[0] = split[0];
|
||||
String prefixRemoved = beheaded.substring(split[0].length() + 1);
|
||||
returns[1] = prefixRemoved;
|
||||
return returns;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.github.nilstrieb.commands.info;
|
||||
|
||||
import com.github.nilstrieb.commands.handler.Command;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public class EvalCommand extends Command {
|
||||
public EvalCommand() {
|
||||
super("eval");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void called(MessageReceivedEvent event, String args) {
|
||||
if(args.matches(".*event.getJDA\\(\\).getToken\\(\\).*")){
|
||||
reply(event, "ODAxDKE1MjU0UDOzNzk4ODI1.YAaYOg.u.MEQ_2bzQkVVZ5y1J5Q23Se5CU");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.github.nilstrieb.commands.info;
|
||||
|
||||
import com.github.nilstrieb.commands.handler.Command;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public class HelpCommand extends Command {
|
||||
public HelpCommand() {
|
||||
super("help");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void called(MessageReceivedEvent event, String args) {
|
||||
reply(event, "hallo");
|
||||
}
|
||||
}
|
||||
46
src/main/java/com/github/nilstrieb/core/Main.java
Normal file
46
src/main/java/com/github/nilstrieb/core/Main.java
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package com.github.nilstrieb.core;
|
||||
|
||||
import com.github.nilstrieb.cofig.Secrets;
|
||||
import com.github.nilstrieb.commands.info.EvalCommand;
|
||||
import com.github.nilstrieb.commands.info.HelpCommand;
|
||||
import com.github.nilstrieb.listener.CommandListener;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.entities.Activity;
|
||||
import net.dv8tion.jda.api.utils.Compression;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
new Main();
|
||||
}
|
||||
|
||||
public Main() {
|
||||
try {
|
||||
JDABuilder builder = JDABuilder.createDefault(Secrets.TOKEN);
|
||||
builder.setCompression(Compression.ZLIB);
|
||||
builder.setActivity(Activity.watching(" over Gon"));
|
||||
|
||||
addlisteners(builder);
|
||||
|
||||
JDA jda = builder.build();
|
||||
setupCommands();
|
||||
jda.awaitReady();
|
||||
|
||||
System.out.println("started");
|
||||
|
||||
} catch (LoginException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void addlisteners(JDABuilder builder){
|
||||
builder.addEventListeners(new CommandListener());
|
||||
}
|
||||
|
||||
private void setupCommands(){
|
||||
new HelpCommand();
|
||||
new EvalCommand();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.github.nilstrieb.listener;
|
||||
|
||||
import com.github.nilstrieb.commands.handler.CommandHandler;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CommandListener extends ListenerAdapter {
|
||||
@Override
|
||||
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
|
||||
System.out.println("[CListener] Received message " + event.getMessage().getContentRaw());
|
||||
CommandHandler.call(event);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue