fix: TimePlanner should now work again,

feat: version is now displayed in the info command
This commit is contained in:
limited_dev 2022-10-29 02:12:21 +02:00
parent a52d7dd1c1
commit 2d0665d4d3
26 changed files with 224 additions and 644 deletions

View file

@ -1,10 +1,11 @@
plugins { plugins {
java java
id("com.github.johnrengelman.shadow") version "7.1.2" id("com.github.johnrengelman.shadow") version "7.1.2"
id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.6"
} }
group = "de.limited_dev" group = "de.limited_dev"
version = "1.0.1" version = "v1.2.1"
repositories { repositories {
mavenCentral() mavenCentral()
@ -13,16 +14,19 @@ repositories {
dependencies { dependencies {
implementation("net.dv8tion:JDA:5.0.0-alpha.20") 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-api:2.0.3")
implementation("org.slf4j:slf4j-simple:2.0.3") implementation("org.slf4j:slf4j-simple:2.0.3")
} }
tasks.getByName<Test>("test") { val templateSource = file("src/main/templates")
val templateDest = layout.buildDirectory.dir("generated/sources/templates")
tasks {
getByName<Test>("test") {
useJUnitPlatform() useJUnitPlatform()
} }
tasks.withType<Jar> { withType<Jar> {
manifest { manifest {
attributes["Main-Class"] = "de.limited_dev.lil_judd.Main" attributes["Main-Class"] = "de.limited_dev.lil_judd.Main"
} }
@ -33,24 +37,58 @@ tasks.withType<Jar> {
from({ from({
configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) } configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
}) })
dependsOn("generateTemplates", "processResources")
} }
withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
dependencies { dependencies {
include(dependency("net.dv8tion:JDA:5.0.0-alpha.20")) include(dependency("net.dv8tion:JDA:5.0.0-alpha.20"))
include(dependency("com.sedmelluq:lavaplayer:1.3.77"))
include(dependency("org.slf4j:slf4j-api:2.0.3")) include(dependency("org.slf4j:slf4j-api:2.0.3"))
include(dependency("org.slf4j:slf4j-simple:2.0.3")) include(dependency("org.slf4j:slf4j-simple:2.0.3"))
} }
dependsOn("generateTemplates", "processResources")
} }
tasks.withType<JavaCompile>{ withType<JavaCompile>{
options.encoding = "UTF-8" options.encoding = "UTF-8"
dependsOn("generateTemplates")
}
create<Copy>("generateTemplates") {
filteringCharset = "UTF-8"
val props = mapOf(
"version" to version
)
inputs.properties(props)
from(templateSource)
expand(props)
into(templateDest)
}
}
sourceSets.main {
java {
srcDir(templateDest)
}
resources {
srcDir("src/main/generated")
}
} }
java{ java{
sourceCompatibility = org.gradle.api.JavaVersion.VERSION_17 sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = org.gradle.api.JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17
} }
rootProject.idea.project {
this as ExtensionAware
configure<org.jetbrains.gradle.ext.ProjectSettings> {
this as ExtensionAware
configure<org.jetbrains.gradle.ext.TaskTriggersConfig> {
afterSync(tasks["generateTemplates"], tasks["processResources"])
}
}
}
//fuck eclipse users amirite?
//rootProject.eclipse.synchronizationTasks("generateTemplates")

View file

@ -1,2 +1,2 @@
rootProject.name = "lil_Judd" rootProject.name = "lil_Judd"
include("templates")

View file

@ -1,5 +1,6 @@
package de.limited_dev.lil_judd; package de.limited_dev.lil_judd;
import de.limited_dev.lil_judd.build.BuildConstants;
import de.limited_dev.lil_judd.consolecommand.component.ConsoleCommandManager; import de.limited_dev.lil_judd.consolecommand.component.ConsoleCommandManager;
import de.limited_dev.lil_judd.jdacommands.components.JDACommandManager; 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.maps.MapManager;
@ -24,7 +25,7 @@ public class Main {
public static void main(String[] args){ public static void main(String[] args){
lgr.info("li'l Judd is waking up ..."); lgr.info("li'l Judd is waking up ...");
lgr.info(BuildConstants.botVersion);
launchTime = System.currentTimeMillis(); launchTime = System.currentTimeMillis();
tokenManager.load(); tokenManager.load();

View file

@ -21,6 +21,27 @@ public class ConsoleCommand {
} }
protected 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);
}
public String getName() { public String getName() {
return name; return name;
} }

View file

