Skip to content

Commit

Permalink
New BassBoost command
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicTeaMC committed Oct 2, 2024
1 parent 0278e4e commit a27f74b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/jagrosh/jmusicbot/JMusicBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public static void main(String[] args) {
new SeekCmd(bot),
new skipSegCmd(bot),

new BassBoostCmd(bot),
new ForceRemoveCmd(bot),
new ForceskipCmd(bot),
new MoveTrackCmd(bot),
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/com/jagrosh/jmusicbot/audio/PlayerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ public PlayerManager(Bot bot) {
this.bot = bot;
}

String clientId = "f5c61bf239ec41e18756db119436c418";
String clientSecret = "2c2e6b4926204f2cb1ad0b2d8c2fca51";
String spDc = "AQASquIDa6JW3xiRbm3tvM9JFXt8gglWPHelVa89aAIbRp5JNVV7BX2RDF0dU5fb27Ei6WRFCcnHO9gZDNAUYhSjd5n_PQ0nk-p1dPOmMdehfSXZOsYHpl5heMkfjtyJ7qlA_LYbOvqb07gajDdFrcKkTi2BZUXYadb3OWezd9CJJJ7gWWmeQbtO0h0P6i_KStVmBVAGGTGOaDQiBROW8mF5Ljoc";

public void init() {
TransformativeAudioSourceManager.createTransforms(bot.getConfig().getTransforms()).forEach(this::registerSourceManager);

Expand Down Expand Up @@ -104,12 +100,12 @@ public void init() {

Function<Void, AudioPlayerManager> audioPlayerManagerFunction = (v) -> this;

SpotifySourceManager spotifyly = new SpotifySourceManager(clientId, clientSecret, spDc, "us", audioPlayerManagerFunction, new DefaultMirroringAudioTrackResolver(new String[]{"ytsearch:"}));
SpotifySourceManager spotifyly = new SpotifySourceManager(bot.getConfig().getSpotifyClientId(), bot.getConfig().getSpotifyClientSecret(), bot.getConfig().getSpDc(), "us", audioPlayerManagerFunction, new DefaultMirroringAudioTrackResolver(new String[]{"ytsearch:"}));

lyricsManager.registerLyricsManager(spotifyly);

registerSourceManager(yt);
registerSourceManager(new SpotifySourceManager(null, clientId, clientSecret, "us", this));
registerSourceManager(new SpotifySourceManager(null, bot.getConfig().getSpotifyClientId(), bot.getConfig().getSpotifyClientSecret(), "us", this));
registerSourceManager(new BilibiliAudioSourceManager());
registerSourceManager(new OdyseeAudioSourceManager());
registerSourceManager(SoundCloudAudioSourceManager.createDefault());
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/com/jagrosh/jmusicbot/commands/dj/BassBoostCmd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.jagrosh.jmusicbot.commands.dj;

import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.commands.DJCommand;
import com.jagrosh.jmusicbot.utils.FormatUtil;
import com.sedmelluq.discord.lavaplayer.filter.equalizer.EqualizerFactory;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;

public class BassBoostCmd extends DJCommand {
private static final float[] BASS_BOOST = {0.05f, 0.05f, 0.05f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, -0.05f, -0.05f, -0.05f};

private static final float MULT_CONSTANT = 0.01f;

private final EqualizerFactory equalizer;

public BassBoostCmd(Bot bot) {
super(bot);
this.name = "bassboost";
this.aliases = bot.getConfig().getAliases(this.name);
this.equalizer = new EqualizerFactory();
this.help = "設定或是顯示重低音調整(預設為0)";
this.arguments = "[0-100]";
for (int i = 0; i < BASS_BOOST.length; i++) {
equalizer.setGain(i, BASS_BOOST[i]);
}
}

@Override
public void doCommand(CommandEvent event) {
AudioHandler handler = (AudioHandler) event.getGuild().getAudioManager().getSendingHandler();
AudioPlayer player = handler.getPlayer();
int bassboost = Math.round(this.equalizer.getGain(3) / MULT_CONSTANT);
player.setFilterFactory(equalizer);
if (event.getArgs().isEmpty()) {
event.reply(FormatUtil.volumeIcon(bassboost) + " 現在的重低音等級為 `" + bassboost + "`");
} else {
int nbassboost;
try {
nbassboost = Integer.parseInt(event.getArgs());
} catch (NumberFormatException e) {
nbassboost = -1;
}
if (nbassboost < 0 || nbassboost > 100)
event.reply(event.getClient().getError() +
" 重低音等級要在 1~100 之間");
else {
for (int i = 0; i < BASS_BOOST.length; i++) {
equalizer.setGain(i, BASS_BOOST[i] + MULT_CONSTANT * nbassboost);
}
event.reply(FormatUtil.volumeIcon(nbassboost) +
" 重低音等級調整至 `" + nbassboost + "`");
}
}
}
}

0 comments on commit a27f74b

Please sign in to comment.