Skip to content

Commit

Permalink
Allow configurable default skip ratio (#1140)
Browse files Browse the repository at this point in the history
* Allow configurable default skip ratio

Revert "Allow configurable default skip ratio"

This reverts commit 10e38b4.

* FIX: Use -1 to denote a guild has not set a skip ratio, and opted to use the bot default.
  • Loading branch information
t3rminus authored Mar 2, 2024
1 parent 23c2dfa commit 8a1066c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/main/java/com/jagrosh/jmusicbot/BotConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class BotConfig
successEmoji, warningEmoji, errorEmoji, loadingEmoji, searchingEmoji;
private boolean stayInChannel, songInGame, npImages, updatealerts, useEval, dbots;
private long owner, maxSeconds, aloneTimeUntilStop;
private double skipratio;
private OnlineStatus status;
private Activity game;
private Config aliases, transforms;
Expand Down Expand Up @@ -91,6 +92,7 @@ public void load()
playlistsFolder = config.getString("playlistsfolder");
aliases = config.getConfig("aliases");
transforms = config.getConfig("transforms");
skipratio = config.getDouble("skipratio");
dbots = owner == 113156185389092864L;

// we may need to write a new config file
Expand Down Expand Up @@ -231,6 +233,11 @@ public String getToken()
return token;
}

public double getSkipRatio()
{
return skipratio;
}

public long getOwnerId()
{
return owner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ public void doCommand(CommandEvent event)
{
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
RequestMetadata rm = handler.getRequestMetadata();
if(event.getAuthor().getIdLong() == rm.getOwner())
double skipRatio = bot.getSettingsManager().getSettings(event.getGuild()).getSkipRatio();
if(skipRatio == -1) {
skipRatio = bot.getConfig().getSkipRatio();
}
if(event.getAuthor().getIdLong() == rm.getOwner() || skipRatio == 0)
{
event.reply(event.getClient().getSuccess()+" Skipped **"+handler.getPlayer().getPlayingTrack().getInfo().title+"**");
handler.getPlayer().stopTrack();
Expand All @@ -61,7 +65,7 @@ public void doCommand(CommandEvent event)
}
int skippers = (int)event.getSelfMember().getVoiceState().getChannel().getMembers().stream()
.filter(m -> handler.getVotes().contains(m.getUser().getId())).count();
int required = (int)Math.ceil(listeners * bot.getSettingsManager().getSettings(event.getGuild()).getSkipRatio());
int required = (int)Math.ceil(listeners * skipRatio);
msg += skippers + " votes, " + required + "/" + listeners + " needed]`";
if(skippers>=required)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
*/
public class SettingsManager implements GuildSettingsManager<Settings>
{
private final static double SKIP_RATIO = .55;
private final HashMap<Long,Settings> settings;

public SettingsManager()
{
this.settings = new HashMap<>();

try {
JSONObject loadedSettings = new JSONObject(new String(Files.readAllBytes(OtherUtil.getPath("serversettings.json"))));
loadedSettings.keySet().forEach((id) -> {
Expand All @@ -56,7 +56,7 @@ public SettingsManager()
o.has("default_playlist")? o.getString("default_playlist") : null,
o.has("repeat_mode") ? o.getEnum(RepeatMode.class, "repeat_mode"): RepeatMode.OFF,
o.has("prefix") ? o.getString("prefix") : null,
o.has("skip_ratio") ? o.getDouble("skip_ratio") : SKIP_RATIO));
o.has("skip_ratio") ? o.getDouble("skip_ratio") : -1));
});
} catch (NoSuchFileException e) {
// create an empty json file
Expand Down Expand Up @@ -93,7 +93,7 @@ public Settings getSettings(long guildId)

private Settings createDefaultSettings()
{
return new Settings(this, 0, 0, 0, 100, null, RepeatMode.OFF, null, SKIP_RATIO);
return new Settings(this, 0, 0, 0, 100, null, RepeatMode.OFF, null, -1);
}

protected void writeSettings()
Expand All @@ -116,7 +116,7 @@ protected void writeSettings()
o.put("repeat_mode", s.getRepeatMode());
if(s.getPrefix() != null)
o.put("prefix", s.getPrefix());
if(s.getSkipRatio() != SKIP_RATIO)
if(s.getSkipRatio() != -1)
o.put("skip_ratio", s.getSkipRatio());
obj.put(Long.toString(key), o);
});
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ stayinchannel = false
maxtime = 0


// This sets the ratio of users that must vote to skip the currently playing song.
// Guild owners can define their own skip ratios, but this will be used if a guild
// has not defined their own skip ratio.

skipratio = 0.55


// This sets the amount of seconds the bot will stay alone on a voice channel until it
// automatically leaves the voice channel and clears the queue. If not set or set
// to any number less than or equal to zero, the bot won't leave when alone.
Expand Down

1 comment on commit 8a1066c

@Toodo
Copy link

@Toodo Toodo commented on 8a1066c Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello
i updated to bot today and i added "skipratio = 0.00" to my config.txt but when i type .setskip it says: default is 55
i dont want any vote skip on my bot

Please sign in to comment.