i have to do it

This commit is contained in:
Chayapak 2023-08-23 16:27:44 +07:00
parent 413592c64f
commit 3003052c78
4 changed files with 23 additions and 11 deletions

View file

@ -21,6 +21,7 @@ public class Configuration {
public Core core = new Core();
public Discord discord = new Discord();
public Music music = new Music();
public ColorPalette colorPalette = new ColorPalette();
@ -91,6 +92,15 @@ public class Configuration {
public String inviteLink = "https://discord.gg/xdgCkUyaA4";
}
public static class Music {
public URLRatelimit urlRatelimit = new URLRatelimit();
public static class URLRatelimit {
public int seconds = 15;
public int limit = 7;
}
}
public static class EmbedColors {
public String normal = "#FFFF00";
public String error = "#FF0000";

View file

@ -37,8 +37,6 @@ public class MusicPlayerPlugin extends Bot.Listener {
}
}
public int loadings = 0;
public Song currentSong;
public final List<Song> songQueue = new ArrayList<>();
public SongLoaderRunnable loaderThread;
@ -54,6 +52,8 @@ public class MusicPlayerPlugin extends Bot.Listener {
private int notesPerSecond = 0;
private int limit = 0;
private final String bossbarName = "music";
public MusicPlayerPlugin (Bot bot) {
@ -62,7 +62,8 @@ public class MusicPlayerPlugin extends Bot.Listener {
bot.core.addListener(new CorePlugin.Listener() {
public void ready () { coreReady(); }
});
bot.executor.scheduleAtFixedRate(() -> notesPerSecond = 0, 0, 10, TimeUnit.SECONDS);
bot.executor.scheduleAtFixedRate(() -> notesPerSecond = 0, 0, 1, TimeUnit.SECONDS);
bot.executor.scheduleAtFixedRate(() -> limit = 0, 0, bot.config.music.urlRatelimit.seconds, TimeUnit.SECONDS);
}
public void loadSong (Path location) {
@ -81,13 +82,13 @@ public class MusicPlayerPlugin extends Bot.Listener {
}
public void loadSong (URL location) {
if (loadings > 7) {
limit++;
if (limit > bot.config.music.urlRatelimit.limit) {
bot.chat.tellraw(Component.text("ohio").color(NamedTextColor.RED));
return;
}
loadings++;
final SongLoaderRunnable runnable = new SongLoaderRunnable(location, bot);
bot.chat.tellraw(
@ -290,7 +291,7 @@ public class MusicPlayerPlugin extends Bot.Listener {
while (currentSong.reachedNextNote()) {
final Note note = currentSong.getNextNote();
if (notesPerSecond > 2048 && bot.core.hasRateLimit()) continue;
if (notesPerSecond > 700) continue;
float key = note.pitch;

View file

@ -71,8 +71,6 @@ public class SongLoaderRunnable implements Runnable {
if (isUrl) {
bytes = DownloadUtilities.DownloadToByteArray(songUrl, 5 * 1024 * 1024);
name = Paths.get(songUrl.toURI().getPath()).getFileName().toString();
bot.music.loadings--;
} else {
bytes = Files.readAllBytes(songPath);
name = !isFolder ? fileName : songPath.getFileName().toString();
@ -131,7 +129,5 @@ public class SongLoaderRunnable implements Runnable {
exception.printStackTrace();
bot.chat.tellraw(Component.translatable("Failed to load song: %s", exception.message).color(NamedTextColor.RED));
bot.music.loaderThread = null;
if (isUrl) bot.music.loadings--;
}
}

View file

@ -34,6 +34,11 @@ discord:
servers:
localhost:25565: 'channel id'
music:
URLRatelimit:
seconds: 15
limit: 7
colorPalette:
primary: 'yellow'
secondary: 'gold'