@ -1,7 +1,9 @@
package de.limited_dev.lil_judd.consolecommand.component; package de.limited_dev.lil_judd.consolecommand.component;
import de.limited_dev.lil_judd.Main; import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.consolecommand.system.BotVersionCommand;
import de.limited_dev.lil_judd.consolecommand.system.ShutdownCommand; import de.limited_dev.lil_judd.consolecommand.system.ShutdownCommand;
import de.limited_dev.lil_judd.consolecommand.util.AnnounceCommand;
import de.limited_dev.lil_judd.consolecommand.util.HelpConsoleCommand; import de.limited_dev.lil_judd.consolecommand.util.HelpConsoleCommand;
import de.limited_dev.lil_judd.consolecommand.util.ManualCommand; import de.limited_dev.lil_judd.consolecommand.util.ManualCommand;
import de.limited_dev.lil_judd.util.Logger; import de.limited_dev.lil_judd.util.Logger;
@ -19,6 +21,8 @@ public class ConsoleCommandManager {
commands.add(new ShutdownCommand()); commands.add(new ShutdownCommand());
commands.add(new HelpConsoleCommand()); commands.add(new HelpConsoleCommand());
commands.add(new ManualCommand()); commands.add(new ManualCommand());
commands.add(new BotVersionCommand());
commands.add(new AnnounceCommand());
} }
public static void registerListener(){ public static void registerListener(){

View file

@ -0,0 +1,15 @@
package de.limited_dev.lil_judd.consolecommand.system;
import de.limited_dev.lil_judd.build.BuildConstants;
import de.limited_dev.lil_judd.consolecommand.component.ConsoleCommand;
public class BotVersionCommand extends ConsoleCommand {
public BotVersionCommand() {
super("version", "Shows the bot version", null);
}
@Override
public void onCommand(String[] args) {
lgr.consoleOut(jda.getSelfUser().getName() + " on " + BuildConstants.botVersion);
}
}

View file

@ -24,7 +24,6 @@ public class ShutdownCommand extends ConsoleCommand {
audioManager.closeAudioConnection(); audioManager.closeAudioConnection();
} }
} }
TimePlanner.sceduThr.interrupt();
TimePlanner.schedulerFirstLesson.shutdown(); TimePlanner.schedulerFirstLesson.shutdown();
jda.shutdown(); jda.shutdown();
} }

View file

@ -0,0 +1,25 @@
package de.limited_dev.lil_judd.consolecommand.util;
import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.consolecommand.component.ConsoleCommand;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import net.dv8tion.jda.api.entities.Guild;
public class AnnounceCommand extends ConsoleCommand {
public AnnounceCommand() {
super("announce", "Announce something to the default channel", new String[]{"Message"});
}
@Override
public void onCommand(String[] args) {
String ar = "";
for(int i = 0; i < args.length; ++i){
ar = ar + " " + args[i];
}
for(Guild g : Main.getJda().getSelfUser().getMutualGuilds()){
EmbeddedMessageHelper.sendSimpleOneLiner(g, g.getDefaultChannel().asTextChannel().getIdLong(),
"Announcement", ar, null);
}
}
}

View file

@ -11,31 +11,10 @@ public class ManualCommand extends ConsoleCommand {
@Override @Override
public void onCommand(String[] args) { public void onCommand(String[] args) {
if(args.length != 1){ if(args.length != 1){
sendUsage(this.getName()); this.sendUsage(this.getName());
return; return;
} }
String commandName = args[0]; String commandName = args[0];
sendUsage(commandName.toLowerCase()); this.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);
} }
} }

View file

@ -29,6 +29,10 @@ public class MapManager {
return md; return md;
if (md.startsWithENName(name)) if (md.startsWithENName(name))
return md; return md;
if(md.equalsDEName(name))
return md;
if(md.equalsENName(name))
return md;
} }
return null; return null;
} }

View file

@ -16,11 +16,11 @@ public class MapData {
} }
public boolean startsWithDEName(String str){ public boolean startsWithDEName(String str){
return this.nameDE.startsWith(str); return this.nameDE.toLowerCase().startsWith(str);
} }
public boolean startsWithENName(String str){ public boolean startsWithENName(String str){
return this.nameEN.startsWith(str); return this.nameEN.toLowerCase().startsWith(str);
} }
public boolean equalsENName(String str) { public boolean equalsENName(String str) {

View file

@ -1,35 +0,0 @@
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;
}
}

View file

@ -1,20 +0,0 @@
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;
}
}

View file

@ -1,97 +0,0 @@
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;
}
}

View file

@ -1,53 +0,0 @@
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);
}
}

View file

