From 4220a798de71873065b8e78a3b991da047e51648 Mon Sep 17 00:00:00 2001 From: r4nx Date: Mon, 9 Jan 2023 21:54:50 +0200 Subject: [PATCH] Add updatenp and updatenptime options --- .../java/com/jagrosh/jmusicbot/BotConfig.java | 16 ++++++++++++++-- .../jmusicbot/audio/NowplayingHandler.java | 8 ++++++-- src/main/resources/reference.conf | 9 +++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/jagrosh/jmusicbot/BotConfig.java b/src/main/java/com/jagrosh/jmusicbot/BotConfig.java index 1e1b6c100..7f45f9eee 100644 --- a/src/main/java/com/jagrosh/jmusicbot/BotConfig.java +++ b/src/main/java/com/jagrosh/jmusicbot/BotConfig.java @@ -41,8 +41,8 @@ public class BotConfig private Path path = null; private String token, prefix, altprefix, helpWord, playlistsFolder, successEmoji, warningEmoji, errorEmoji, loadingEmoji, searchingEmoji; - private boolean stayInChannel, songInGame, npImages, updatealerts, useEval, dbots; - private long owner, maxSeconds, aloneTimeUntilStop; + private boolean stayInChannel, songInGame, updateNP, npImages, updatealerts, useEval, dbots; + private long owner, updateNPTime, maxSeconds, aloneTimeUntilStop; private OnlineStatus status; private Activity game; private Config aliases, transforms; @@ -83,6 +83,8 @@ public void load() status = OtherUtil.parseStatus(config.getString("status")); stayInChannel = config.getBoolean("stayinchannel"); songInGame = config.getBoolean("songinstatus"); + updateNP = config.getBoolean("updatenp"); + updateNPTime = config.getLong("updatenptime"); npImages = config.getBoolean("npimages"); updatealerts = config.getBoolean("updatealerts"); useEval = config.getBoolean("eval"); @@ -306,6 +308,16 @@ public boolean useEval() return useEval; } + public boolean getUpdateNP() + { + return updateNP; + } + + public long getUpdateNPTime() + { + return updateNPTime; + } + public boolean useNPImages() { return npImages; diff --git a/src/main/java/com/jagrosh/jmusicbot/audio/NowplayingHandler.java b/src/main/java/com/jagrosh/jmusicbot/audio/NowplayingHandler.java index 5d96e7df9..cbca3e7d9 100644 --- a/src/main/java/com/jagrosh/jmusicbot/audio/NowplayingHandler.java +++ b/src/main/java/com/jagrosh/jmusicbot/audio/NowplayingHandler.java @@ -48,8 +48,12 @@ public NowplayingHandler(Bot bot) public void init() { - if(!bot.getConfig().useNPImages()) - bot.getThreadpool().scheduleWithFixedDelay(() -> updateAll(), 0, 5, TimeUnit.SECONDS); + if(bot.getConfig().getUpdateNP() && !bot.getConfig().useNPImages()) + bot.getThreadpool().scheduleWithFixedDelay( + () -> updateAll(), + 0, + bot.getConfig().getUpdateNPTime(), + TimeUnit.SECONDS); } public void setLastNPMessage(Message m) diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf index b74103b3e..05a0a9a01 100644 --- a/src/main/resources/reference.conf +++ b/src/main/resources/reference.conf @@ -77,6 +77,15 @@ searching = "🔎" help = help +// If you set this, the "nowplaying" command will refresh every n-seconds, +// specified in option "updatenptime" below. +updatenp = true + + +// This sets the amount of seconds of "nowplaying" refreshing interval. +updatenptime = 5 + + // If you set this, the "nowplaying" command will show youtube thumbnails // Note: If you set this to true, the nowplaying boxes will NOT refresh // This is because refreshing the boxes causes the image to be reloaded