feat: added music bot features, added console commands
This commit is contained in:
parent
a1f7951c03
commit
793de28215
46 changed files with 1091 additions and 259 deletions
|
@ -8,12 +8,14 @@ version = "0.1.0-alpha"
|
|||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://m2.dv8tion.net/releases")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
|
||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1")
|
||||
implementation("net.dv8tion:JDA:5.0.0-alpha.20")
|
||||
implementation("com.sedmelluq:lavaplayer:1.3.77")
|
||||
implementation("org.slf4j:slf4j-api:2.0.3")
|
||||
implementation("org.slf4j:slf4j-simple:2.0.3")
|
||||
}
|
||||
|
||||
tasks.getByName<Test>("test") {
|
||||
|
@ -37,7 +39,9 @@ tasks.withType<Jar> {
|
|||
tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
|
||||
dependencies {
|
||||
include(dependency("net.dv8tion:JDA:5.0.0-alpha.20"))
|
||||
//include(dependency("com.sedmelluq:lavaplayer:1.3.77"))
|
||||
include(dependency("com.sedmelluq:lavaplayer:1.3.77"))
|
||||
include(dependency("org.slf4j:slf4j-api:2.0.3"))
|
||||
include(dependency("org.slf4j:slf4j-simple:2.0.3"))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package de.limited_dev.lil_judd;
|
||||
|
||||
import de.limited_dev.lil_judd.commands.components.CommandManager;
|
||||
import de.limited_dev.lil_judd.features.MapManager;
|
||||
import de.limited_dev.lil_judd.features.TimePlanner;
|
||||
import de.limited_dev.lil_judd.consolecommand.component.ConsoleCommandManager;
|
||||
import de.limited_dev.lil_judd.jdacommands.components.JDACommandManager;
|
||||
import de.limited_dev.lil_judd.features.maps.MapManager;
|
||||
import de.limited_dev.lil_judd.features.planner.TimePlanner;
|
||||
import de.limited_dev.lil_judd.features.storage.GuildTimePlannerStorage;
|
||||
import de.limited_dev.lil_judd.listeners.GuildStateListener;
|
||||
import de.limited_dev.lil_judd.listeners.ReadyListener;
|
||||
|
@ -25,32 +26,30 @@ public class Main {
|
|||
lgr.info("li'l Judd is waking up ...");
|
||||
|
||||
launchTime = System.currentTimeMillis();
|
||||
|
||||
tokenManager.load();
|
||||
|
||||
|
||||
jda = JDABuilder.createDefault(tokenManager.getToken())
|
||||
.setActivity(Activity.watching("You"))
|
||||
.setStatus(OnlineStatus.DO_NOT_DISTURB)
|
||||
.enableIntents(GatewayIntent.GUILD_MEMBERS)
|
||||
.build();
|
||||
|
||||
CommandManager.registerCommands();
|
||||
MapManager.registerMaps();
|
||||
|
||||
jda.addEventListener(new ReadyListener());
|
||||
jda.addEventListener(new SlashCommandInteractionListener());
|
||||
jda.addEventListener(new GuildStateListener());
|
||||
|
||||
|
||||
GuildTimePlannerStorage.getInstance().load();
|
||||
TimePlanner.registerMessageThread();
|
||||
|
||||
try {
|
||||
jda.awaitReady();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
MapManager.registerMaps();
|
||||
GuildTimePlannerStorage.getInstance().load();
|
||||
TimePlanner.registerMessageThread();
|
||||
JDACommandManager.registerCommands();
|
||||
ConsoleCommandManager.registerCommands();
|
||||
ConsoleCommandManager.registerListener();
|
||||
}
|
||||
|
||||
public static JDA getJda() {
|
||||
|
@ -61,6 +60,10 @@ public class Main {
|
|||
return lgr;
|
||||
}
|
||||
|
||||
public static long getUptime(){
|
||||
return System.currentTimeMillis() - launchTime;
|
||||
}
|
||||
|
||||
public static long getLaunchTime() {
|
||||
return launchTime;
|
||||
}
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
package de.limited_dev.lil_judd.commands;
|
||||
|
||||
import de.limited_dev.lil_judd.commands.components.Command;
|
||||
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
|
||||
public class InfoCommand extends Command {
|
||||
public InfoCommand() {
|
||||
super("info");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event,
|
||||
"Bot information","I'm li'l Judd.\nI was created to help you & your Splatoon competitive Team.\nContact me with \"/\"-commands",
|
||||
"https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fvignette.wikia.nocookie.net%2Fsplatoon%2Fimages%2Fa%2Fa3%2FLittle_Judd_Animated.gif%2Frevision%2Flatest%3Fcb%3D20170605172120&f=1&nofb=1&ipt=f6197a3fdaf8bd6755347ba4e4c67a91320ff047969a9fa1ef4ee3bc88840ffe&ipo=images");
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package de.limited_dev.lil_judd.commands.components;
|
||||
|
||||
import de.limited_dev.lil_judd.commands.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class CommandManager {
|
||||
|
||||
private static List<Command> commands = new CopyOnWriteArrayList<>();
|
||||
|
||||
public static void registerCommands(){
|
||||
commands.add(new PingCommand());
|
||||
commands.add(new InfoCommand());
|
||||
commands.add(new SetupFeatureCommand());
|
||||
commands.add(new RemoveFeatureCommand());
|
||||
commands.add(new SearchScrimCommand());
|
||||
commands.add(new EndScrimCommand());
|
||||
commands.add(new MessageScrimCommand());
|
||||
commands.add(new ScrimInfoCommand());
|
||||
commands.add(new TranslateCommand());
|
||||
}
|
||||
|
||||
public static List<Command> getCommands() {
|
||||
return commands;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package de.limited_dev.lil_judd.consolecommand.component;
|
||||
|
||||
import de.limited_dev.lil_judd.Main;
|
||||
import de.limited_dev.lil_judd.util.Logger;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
|
||||
public class ConsoleCommand {
|
||||
private final String name;
|
||||
private final String description;
|
||||
private final String[] args;
|
||||
protected final Logger lgr = Main.getLgr();
|
||||
protected final JDA jda = Main.getJda();
|
||||
|
||||
public ConsoleCommand(String name, String description, String[] args){
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
public void onCommand(String[] args){
|
||||
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String[] getArgs() {
|
||||
return args;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package de.limited_dev.lil_judd.consolecommand.component;
|
||||
|
||||
import de.limited_dev.lil_judd.Main;
|
||||
import de.limited_dev.lil_judd.consolecommand.system.ShutdownCommand;
|
||||
import de.limited_dev.lil_judd.consolecommand.util.HelpConsoleCommand;
|
||||
import de.limited_dev.lil_judd.consolecommand.util.ManualCommand;
|
||||
import de.limited_dev.lil_judd.util.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ConsoleCommandManager {
|
||||
private static List<ConsoleCommand> commands = new ArrayList<>();
|
||||
private static final Logger lgr = Main.getLgr();
|
||||
|
||||
public static void registerCommands(){
|
||||
commands.add(new ShutdownCommand());
|
||||
commands.add(new HelpConsoleCommand());
|
||||
commands.add(new ManualCommand());
|
||||
}
|
||||
|
||||
public static void registerListener(){
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
while(true){
|
||||
if(handleConsoleInput()){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
public static boolean handleConsoleInput(){
|
||||
Scanner in = new Scanner(System.in);
|
||||
String input = in.nextLine();
|
||||
lgr.info("Console input: " + input);
|
||||
String[] commandArr = getCommandArray(input);
|
||||
String command = commandArr[0];
|
||||
String[] args = getArgumentsFromCommandArray(commandArr);
|
||||
for(ConsoleCommand c : commands){
|
||||
if(Objects.equals(c.getName(), command)){
|
||||
c.onCommand(args);
|
||||
}
|
||||
}
|
||||
if(Objects.equals("shutdown", command)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String[] getCommandArray(String command) {
|
||||
return command.split(" ", 0);
|
||||
}
|
||||
|
||||
private static String[] getArgumentsFromCommandArray(String[] commandArr) {
|
||||
String[] args = new String[commandArr.length - 1];
|
||||
for (int i = 1, j = 0; i < commandArr.length; i++) {
|
||||
args[j++] = commandArr[i];
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
public static ConsoleCommand getCommand(String name){
|
||||
for(ConsoleCommand c : commands){
|
||||
if(Objects.equals(c.getName(), name))
|
||||
return c;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<ConsoleCommand> getCommands() {
|
||||
return commands;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package de.limited_dev.lil_judd.consolecommand.system;
|
||||
|
||||
import de.limited_dev.lil_judd.consolecommand.component.ConsoleCommand;
|
||||
import de.limited_dev.lil_judd.features.planner.TimePlanner;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.GuildVoiceState;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.managers.AudioManager;
|
||||
|
||||
public class ShutdownCommand extends ConsoleCommand {
|
||||
public ShutdownCommand() {
|
||||
super("shutdown", "Shut the bot down", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(String[] args) {
|
||||
lgr.consoleOut("Shutting down...");
|
||||
for(Guild g : jda.getSelfUser().getMutualGuilds()){
|
||||
Member self = g.getSelfMember();
|
||||
GuildVoiceState selfState = self.getVoiceState();
|
||||
if(selfState.inAudioChannel()){
|
||||
AudioManager audioManager = g.getAudioManager();
|
||||
lgr.consoleOut("Leaving VC " + audioManager.getConnectedChannel().asVoiceChannel().getName() + " in " + g.getName());
|
||||
audioManager.closeAudioConnection();
|
||||
}
|
||||
}
|
||||
TimePlanner.sceduThr.interrupt();
|
||||
TimePlanner.schedulerFirstLesson.shutdown();
|
||||
jda.shutdown();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package de.limited_dev.lil_judd.consolecommand.util;
|
||||
|
||||
import de.limited_dev.lil_judd.consolecommand.component.ConsoleCommand;
|
||||
import de.limited_dev.lil_judd.consolecommand.component.ConsoleCommandManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class HelpConsoleCommand extends ConsoleCommand {
|
||||
public HelpConsoleCommand() {
|
||||
super("help", "Shows all commands", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(String[] args) {
|
||||
String out = "List of available console commands:\n";
|
||||
List<ConsoleCommand> commandList = ConsoleCommandManager.getCommands();
|
||||
for(int i = 0; i < commandList.size(); ++i){
|
||||
out = out + commandList.get(i).getName() + (i == commandList.size() - 1 ? "" : ",");
|
||||
}
|
||||
lgr.consoleOut(out);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package de.limited_dev.lil_judd.consolecommand.util;
|
||||
|
||||
import de.limited_dev.lil_judd.consolecommand.component.ConsoleCommand;
|
||||
import de.limited_dev.lil_judd.consolecommand.component.ConsoleCommandManager;
|
||||
|
||||
public class ManualCommand extends ConsoleCommand {
|
||||
public ManualCommand() {
|
||||
super("man", "Show the correct usage of a command & its description", new String[]{"Command Name"});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(String[] args) {
|
||||
if(args.length != 1){
|
||||
sendUsage(this.getName());
|
||||
return;
|
||||
}
|
||||
String commandName = args[0];
|
||||
sendUsage(commandName.toLowerCase());
|
||||
}
|
||||
|
||||
private void sendUsage(String commandName){
|
||||
ConsoleCommand command = ConsoleCommandManager.getCommand(commandName);
|
||||
if(command == null){
|
||||
sendUsage(this.getName());
|
||||
return;
|
||||
}
|
||||
String out = "Command: " + command.getName() + " = " + command.getDescription() + "";
|
||||
lgr.consoleOut(out);
|
||||
|
||||
out = "Usage: " + commandName;
|
||||
if(command.getArgs() == null){
|
||||
lgr.consoleOut(out);
|
||||
return;
|
||||
}
|
||||
out = out + (command.getArgs().length == 0 ? "" : " ");
|
||||
for(int i = 0; i < command.getArgs().length; ++i){
|
||||
out = out + "<" + command.getArgs()[i] + ">" + (command.getArgs().length - 1 == i ? "" : " ");
|
||||
}
|
||||
lgr.consoleOut(out);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package de.limited_dev.lil_judd.features;
|
||||
package de.limited_dev.lil_judd.features.maps;
|
||||
|
||||
import de.limited_dev.lil_judd.features.components.maps.MapData;
|
||||
import de.limited_dev.lil_judd.features.maps.components.MapData;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
@ -25,9 +25,9 @@ public class MapManager {
|
|||
|
||||
public static MapData getMapData(String name) {
|
||||
for (MapData md : maps) {
|
||||
if (md.equalsDEName(name))
|
||||
if (md.startsWithDEName(name))
|
||||
return md;
|
||||
if (md.equalsENName(name))
|
||||
if (md.startsWithENName(name))
|
||||
return md;
|
||||
}
|
||||
return null;
|
|
@ -1,4 +1,4 @@
|
|||
package de.limited_dev.lil_judd.features.components.maps;
|
||||
package de.limited_dev.lil_judd.features.maps.components;
|
||||
|
||||
public class MapData {
|
||||
private final String nameDE;
|
||||
|
@ -15,6 +15,14 @@ public class MapData {
|
|||
return this.nameDE.toLowerCase().equals(str);
|
||||
}
|
||||
|
||||
public boolean startsWithDEName(String str){
|
||||
return this.nameDE.startsWith(str);
|
||||
}
|
||||
|
||||
public boolean startsWithENName(String str){
|
||||
return this.nameEN.startsWith(str);
|
||||
}
|
||||
|
||||
public boolean equalsENName(String str) {
|
||||
return this.nameEN.toLowerCase().equals(str);
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package de.limited_dev.lil_judd.features.music;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
import com.sedmelluq.discord.lavaplayer.track.playback.MutableAudioFrame;
|
||||
import net.dv8tion.jda.api.audio.AudioSendHandler;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class AudioPlayerSendHandler implements AudioSendHandler {
|
||||
private final AudioPlayer audioPlayer;
|
||||
private final ByteBuffer buffer;
|
||||
private final MutableAudioFrame frame;
|
||||
|
||||
public AudioPlayerSendHandler(AudioPlayer audioPlayer) {
|
||||
this.audioPlayer = audioPlayer;
|
||||
this.buffer = ByteBuffer.allocate(1024);
|
||||
this.frame = new MutableAudioFrame();
|
||||
this.frame.setBuffer(buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvide() {
|
||||
return this.audioPlayer.provide(this.frame);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuffer provide20MsAudio() {
|
||||
return this.buffer.flip();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpus() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package de.limited_dev.lil_judd.features.music;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
|
||||
|
||||
public class GuildMusicManager {
|
||||
public final AudioPlayer audioPlayer;
|
||||
public final TrackScheduler scheduler;
|
||||
private final AudioPlayerSendHandler sendHandler;
|
||||
public GuildMusicManager(AudioPlayerManager manager){
|
||||
this.audioPlayer = manager.createPlayer();
|
||||
this.scheduler = new TrackScheduler(this.audioPlayer);
|
||||
this.audioPlayer.addListener(this.scheduler);
|
||||
this.sendHandler = new AudioPlayerSendHandler(this.audioPlayer);
|
||||
}
|
||||
|
||||
public AudioPlayerSendHandler getSendHandler() {
|
||||
return sendHandler;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package de.limited_dev.lil_judd.features.music;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
|
||||
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
|
||||
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
|
||||
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
|
||||
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
|
||||
import de.limited_dev.lil_judd.util.TimeUtil;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MusicManager {
|
||||
|
||||
private static MusicManager instance;
|
||||
|
||||
private final AudioPlayerManager playerManager;
|
||||
private final Map<Long, GuildMusicManager> musicManagerMap;
|
||||
public MusicManager(){
|
||||
this.playerManager = new DefaultAudioPlayerManager();
|
||||
this.musicManagerMap = new HashMap<>();
|
||||
|
||||
|
||||
AudioSourceManagers.registerRemoteSources(this.playerManager);
|
||||
AudioSourceManagers.registerLocalSource(this.playerManager);
|
||||
}
|
||||
|
||||
public GuildMusicManager getGuildMusicManager(Guild guild) {
|
||||
return this.musicManagerMap.computeIfAbsent(guild.getIdLong(), (guildId) -> {
|
||||
final GuildMusicManager guildMusicManager = new GuildMusicManager(this.playerManager);
|
||||
|
||||
guild.getAudioManager().setSendingHandler(guildMusicManager.getSendHandler());
|
||||
|
||||
return guildMusicManager;
|
||||
});
|
||||
}
|
||||
|
||||
public void loadAndPlay(SlashCommandInteractionEvent event, String trackUrl) {
|
||||
final GuildMusicManager musicManager = this.getGuildMusicManager(event.getGuild());
|
||||
|
||||
this.playerManager.loadItemOrdered(musicManager, trackUrl, new AudioLoadResultHandler() {
|
||||
@Override
|
||||
public void trackLoaded(AudioTrack track) {
|
||||
musicManager.scheduler.queue(track);
|
||||
AudioTrackInfo info = track.getInfo();
|
||||
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Added to queue from link",
|
||||
"**" + info.title + "**\n" +
|
||||
"by " + info.author + "\n" +
|
||||
TimeUtil.getTimeFormatedShortend(info.length) + "\n\n" +
|
||||
">>>" + info.uri, "https://img.youtube.com/vi/" + getImgURL(info.uri) + "/maxresdefault.jpg");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playlistLoaded(AudioPlaylist playlist) {
|
||||
AudioTrack track = playlist.getTracks().get(0);
|
||||
AudioTrackInfo info = track.getInfo();
|
||||
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Added to queue from query",
|
||||
"**" + info.title + "**\n" +
|
||||
"by " + info.author + "\n" +
|
||||
TimeUtil.getTimeFormatedShortend(info.length) + "\n\n" +
|
||||
">>>" + info.uri, "https://img.youtube.com/vi/" + getImgURL(info.uri) + "/maxresdefault.jpg");
|
||||
|
||||
musicManager.scheduler.queue(track);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void noMatches() {
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "No Matches", "No Matches found", "https://media.discordapp.net/attachments/833442323160891452/1031591718149165128/unknown.png");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFailed(FriendlyException exception) {
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Load failed", "Could not load song.", "https://media.discordapp.net/attachments/833442323160891452/1031656911147372585/unknown.png");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String getImgURL(String uri){
|
||||
return uri.split("=")[1];
|
||||
}
|
||||
|
||||
public static MusicManager getInstance(){
|
||||
if(instance == null){
|
||||
instance = new MusicManager();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package de.limited_dev.lil_judd.features.music;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter;
|
||||
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
public class TrackScheduler extends AudioEventAdapter {
|
||||
public final AudioPlayer player;
|
||||
public final BlockingQueue<AudioTrack> queue;
|
||||
public boolean repeating = false;
|
||||
|
||||
|
||||
public TrackScheduler(AudioPlayer player) {
|
||||
this.player = player;
|
||||
this.queue = new LinkedBlockingQueue<>();
|
||||
}
|
||||
|
||||
public void queue(AudioTrack track) {
|
||||
if (!this.player.startTrack(track, true)) {
|
||||
this.queue.offer(track);
|
||||
}
|
||||
}
|
||||
|
||||
public void nextTrack() {
|
||||
this.player.startTrack(this.queue.poll(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrackException(AudioPlayer player, AudioTrack track, FriendlyException exception) {
|
||||
this.player.startTrack(track.makeClone(), false);
|
||||
}
|
||||
@Override
|
||||
public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) {
|
||||
if (endReason.mayStartNext) {
|
||||
if (this.repeating || endReason == AudioTrackEndReason.LOAD_FAILED) {
|
||||
this.player.startTrack(track.makeClone(), false);
|
||||
return;
|
||||
}
|
||||
|
||||
nextTrack();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrackStuck(AudioPlayer player, AudioTrack track, long thresholdMs) {
|
||||
this.player.startTrack(track.makeClone(), false);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package de.limited_dev.lil_judd.features;
|
||||
package de.limited_dev.lil_judd.features.planner;
|
||||
|
||||
import de.limited_dev.lil_judd.Main;
|
||||
import de.limited_dev.lil_judd.features.storage.GuildTimePlannerStorage;
|
||||
|
@ -29,6 +29,8 @@ public class TimePlanner {
|
|||
private static final int hour = 8;
|
||||
private static final int minute = 0;
|
||||
private static final int second = 0;
|
||||
public static Thread sceduThr;
|
||||
public static ScheduledExecutorService schedulerFirstLesson;
|
||||
|
||||
public static GuildTimePlannerStorage getGtps() {
|
||||
return gtps;
|
||||
|
@ -38,6 +40,70 @@ public class TimePlanner {
|
|||
// get the current ZonedDateTime of your TimeZone
|
||||
ZonedDateTime now = ZonedDateTime.now(ZoneId.of("Europe/Berlin"));
|
||||
|
||||
sceduThr = new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
// send a message
|
||||
JDA jda = Main.getJda();
|
||||
Set<Long> gs = gtps.guildsWithPlanner.keySet();
|
||||
lgr.info(gs.toString());
|
||||
sceduThr.start();
|
||||
lgr.info("Started sending Push Notifications for time Management");
|
||||
for(Long l : gs) {
|
||||
ZonedDateTime then = ZonedDateTime.now(ZoneId.of("Europe/Berlin")).withHour(hour).withMinute(minute).withSecond(second);
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(jda.getGuildById(l), gtps.guildsWithPlanner.get(l), "Timeplanning System", "Do you have time on the following Days?", null);
|
||||
try {
|
||||
Thread.sleep(4000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
for(int i = 0; i < 7; ++i){
|
||||
if(i != 0)
|
||||
then = then.plusDays(1).withHour(hour).withMinute(minute).withSecond(second);
|
||||
MessageEmbed eb = EmbeddedMessageHelper.getEmbeddedMessageAutomated(false, null, then.getDayOfWeek() + ", " + then.getDayOfMonth() + "." + then.getMonthValue() + "." + then.getYear(), null, false).build();
|
||||
jda.getGuildById(l).getTextChannelById(gtps.guildsWithPlanner.get(l)).sendMessageEmbeds(eb).queue(message -> addReactions(message));
|
||||
lgr.info(gs + ": " + then.getDayOfWeek() + ", " + then.getDayOfMonth() + "." + then.getMonthValue() + "." + then.getYear());
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
lgr.info("Send to Server " + jda.getGuildById(l).getName());
|
||||
}
|
||||
lgr.info("Terminating Thread...");
|
||||
Thread.currentThread().interrupt();
|
||||
return;
|
||||
}
|
||||
|
||||
private void addReactions(Message msg){
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
msg.addReaction(Emoji.fromUnicode("✅")).queue();
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
msg.addReaction(Emoji.fromFormatted("❌")).queue();
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
msg.addReaction(Emoji.fromFormatted("❓")).queue();
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ZonedDateTime nextNotifyDay = now.plusDays(DayUtil.getDelay(now.getDayOfWeek().name())).withHour(hour).withMinute(minute).withSecond(second);
|
||||
//ZonedDateTime nextNotifyDay = now.plusSeconds(10);
|
||||
|
@ -59,71 +125,9 @@ public class TimePlanner {
|
|||
lgr.info("Duration: " + initialDelayUntilNextNotification);
|
||||
|
||||
// schedules the reminder at a fixed rate of one day
|
||||
ScheduledExecutorService schedulerFirstLesson = Executors.newScheduledThreadPool(1);
|
||||
schedulerFirstLesson = Executors.newScheduledThreadPool(1);
|
||||
schedulerFirstLesson.scheduleAtFixedRate(() -> {
|
||||
// send a message
|
||||
JDA jda = Main.getJda();
|
||||
Set<Long> gs = gtps.guildsWithPlanner.keySet();
|
||||
lgr.info(gs.toString());
|
||||
Thread thr = new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
for(Long l : gs) {
|
||||
ZonedDateTime then = ZonedDateTime.now(ZoneId.of("Europe/Berlin")).withHour(hour).withMinute(minute).withSecond(second);
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(jda.getGuildById(l), gtps.guildsWithPlanner.get(l), "Timeplanning System", "Do you have time on the following Days?", null);
|
||||
try {
|
||||
Thread.sleep(4000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
for(int i = 0; i < 7; ++i){
|
||||
if(i != 0)
|
||||
then = then.plusDays(1).withHour(hour).withMinute(minute).withSecond(second);
|
||||
MessageEmbed eb = EmbeddedMessageHelper.getEmbeddedMessageAutomated(false, null, then.getDayOfWeek() + ", " + then.getDayOfMonth() + "." + then.getMonthValue() + "." + then.getYear(), null, false).build();
|
||||
jda.getGuildById(l).getTextChannelById(gtps.guildsWithPlanner.get(l)).sendMessageEmbeds(eb).queue(message -> addReactions(message));
|
||||
lgr.info(gs + ": " + then.getDayOfWeek() + ", " + then.getDayOfMonth() + "." + then.getMonthValue() + "." + then.getYear());
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
lgr.info("Send to Server " + jda.getGuildById(l).getName());
|
||||
}
|
||||
lgr.info("Terminating Thread...");
|
||||
Thread.currentThread().interrupt();
|
||||
return;
|
||||
}
|
||||
|
||||
private void addReactions(Message msg){
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
msg.addReaction(Emoji.fromUnicode("✅")).queue();
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
msg.addReaction(Emoji.fromFormatted("❌")).queue();
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
msg.addReaction(Emoji.fromFormatted("❓")).queue();
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
thr.start();
|
||||
lgr.info("Started sending Push Notifications for time Management");
|
||||
sceduThr.start();
|
||||
},
|
||||
initialDelayUntilNextNotification,
|
||||
TimeUnit.DAYS.toSeconds(7),
|
|
@ -1,6 +1,6 @@
|
|||
package de.limited_dev.lil_judd.features;
|
||||
package de.limited_dev.lil_judd.features.scrims;
|
||||
|
||||
import de.limited_dev.lil_judd.features.components.scrims.GuildInQueue;
|
||||
import de.limited_dev.lil_judd.features.scrims.components.GuildInQueue;
|
||||
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.User;
|
|
@ -1,4 +1,4 @@
|
|||
package de.limited_dev.lil_judd.features.components.scrims;
|
||||
package de.limited_dev.lil_judd.features.scrims.components;
|
||||
|
||||
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
|
||||
import de.limited_dev.lil_judd.util.TimeUtil;
|
||||
|
@ -7,7 +7,6 @@ import net.dv8tion.jda.api.entities.User;
|
|||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class GuildInQueue {
|
||||
private final Guild g;
|
|
@ -1,8 +1,7 @@
|
|||
package de.limited_dev.lil_judd.features;
|
||||
package de.limited_dev.lil_judd.features.weapons;
|
||||
|
||||
|
||||
import de.limited_dev.lil_judd.Main;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
|
@ -1,8 +1,8 @@
|
|||
package de.limited_dev.lil_judd.features.components.weapon;
|
||||
package de.limited_dev.lil_judd.features.weapons.components;
|
||||
|
||||
import de.limited_dev.lil_judd.features.components.weapon.enums.MainType;
|
||||
import de.limited_dev.lil_judd.features.components.weapon.enums.SubType;
|
||||
import de.limited_dev.lil_judd.features.components.weapon.enums.SpecialType;
|
||||
import de.limited_dev.lil_judd.features.weapons.components.enums.MainType;
|
||||
import de.limited_dev.lil_judd.features.weapons.components.enums.SubType;
|
||||
import de.limited_dev.lil_judd.features.weapons.components.enums.SpecialType;
|
||||
|
||||
public class WeaponKit {
|
||||
private final String weaponName;
|
|
@ -1,4 +1,4 @@
|
|||
package de.limited_dev.lil_judd.features.components.weapon.enums;
|
||||
package de.limited_dev.lil_judd.features.weapons.components.enums;
|
||||
|
||||
public enum MainType {
|
||||
SHOOTER,
|
|
@ -1,4 +1,4 @@
|
|||
package de.limited_dev.lil_judd.features.components.weapon.enums;
|
||||
package de.limited_dev.lil_judd.features.weapons.components.enums;
|
||||
|
||||
public enum SpecialType {
|
||||
TRIZOOKA,
|
|
@ -1,4 +1,4 @@
|
|||
package de.limited_dev.lil_judd.features.components.weapon.enums;
|
||||
package de.limited_dev.lil_judd.features.weapons.components.enums;
|
||||
|
||||
public enum SubType {
|
||||
SUCTION_BOMB,
|
|
@ -1,16 +1,19 @@
|
|||
package de.limited_dev.lil_judd.commands.components;
|
||||
package de.limited_dev.lil_judd.jdacommands.components;
|
||||
|
||||
import de.limited_dev.lil_judd.Main;
|
||||
import de.limited_dev.lil_judd.util.Logger;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
|
||||
public class Command {
|
||||
public class JDACommand {
|
||||
|
||||
private final String name;
|
||||
protected final Logger lgr = Main.getLgr();
|
||||
|
||||
public Command(String name) {
|
||||
public JDACommand(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void onSlashCommandInteraction(SlashCommandInteractionEvent event){
|
||||
public void onSlashCommand(SlashCommandInteractionEvent event){
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package de.limited_dev.lil_judd.jdacommands.components;
|
||||
|
||||
import de.limited_dev.lil_judd.jdacommands.management.RemoveFeatureCommand;
|
||||
import de.limited_dev.lil_judd.jdacommands.management.SetupFeatureCommand;
|
||||
import de.limited_dev.lil_judd.jdacommands.music.*;
|
||||
import de.limited_dev.lil_judd.jdacommands.scrim.EndScrimCommand;
|
||||
import de.limited_dev.lil_judd.jdacommands.scrim.MessageScrimCommand;
|
||||
import de.limited_dev.lil_judd.jdacommands.scrim.ScrimInfoCommand;
|
||||
import de.limited_dev.lil_judd.jdacommands.scrim.SearchScrimCommand;
|
||||
import de.limited_dev.lil_judd.jdacommands.util.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class JDACommandManager {
|
||||
|
||||
private static List<JDACommand> commands = new CopyOnWriteArrayList<>();
|
||||
|
||||
public static void registerCommands(){
|
||||
commands.add(new PingCommand());
|
||||
commands.add(new InfoCommand());
|
||||
commands.add(new SetupFeatureCommand());
|
||||
commands.add(new RemoveFeatureCommand());
|
||||
commands.add(new SearchScrimCommand());
|
||||
commands.add(new EndScrimCommand());
|
||||
commands.add(new MessageScrimCommand());
|
||||
commands.add(new ScrimInfoCommand());
|
||||
commands.add(new TranslateCommand());
|
||||
commands.add(new PlayCommand());
|
||||
commands.add(new StopCommand());
|
||||
commands.add(new SkipCommand());
|
||||
commands.add(new QueueCommand());
|
||||
commands.add(new NowPlayingCommand());
|
||||
}
|
||||
|
||||
public static List<JDACommand> getCommands() {
|
||||
return commands;
|
||||
}
|
||||
}
|
|
@ -1,18 +1,18 @@
|
|||
package de.limited_dev.lil_judd.commands;
|
||||
package de.limited_dev.lil_judd.jdacommands.management;
|
||||
|
||||
import de.limited_dev.lil_judd.commands.components.Command;
|
||||
import de.limited_dev.lil_judd.features.TimePlanner;
|
||||
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
|
||||
import de.limited_dev.lil_judd.features.planner.TimePlanner;
|
||||
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
|
||||
public class RemoveFeatureCommand extends Command {
|
||||
public class RemoveFeatureCommand extends JDACommand {
|
||||
public RemoveFeatureCommand() {
|
||||
super("remove");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
|
||||
public void onSlashCommand(SlashCommandInteractionEvent event) {
|
||||
if(!event.getGuild().getMemberById(event.getUser().getId()).hasPermission(Permission.ADMINISTRATOR)){
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "403: Forbidden", "Sorry, but you don't have the Permission to run this command", null);
|
||||
return;
|
|
@ -1,18 +1,18 @@
|
|||
package de.limited_dev.lil_judd.commands;
|
||||
package de.limited_dev.lil_judd.jdacommands.management;
|
||||
|
||||
import de.limited_dev.lil_judd.commands.components.Command;
|
||||
import de.limited_dev.lil_judd.features.TimePlanner;
|
||||
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
|
||||
import de.limited_dev.lil_judd.features.planner.TimePlanner;
|
||||
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
|
||||
public class SetupFeatureCommand extends Command {
|
||||
public class SetupFeatureCommand extends JDACommand {
|
||||
public SetupFeatureCommand() {
|
||||
super("setup");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
|
||||
public void onSlashCommand(SlashCommandInteractionEvent event) {
|
||||
if(!event.getGuild().getMemberById(event.getUser().getIdLong()).hasPermission(Permission.ADMINISTRATOR)){
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "403: Forbidden", "You are not allowed to run this command.", null);
|
||||
return;
|
|
@ -0,0 +1,54 @@
|
|||
package de.limited_dev.lil_judd.jdacommands.music;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
|
||||
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
|
||||
import de.limited_dev.lil_judd.features.music.GuildMusicManager;
|
||||
import de.limited_dev.lil_judd.features.music.MusicManager;
|
||||
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
|
||||
import de.limited_dev.lil_judd.util.TimeUtil;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.GuildVoiceState;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
|
||||
public class NowPlayingCommand extends JDACommand {
|
||||
public NowPlayingCommand() {
|
||||
super("nowplaying");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlashCommand(SlashCommandInteractionEvent event) {
|
||||
final TextChannel c = event.getChannel().asTextChannel();
|
||||
final Guild g = event.getGuild();
|
||||
final Member self = g.getSelfMember();
|
||||
final GuildVoiceState selfState = self.getVoiceState();
|
||||
|
||||
if(!selfState.inAudioChannel()){
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Not in VC", "I'm not playing anything.", null);
|
||||
return;
|
||||
}
|
||||
|
||||
final GuildMusicManager guildMusicManager = MusicManager.getInstance().getGuildMusicManager(g);
|
||||
final AudioPlayer audioPlayer = guildMusicManager.audioPlayer;
|
||||
final AudioTrack track = audioPlayer.getPlayingTrack();
|
||||
|
||||
if(track == null){
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Not Playing", "Not playing anything", null);
|
||||
return;
|
||||
}
|
||||
|
||||
final AudioTrackInfo info = track.getInfo();
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Currently playing",
|
||||
"**" + info.title + "**\n" +
|
||||
"by " + info.author + "\n" +
|
||||
TimeUtil.getTimeFormatedShortend(audioPlayer.getPlayingTrack().getPosition()) + " : " + TimeUtil.getTimeFormatedShortend(info.length) + "\n\n" +
|
||||
">>>" + info.uri, "https://img.youtube.com/vi/" + getImgURL(info.uri) + "/maxresdefault.jpg");
|
||||
}
|
||||
|
||||
private String getImgURL(String uri){
|
||||
return uri.split("=")[1];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package de.limited_dev.lil_judd.jdacommands.music;
|
||||
|
||||
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
|
||||
import de.limited_dev.lil_judd.features.music.MusicManager;
|
||||
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.GuildVoiceState;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.managers.AudioManager;
|
||||
|
||||
public class PlayCommand extends JDACommand {
|
||||
|
||||
public PlayCommand() {
|
||||
super("play");
|
||||
}
|
||||
@Override
|
||||
public void onSlashCommand(SlashCommandInteractionEvent event) {
|
||||
final Guild g = event.getGuild();
|
||||
final Member self = g.getSelfMember();
|
||||
final Member m = g.getMemberById(event.getUser().getIdLong());
|
||||
final TextChannel c = event.getChannel().asTextChannel();
|
||||
final GuildVoiceState selfState = self.getVoiceState();
|
||||
final GuildVoiceState memberState = m.getVoiceState();
|
||||
|
||||
|
||||
boolean hadToJoin = false;
|
||||
if(!selfState.inAudioChannel()){
|
||||
if(!attemptToJoinVoice(event, m))
|
||||
return;
|
||||
hadToJoin = true;
|
||||
}
|
||||
|
||||
if(!hadToJoin){
|
||||
if(!selfState.getChannel().equals(memberState.getChannel())){
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Error", "You are not in the same voice channel", null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String link = event.getOption("linkquery").getAsString();
|
||||
|
||||
if(!link.startsWith("https://www.youtube.com") && !link.startsWith("https://youtube.com") && link.startsWith("https://")){
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Error", "Not a YouTube URL.", null);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!isURL(link)){
|
||||
link = "ytsearch:" + link;
|
||||
lgr.info("Is not link");
|
||||
}
|
||||
|
||||
|
||||
MusicManager.getInstance().loadAndPlay(event, link);
|
||||
}
|
||||
|
||||
public boolean attemptToJoinVoice(SlashCommandInteractionEvent event, Member m){
|
||||
Guild g = event.getGuild();
|
||||
GuildVoiceState memberVoiceState = m.getVoiceState();
|
||||
if(!memberVoiceState.inAudioChannel()){
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Not In Voice",
|
||||
"You are not in a voice channel.", null);
|
||||
lgr.info("Could not join vc");
|
||||
return false;
|
||||
}
|
||||
final AudioManager audioManager = g.getAudioManager();
|
||||
final VoiceChannel vc = memberVoiceState.getChannel().asVoiceChannel();
|
||||
|
||||
audioManager.openAudioConnection(vc);
|
||||
lgr.info("Joined VC in " + g.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isURL(String uri){
|
||||
return uri.startsWith("https://www.youtube.com") || uri.startsWith("https://youtube.com") || uri.startsWith("https://youtu.be");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package de.limited_dev.lil_judd.jdacommands.music;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
|
||||
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
|
||||
import de.limited_dev.lil_judd.features.music.GuildMusicManager;
|
||||
import de.limited_dev.lil_judd.features.music.MusicManager;
|
||||
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
|
||||
import de.limited_dev.lil_judd.util.TimeUtil;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
||||
public class QueueCommand extends JDACommand {
|
||||
public QueueCommand() {
|
||||
super("queue");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlashCommand(SlashCommandInteractionEvent event) {
|
||||
final Guild g = event.getGuild();
|
||||
final GuildMusicManager guildMusicManager = MusicManager.getInstance().getGuildMusicManager(g);
|
||||
final BlockingQueue<AudioTrack> queue = guildMusicManager.scheduler.queue;
|
||||
final AudioPlayer audioPlayer = guildMusicManager.audioPlayer;
|
||||
final AudioTrack currenttrack = audioPlayer.getPlayingTrack();
|
||||
|
||||
if(queue.isEmpty() && currenttrack == null){
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Queue", "**Queue Empty**", null);
|
||||
return;
|
||||
}
|
||||
|
||||
final List<AudioTrack> trackList = new ArrayList<>(queue);
|
||||
String description = "";
|
||||
AudioTrackInfo info;
|
||||
String trackInfo;
|
||||
int index = 0;
|
||||
info = currenttrack.getInfo();
|
||||
description = "**" + info.title + " - " + TimeUtil.getTimeFormatedShortend(info.length) + " (" + info.author + ")**\n";
|
||||
for(AudioTrack track : trackList){
|
||||
if(index == 14)
|
||||
continue;
|
||||
info = track.getInfo();
|
||||
trackInfo = info.title + " - " + TimeUtil.getTimeFormatedShortend(track.getDuration()) + " (" + info.author + ")\n";
|
||||
description = description + trackInfo;
|
||||
++index;
|
||||
}
|
||||
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Queue", description, "https://cdn.discordapp.com/attachments/833442323160891452/1031670452642394182/unknown.png");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package de.limited_dev.lil_judd.jdacommands.music;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
|
||||
import de.limited_dev.lil_judd.features.music.GuildMusicManager;
|
||||
import de.limited_dev.lil_judd.features.music.MusicManager;
|
||||
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.GuildVoiceState;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
|
||||
public class SkipCommand extends JDACommand {
|
||||
public SkipCommand() {
|
||||
super("skip");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlashCommand(SlashCommandInteractionEvent event) {
|
||||
final Guild g = event.getGuild();
|
||||
final Member self = g.getSelfMember();
|
||||
final GuildVoiceState selfState = self.getVoiceState();
|
||||
|
||||
if(!selfState.inAudioChannel()){
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Not In VC", "I'm not a voice channel", null);
|
||||
return;
|
||||
}
|
||||
|
||||
final Member m = g.getMemberById(event.getUser().getIdLong());
|
||||
final GuildVoiceState mState = m.getVoiceState();
|
||||
|
||||
if(!mState.inAudioChannel()){
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Not in VC", "You are not in a vc", null);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!selfState.getChannel().asVoiceChannel().equals(mState.getChannel().asVoiceChannel())){
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Not in same VC", "You are not in my vc", null);
|
||||
return;
|
||||
}
|
||||
|
||||
final GuildMusicManager guildMusicManager = MusicManager.getInstance().getGuildMusicManager(g);
|
||||
final AudioPlayer audioPlayer = guildMusicManager.audioPlayer;
|
||||
|
||||
if(audioPlayer.getPlayingTrack() == null){
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Error", "There is no playing track currently", null);
|
||||
return;
|
||||
}
|
||||
|
||||
guildMusicManager.scheduler.nextTrack();
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Skip", "Song Skipped", "https://cdn.discordapp.com/attachments/833442323160891452/1031670974568988783/unknown.png");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package de.limited_dev.lil_judd.jdacommands.music;
|
||||
|
||||
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
|
||||
import de.limited_dev.lil_judd.features.music.GuildMusicManager;
|
||||
import de.limited_dev.lil_judd.features.music.MusicManager;
|
||||
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.GuildVoiceState;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.managers.AudioManager;
|
||||
|
||||
public class StopCommand extends JDACommand {
|
||||
public StopCommand() {
|
||||
super("stop");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlashCommand(SlashCommandInteractionEvent event) {
|
||||
final Guild g = event.getGuild();
|
||||
final Member self = g.getSelfMember();
|
||||
final GuildVoiceState selfState = self.getVoiceState();
|
||||
|
||||
if(!selfState.inAudioChannel()){
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Not In VC", "I'm not a voice channel", null);
|
||||
return;
|
||||
}
|
||||
|
||||
final Member m = g.getMemberById(event.getUser().getIdLong());
|
||||
final GuildVoiceState mState = m.getVoiceState();
|
||||
|
||||
if(!mState.inAudioChannel()){
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Not in VC", "You are not in a vc", null);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!selfState.getChannel().asVoiceChannel().equals(mState.getChannel().asVoiceChannel())){
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Not in same VC", "You are not in my vc", null);
|
||||
return;
|
||||
}
|
||||
|
||||
final GuildMusicManager guildMusicManager = MusicManager.getInstance().getGuildMusicManager(g);
|
||||
|
||||
guildMusicManager.scheduler.player.stopTrack();
|
||||
guildMusicManager.scheduler.queue.clear();
|
||||
|
||||
final AudioManager audioManager = g.getAudioManager();
|
||||
|
||||
audioManager.closeAudioConnection();
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "I stopped", "And left, just like your girlfriend.", "https://cdn.discordapp.com/attachments/833442323160891452/1031671269281763438/unknown.png");
|
||||
}
|
||||
}
|
|
@ -1,19 +1,19 @@
|
|||
package de.limited_dev.lil_judd.commands;
|
||||
package de.limited_dev.lil_judd.jdacommands.scrim;
|
||||
|
||||
import de.limited_dev.lil_judd.commands.components.Command;
|
||||
import de.limited_dev.lil_judd.features.ScrimMaker;
|
||||
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
|
||||
import de.limited_dev.lil_judd.features.scrims.ScrimMaker;
|
||||
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
|
||||
public class EndScrimCommand extends Command {
|
||||
public class EndScrimCommand extends JDACommand {
|
||||
public EndScrimCommand() {
|
||||
super("endscrim");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
|
||||
public void onSlashCommand(SlashCommandInteractionEvent event) {
|
||||
Guild g = event.getGuild();
|
||||
User u = event.getUser();
|
||||
if(!ScrimMaker.IsInGameOrQueue(g)){
|
|
@ -1,19 +1,19 @@
|
|||
package de.limited_dev.lil_judd.commands;
|
||||
package de.limited_dev.lil_judd.jdacommands.scrim;
|
||||
|
||||
import de.limited_dev.lil_judd.commands.components.Command;
|
||||
import de.limited_dev.lil_judd.features.ScrimMaker;
|
||||
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
|
||||
import de.limited_dev.lil_judd.features.scrims.ScrimMaker;
|
||||
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
|
||||
public class MessageScrimCommand extends Command {
|
||||
public class MessageScrimCommand extends JDACommand {
|
||||
public MessageScrimCommand() {
|
||||
super("msgscrim");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
|
||||
public void onSlashCommand(SlashCommandInteractionEvent event) {
|
||||
Guild g = event.getGuild();
|
||||
User u = event.getUser();
|
||||
if(!ScrimMaker.IsInGameOrQueue(g)){
|
|
@ -1,17 +1,17 @@
|
|||
package de.limited_dev.lil_judd.commands;
|
||||
package de.limited_dev.lil_judd.jdacommands.scrim;
|
||||
|
||||
import de.limited_dev.lil_judd.commands.components.Command;
|
||||
import de.limited_dev.lil_judd.features.ScrimMaker;
|
||||
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
|
||||
import de.limited_dev.lil_judd.features.scrims.ScrimMaker;
|
||||
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
|
||||
public class ScrimInfoCommand extends Command {
|
||||
public class ScrimInfoCommand extends JDACommand {
|
||||
public ScrimInfoCommand() {
|
||||
super("scriminfo");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
|
||||
public void onSlashCommand(SlashCommandInteractionEvent event) {
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "ScrimMaker info",
|
||||
"Guilds in queue: " + ScrimMaker.getQueueSize() + "\n" +
|
||||
"Guild in game: " + ScrimMaker.getGameSize() + "\n" +
|
|
@ -1,7 +1,7 @@
|
|||
package de.limited_dev.lil_judd.commands;
|
||||
package de.limited_dev.lil_judd.jdacommands.scrim;
|
||||
|
||||
import de.limited_dev.lil_judd.commands.components.Command;
|
||||
import de.limited_dev.lil_judd.features.ScrimMaker;
|
||||
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
|
||||
import de.limited_dev.lil_judd.features.scrims.ScrimMaker;
|
||||
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
|
@ -10,13 +10,13 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEve
|
|||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class SearchScrimCommand extends Command {
|
||||
public class SearchScrimCommand extends JDACommand {
|
||||
public SearchScrimCommand() {
|
||||
super("searchscrim");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
|
||||
public void onSlashCommand(SlashCommandInteractionEvent event) {
|
||||
User u1 = event.getOption("player1").getAsUser();
|
||||
User u2 = event.getOption("player2").getAsUser();
|
||||
User u3 = event.getOption("player3").getAsUser();
|
|
@ -0,0 +1,28 @@
|
|||
package de.limited_dev.lil_judd.jdacommands.util;
|
||||
|
||||
import de.limited_dev.lil_judd.Main;
|
||||
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
|
||||
import de.limited_dev.lil_judd.jdacommands.components.JDACommandManager;
|
||||
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
|
||||
import de.limited_dev.lil_judd.util.TimeUtil;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class InfoCommand extends JDACommand {
|
||||
public InfoCommand() {
|
||||
super("info");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlashCommand(SlashCommandInteractionEvent event) {
|
||||
HashMap<String, String[]> hm = new HashMap<>();
|
||||
hm.put("Information", new String[]{"Ping", "Uptime", "RAM", "# Commands"});
|
||||
hm.put("Value", new String[]{Main.getJda().getGatewayPing() + "ms", TimeUtil.getTimeFormatedShortend(Main.getUptime()),
|
||||
(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + "MB / " + (Runtime.getRuntime().maxMemory() - (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())) / 1024 / 1024 + "MB; " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) * 100L / Runtime.getRuntime().maxMemory() + "%"
|
||||
, JDACommandManager.getCommands().size() + ""});
|
||||
EmbeddedMessageHelper.sendWithTable(event, Main.getJda().getSelfUser().getName(), "Bot information", Color.YELLOW, Main.getJda().getSelfUser().getAvatarUrl(), "General information about the bot",
|
||||
new String[]{"Information", "Value"}, hm, true);
|
||||
}
|
||||
}
|
|
@ -1,18 +1,18 @@
|
|||
package de.limited_dev.lil_judd.commands;
|
||||
package de.limited_dev.lil_judd.jdacommands.util;
|
||||
|
||||
|
||||
import de.limited_dev.lil_judd.Main;
|
||||
import de.limited_dev.lil_judd.commands.components.Command;
|
||||
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
|
||||
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
|
||||
public class PingCommand extends Command {
|
||||
public class PingCommand extends JDACommand {
|
||||
public PingCommand() {
|
||||
super("ping");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
|
||||
public void onSlashCommand(SlashCommandInteractionEvent event) {
|
||||
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Connection speed", "My connection to base takes **" + Main.getJda().getGatewayPing() + "ms**", null);
|
||||
}
|
||||
}
|
|
@ -1,18 +1,18 @@
|
|||
package de.limited_dev.lil_judd.commands;
|
||||
package de.limited_dev.lil_judd.jdacommands.util;
|
||||
|
||||
import de.limited_dev.lil_judd.commands.components.Command;
|
||||
import de.limited_dev.lil_judd.features.MapManager;
|
||||
import de.limited_dev.lil_judd.features.components.maps.MapData;
|
||||
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
|
||||
import de.limited_dev.lil_judd.features.maps.MapManager;
|
||||
import de.limited_dev.lil_judd.features.maps.components.MapData;
|
||||
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
|
||||
public class TranslateCommand extends Command {
|
||||
public class TranslateCommand extends JDACommand {
|
||||
public TranslateCommand() {
|
||||
super("translatemap");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
|
||||
public void onSlashCommand(SlashCommandInteractionEvent event) {
|
||||
String map = event.getOption("map").getAsString().toLowerCase();
|
||||
MapData md = MapManager.getMapData(map);
|
||||
if (md == null) {
|
|
@ -2,8 +2,6 @@ package de.limited_dev.lil_judd.listeners;
|
|||
|
||||
import de.limited_dev.lil_judd.Main;
|
||||
import de.limited_dev.lil_judd.util.Logger;
|
||||
import de.limited_dev.lil_judd.util.SlashCommandHelper;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.events.guild.GuildJoinEvent;
|
||||
import net.dv8tion.jda.api.events.guild.GuildLeaveEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
|
|
|
@ -1,26 +1,14 @@
|
|||
package de.limited_dev.lil_judd.listeners;
|
||||
|
||||
import de.limited_dev.lil_judd.Main;
|
||||
import de.limited_dev.lil_judd.features.TimePlanner;
|
||||
import de.limited_dev.lil_judd.features.planner.TimePlanner;
|
||||
import de.limited_dev.lil_judd.features.storage.GuildTimePlannerStorage;
|
||||
import de.limited_dev.lil_judd.util.DayUtil;
|
||||
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
|
||||
import de.limited_dev.lil_judd.util.Logger;
|
||||
import de.limited_dev.lil_judd.util.SlashCommandHelper;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import de.limited_dev.lil_judd.util.SlashCommandRegister;
|
||||
import net.dv8tion.jda.api.events.ReadyEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ReadyListener extends ListenerAdapter {
|
||||
private final Logger lgr = Main.getLgr();
|
||||
private final GuildTimePlannerStorage gtps = TimePlanner.getGtps();
|
||||
|
@ -29,7 +17,7 @@ public class ReadyListener extends ListenerAdapter {
|
|||
public void onReady(@NotNull ReadyEvent event) {
|
||||
String usernameOfSelf = Main.getJda().getSelfUser().getName();
|
||||
|
||||
SlashCommandHelper.addSlashCommandsToGuild();
|
||||
SlashCommandRegister.registerCommands();
|
||||
|
||||
lgr.info("Logged into: " + usernameOfSelf);
|
||||
lgr.info(usernameOfSelf + " is ready for Freddy");
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package de.limited_dev.lil_judd.listeners;
|
||||
|
||||
import de.limited_dev.lil_judd.Main;
|
||||
import de.limited_dev.lil_judd.commands.components.Command;
|
||||
import de.limited_dev.lil_judd.commands.components.CommandManager;
|
||||
import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
|
||||
import de.limited_dev.lil_judd.jdacommands.components.JDACommandManager;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -12,8 +12,8 @@ public class SlashCommandInteractionListener extends ListenerAdapter {
|
|||
@Override
|
||||
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
|
||||
Main.getLgr().info("New Command: /" + event.getName() + " in " + event.getGuild().getName());
|
||||
for(Command c : CommandManager.getCommands())
|
||||
for(JDACommand c : JDACommandManager.getCommands())
|
||||
if(event.getName().equals(c.getName()))
|
||||
c.onSlashCommandInteraction(event);
|
||||
c.onSlashCommand(event);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,18 +3,118 @@ package de.limited_dev.lil_judd.util;
|
|||
import de.limited_dev.lil_judd.Main;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import net.dv8tion.jda.api.events.Event;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.awt.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class EmbeddedMessageHelper {
|
||||
private static final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy @ HH:mm:ss");
|
||||
|
||||
public static void sendWithTable(MessageReceivedEvent event, String author, String title, Color color, String imageUrl,
|
||||
String description, @Nullable String[] titleOfFlields, @Nullable HashMap<String, String[]> valueOfFlieds, boolean inline, boolean fromMobile, int deleteDelay) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
EmbedBuilder eb = new EmbedBuilder();
|
||||
eb.setAuthor(author);
|
||||
eb.setTitle(title);
|
||||
eb.setColor(color);
|
||||
eb.setDescription(description);
|
||||
if (titleOfFlields != null) {
|
||||
if (!fromMobile) {
|
||||
for (String titleOfFlied : titleOfFlields) {
|
||||
String value = "";
|
||||
for (String s : valueOfFlieds.get(titleOfFlied)) {
|
||||
value = value.isEmpty() ? s : value + "\n" + s;
|
||||
}
|
||||
eb.addField(titleOfFlied, value, inline);
|
||||
}
|
||||
} else { // is from mobile
|
||||
String tof = "";
|
||||
String vof = "";
|
||||
for (int i = 0; i < titleOfFlields.length; ++i) {
|
||||
tof += titleOfFlields[i] + (i == titleOfFlields.length - 1 ? "" : " -- ");
|
||||
}
|
||||
if (!valueOfFlieds.isEmpty()) {
|
||||
for (int i = 0; i < valueOfFlieds.get(titleOfFlields[0]).length; ++i) {
|
||||
for (int j = 0; j < titleOfFlields.length; ++j) {
|
||||
vof += valueOfFlieds.get(titleOfFlields[j])[i] + (j == titleOfFlields.length - 1 ? "" : " == ");
|
||||
}
|
||||
vof += "\n"; //TODO finish
|
||||
}
|
||||
eb.addField(tof, vof, inline);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (imageUrl != null && !fromMobile) {
|
||||
eb.setThumbnail(imageUrl);
|
||||
}
|
||||
|
||||
eb.setFooter(">" + dtf.format(now) + " - " + event.getMessage().getAuthor().getName() + "#" + event.getMessage().getAuthor().getDiscriminator());
|
||||
if (deleteDelay == 0) {
|
||||
event.getChannel().sendMessageEmbeds(eb.build()).queue();
|
||||
return;
|
||||
}
|
||||
event.getChannel().sendMessageEmbeds(eb.build()).delay(deleteDelay, TimeUnit.SECONDS).flatMap(Message::delete).queue();
|
||||
}
|
||||
|
||||
public static void sendWithTable(SlashCommandInteractionEvent event, String author, String title, Color color, String imageUrl,
|
||||
String description, @Nullable String[] titleOfFlields, @Nullable HashMap<String, String[]> valueOfFlieds, boolean inline) {
|
||||
boolean fromMobile;
|
||||
if(event.getOption("mobileformatting") != null){
|
||||
fromMobile = event.getOption("mobileformatting").getAsBoolean();
|
||||
}else{
|
||||
fromMobile = false;
|
||||
}
|
||||
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
EmbedBuilder eb = new EmbedBuilder();
|
||||
eb.setAuthor(author);
|
||||
eb.setTitle(title);
|
||||
eb.setColor(color);
|
||||
eb.setDescription(description);
|
||||
if (titleOfFlields != null) {
|
||||
if (!fromMobile) {
|
||||
for (String titleOfFlied : titleOfFlields) {
|
||||
String value = "";
|
||||
for (String s : valueOfFlieds.get(titleOfFlied)) {
|
||||
value = value.isEmpty() ? s : value + "\n" + s;
|
||||
}
|
||||
eb.addField(titleOfFlied, value, inline);
|
||||
}
|
||||
} else { // is from mobile
|
||||
String tof = "";
|
||||
String vof = "";
|
||||
for (int i = 0; i < titleOfFlields.length; ++i) {
|
||||
tof += titleOfFlields[i] + (i == titleOfFlields.length - 1 ? "" : " -- ");
|
||||
}
|
||||
if (!valueOfFlieds.isEmpty()) {
|
||||
for (int i = 0; i < valueOfFlieds.get(titleOfFlields[0]).length; ++i) {
|
||||
for (int j = 0; j < titleOfFlields.length; ++j) {
|
||||
vof += valueOfFlieds.get(titleOfFlields[j])[i] + (j == titleOfFlields.length - 1 ? "" : " == ");
|
||||
}
|
||||
vof += "\n"; //TODO finish
|
||||
}
|
||||
eb.addField(tof, vof, inline);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (imageUrl != null && !fromMobile) {
|
||||
eb.setThumbnail(imageUrl);
|
||||
}
|
||||
|
||||
eb.setFooter(">" + dtf.format(now) + " - " + event.getUser().getName() + "#" + event.getUser().getDiscriminator());
|
||||
event.replyEmbeds(eb.build()).queue();
|
||||
}
|
||||
|
||||
public static void sendSimpleOneLiner(SlashCommandInteractionEvent event, String title, String description, String thumbnailURL){
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
EmbedBuilder eb = new EmbedBuilder();
|
||||
|
|
|
@ -17,4 +17,9 @@ public class Logger {
|
|||
// Ich kann nicht mehr
|
||||
// [Klasse.Funktion] [T/M HH:MM] <NACHRICHT>
|
||||
}
|
||||
|
||||
public void consoleOut(String msg) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
System.out.println("[console command output] [" + dtf.format(now) + "] <" + msg + ">");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
package de.limited_dev.lil_judd.util;
|
||||
|
||||
import de.limited_dev.lil_judd.Main;
|
||||
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;
|
||||
|
||||
public class SlashCommandHelper {
|
||||
|
||||
public static void addSlashCommandsToGuild(){
|
||||
|
||||
Main.getJda().updateCommands().addCommands(
|
||||
Commands.slash("ping", "Pong! Display the Ping"),
|
||||
Commands.slash("info", "Shows Info about me"),
|
||||
Commands.slash("setup", "Setup a feature")
|
||||
.addOptions(
|
||||
new OptionData(OptionType.STRING, "feature", "The Feature you want to setup", true)
|
||||
.addChoice("Send Time finder", "timefinder")
|
||||
, new OptionData(OptionType.CHANNEL, "channel", "The Channel the feature will post in.", true)
|
||||
),
|
||||
Commands.slash("remove", "Remove a feature")
|
||||
.addOptions(
|
||||
new OptionData(OptionType.STRING, "feature", "The Feature you want to remove", true)
|
||||
.addChoice("Send Time finder", "timefinder")
|
||||
, new OptionData(OptionType.CHANNEL, "channel", "The Channel with the feature", true)
|
||||
),
|
||||
Commands.slash("searchscrim", "Search for a scrim")
|
||||
.addOptions(
|
||||
new OptionData(OptionType.INTEGER, "div", "The Division you want to search in", true)
|
||||
, new OptionData(OptionType.USER, "player1", "The first Player of the team", true)
|
||||
, new OptionData(OptionType.USER, "player2", "The second Player of the team", true)
|
||||
, new OptionData(OptionType.USER, "player3", "The third Player of the team", true)
|
||||
, new OptionData(OptionType.USER, "player4", "The fourth Player of the team", true)
|
||||
),
|
||||
Commands.slash("endscrim", "Quit a scrum / Leave the queue"),
|
||||
Commands.slash("msgscrim", "Msg the enemy team")
|
||||
.addOptions(
|
||||
new OptionData(OptionType.STRING, "message", "Message content", true)
|
||||
),
|
||||
Commands.slash("scriminfo", "Show info about the scrim system."),
|
||||
Commands.slash("translatemap", "Translate a Map from German to English")
|
||||
.addOptions(
|
||||
new OptionData(OptionType.STRING, "map", "Map Name", true)
|
||||
)
|
||||
|
||||
|
||||
).queue();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package de.limited_dev.lil_judd.util;
|
||||
|
||||
import de.limited_dev.lil_judd.Main;
|
||||
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;
|
||||
|
||||
public class SlashCommandRegister {
|
||||
|
||||
public static void registerCommands(){
|
||||
|
||||
Main.getJda().updateCommands().addCommands(
|
||||
Commands.slash("info", "Shows Info about me")
|
||||
.addOptions(new OptionData(OptionType.BOOLEAN, "mobileformatting", "Format the reply for mobile devices")),
|
||||
Commands.slash("setup", "Setup a feature")
|
||||
.addOptions(
|
||||
new OptionData(OptionType.STRING, "feature", "The Feature you want to setup", true)
|
||||
.addChoice("Send Time finder", "timefinder"),
|
||||
new OptionData(OptionType.CHANNEL, "channel", "The Channel the feature will post in.", true)),
|
||||
Commands.slash("remove", "Remove a feature")
|
||||
.addOptions(new OptionData(OptionType.STRING, "feature", "The Feature you want to remove", true)
|
||||
.addChoice("Send Time finder", "timefinder"),
|
||||
new OptionData(OptionType.CHANNEL, "channel", "The Channel with the feature", true)),
|
||||
Commands.slash("searchscrim", "Search for a scrim")
|
||||
.addOptions(new OptionData(OptionType.INTEGER, "div", "The Division you want to search in", true),
|
||||
new OptionData(OptionType.USER, "player1", "The first Player of the team", true),
|
||||
new OptionData(OptionType.USER, "player2", "The second Player of the team", true),
|
||||
new OptionData(OptionType.USER, "player3", "The third Player of the team", true),
|
||||
new OptionData(OptionType.USER, "player4", "The fourth Player of the team", true)),
|
||||
Commands.slash("endscrim", "Quit a scrum / Leave the queue"),
|
||||
Commands.slash("msgscrim", "Msg the enemy team")
|
||||
.addOptions(new OptionData(OptionType.STRING, "message", "Message content", true)),
|
||||
Commands.slash("scriminfo", "Show info about the scrim system."),
|
||||
Commands.slash("translatemap", "Translate a Map")
|
||||
.addOptions(new OptionData(OptionType.STRING, "map", "Map Name", true)),
|
||||
Commands.slash("play", "Play music with the bot")
|
||||
.addOptions(new OptionData(OptionType.STRING, "linkquery", "YouTube Lik / Search Query", true)),
|
||||
Commands.slash("stop", "Stop the music & Bot leaves the voice channel"),
|
||||
Commands.slash("nowplaying", "Show what's currently playing"),
|
||||
Commands.slash("queue", "Show the music queue"),
|
||||
Commands.slash("skip", "Skip the current song")
|
||||
).queue();
|
||||
}
|
||||
}
|
Reference in a new issue