@ -29,7 +29,6 @@ public class TimePlanner {
private static final int hour = 8; private static final int hour = 8;
private static final int minute = 0; private static final int minute = 0;
private static final int second = 0; private static final int second = 0;
public static Thread sceduThr;
public static ScheduledExecutorService schedulerFirstLesson; public static ScheduledExecutorService schedulerFirstLesson;
public static GuildTimePlannerStorage getGtps() { public static GuildTimePlannerStorage getGtps() {
@ -40,15 +39,35 @@ public class TimePlanner {
// get the current ZonedDateTime of your TimeZone // get the current ZonedDateTime of your TimeZone
ZonedDateTime now = ZonedDateTime.now(ZoneId.of("Europe/Berlin")); ZonedDateTime now = ZonedDateTime.now(ZoneId.of("Europe/Berlin"));
sceduThr = new Thread(){ ZonedDateTime nextNotifyDay = now.plusDays(DayUtil.getDelay(now.getDayOfWeek().name())).withHour(hour).withMinute(minute).withSecond(second);
@Override //ZonedDateTime nextNotifyDay = now.plusSeconds(10);
public void run() { lgr.info(nextNotifyDay.getDayOfWeek() + ", " + nextNotifyDay.getDayOfMonth() + "." + nextNotifyDay.getMonth() + "." + nextNotifyDay.getYear() + " / " + nextNotifyDay.getHour() + ":" + nextNotifyDay.getMinute() + ":" + nextNotifyDay.getSecond());
//lgr.info(now.getDayOfWeek().name() + " " + nextNotifyDay.getDayOfWeek().name());
// if it's already past the time (in this case 8:05) the first lesson will be scheduled for the next day
if (now.compareTo(nextNotifyDay) > 0) {
nextNotifyDay = nextNotifyDay.plusDays(7).withHour(hour).withMinute(minute).withSecond(second);
lgr.info("Its already after 8am. Setting time to next Week");
}
// duration between now and the beginning of the next first lesson
Duration timeUntilNextNotification = Duration.between(now, nextNotifyDay);
// in seconds
long initialDelayUntilNextNotification = timeUntilNextNotification.getSeconds();
lgr.info("Duration: " + initialDelayUntilNextNotification);
// schedules the reminder at a fixed rate of one day
ScheduledExecutorService schedulerFirstLesson = Executors.newScheduledThreadPool(1);
schedulerFirstLesson.scheduleAtFixedRate(() -> {
// send a message // send a message
JDA jda = Main.getJda(); JDA jda = Main.getJda();
Set<Long> gs = gtps.guildsWithPlanner.keySet(); Set<Long> gs = gtps.guildsWithPlanner.keySet();
lgr.info(gs.toString()); lgr.info(gs.toString());
sceduThr.start(); Thread thr = new Thread(){
lgr.info("Started sending Push Notifications for time Management"); @Override
public void run() {
for(Long l : gs) { for(Long l : gs) {
ZonedDateTime then = ZonedDateTime.now(ZoneId.of("Europe/Berlin")).withHour(hour).withMinute(minute).withSecond(second); 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); EmbeddedMessageHelper.sendSimpleOneLiner(jda.getGuildById(l), gtps.guildsWithPlanner.get(l), "Timeplanning System", "Do you have time on the following Days?", null);
@ -103,34 +122,12 @@ public class TimePlanner {
} }
} }
}; };
thr.start();
lgr.info("Started sending Push Notifications for time Management");
ZonedDateTime nextNotifyDay = now.plusDays(DayUtil.getDelay(now.getDayOfWeek().name())).withHour(hour).withMinute(minute).withSecond(second);
//ZonedDateTime nextNotifyDay = now.plusSeconds(10);
lgr.info(nextNotifyDay.getDayOfWeek() + ", " + nextNotifyDay.getDayOfMonth() + "." + nextNotifyDay.getMonth() + "." + nextNotifyDay.getYear() + " / " + nextNotifyDay.getHour() + ":" + nextNotifyDay.getMinute() + ":" + nextNotifyDay.getSecond());
//lgr.info(now.getDayOfWeek().name() + " " + nextNotifyDay.getDayOfWeek().name());
// if it's already past the time (in this case 8:05) the first lesson will be scheduled for the next day
if (now.compareTo(nextNotifyDay) > 0) {
nextNotifyDay = nextNotifyDay.plusDays(7).withHour(hour).withMinute(minute).withSecond(second);
lgr.info("Its already after 8am. Setting time to next Week");
}
// duration between now and the beginning of the next first lesson
Duration timeUntilNextNotification = Duration.between(now, nextNotifyDay);
// in seconds
long initialDelayUntilNextNotification = timeUntilNextNotification.getSeconds();
lgr.info("Duration: " + initialDelayUntilNextNotification);
// schedules the reminder at a fixed rate of one day
schedulerFirstLesson = Executors.newScheduledThreadPool(1);
schedulerFirstLesson.scheduleAtFixedRate(() -> {
sceduThr.start();
}, },
initialDelayUntilNextNotification, initialDelayUntilNextNotification,
TimeUnit.DAYS.toSeconds(7), TimeUnit.DAYS.toSeconds(7),
TimeUnit.SECONDS); TimeUnit.SECONDS);
} }
} }

View file

@ -2,7 +2,6 @@ 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.RemoveFeatureCommand;
import de.limited_dev.lil_judd.jdacommands.management.SetupFeatureCommand; 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.EndScrimCommand;
import de.limited_dev.lil_judd.jdacommands.scrim.MessageScrimCommand; 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.ScrimInfoCommand;
@ -26,11 +25,6 @@ public class JDACommandManager {
commands.add(new MessageScrimCommand()); commands.add(new MessageScrimCommand());
commands.add(new ScrimInfoCommand()); commands.add(new ScrimInfoCommand());
commands.add(new TranslateCommand()); 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() { public static List<JDACommand> getCommands() {

View file

@ -1,54 +0,0 @@
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];
}
}

View file

@ -1,79 +0,0 @@
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");
}
}

View file

@ -1,54 +0,0 @@
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");
}
}

View file

@ -1,53 +0,0 @@
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");
}
}

View file

@ -1,52 +0,0 @@
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");
}
}

View file

@ -1,6 +1,7 @@
package de.limited_dev.lil_judd.jdacommands.util; package de.limited_dev.lil_judd.jdacommands.util;
import de.limited_dev.lil_judd.Main; import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.build.BuildConstants;
import de.limited_dev.lil_judd.jdacommands.components.JDACommand; import de.limited_dev.lil_judd.jdacommands.components.JDACommand;
import de.limited_dev.lil_judd.jdacommands.components.JDACommandManager; import de.limited_dev.lil_judd.jdacommands.components.JDACommandManager;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper; import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
@ -18,11 +19,11 @@ public class InfoCommand extends JDACommand {
@Override @Override
public void onSlashCommand(SlashCommandInteractionEvent event) { public void onSlashCommand(SlashCommandInteractionEvent event) {
HashMap<String, String[]> hm = new HashMap<>(); HashMap<String, String[]> hm = new HashMap<>();
hm.put("Information", new String[]{"Ping", "Uptime", "RAM", "# Commands"}); hm.put("Information", new String[]{"Version", "Ping", "Uptime", "RAM", "# Commands"});
hm.put("Value", new String[]{Main.getJda().getGatewayPing() + "ms", TimeUtil.getTimeFormatedShortend(Main.getUptime()), hm.put("Value", new String[]{BuildConstants.botVersion, 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() + "%" (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() + ""}); , JDACommandManager.getCommands().size() + ""});
EmbeddedMessageHelper.sendWithTable(event, Main.getJda().getSelfUser().getName(), "Bot information", Color.YELLOW, Main.getJda().getSelfUser().getAvatarUrl(), "General information about the bot", EmbeddedMessageHelper.sendWithTable(event, Main.getJda().getSelfUser().getName() + " " + BuildConstants.botVersion, "Bot information", Color.YELLOW, Main.getJda().getSelfUser().getAvatarUrl(), "General information about the bot",
new String[]{"Information", "Value"}, hm, true); new String[]{"Information", "Value"}, hm, true);
} }
} }

View file

@ -32,13 +32,7 @@ public class SlashCommandRegister {
.addOptions(new OptionData(OptionType.STRING, "message", "Message content", true)), .addOptions(new OptionData(OptionType.STRING, "message", "Message content", true)),
Commands.slash("scriminfo", "Show info about the scrim system."), Commands.slash("scriminfo", "Show info about the scrim system."),
Commands.slash("translatemap", "Translate a Map") Commands.slash("translatemap", "Translate a Map")
.addOptions(new OptionData(OptionType.STRING, "map", "Map Name", true)), .addOptions(new OptionData(OptionType.STRING, "map", "Map Name", true))
Commands.slash("play", "Play music with the bot")
.addOptions(new OptionData(OptionType.STRING, "linkquery", "YouTube Link / 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(); ).queue();
} }
} }

View file

@ -0,0 +1,5 @@
package de.limited_dev.lil_judd.build;
public class BuildConstants{
public static String botVersion = "${version}";
}