From 7942987f78150b34d1d3d9e757ecad2a59ffee08 Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Sun, 22 Nov 2020 16:20:44 +0700 Subject: [PATCH 1/5] Update webhook --- py/vote_webhook.py | 42 +++++++++++++++++++ ...CustomFilter.java => BassBoostFilter.java} | 9 +++- 2 files changed, 49 insertions(+), 2 deletions(-) rename src/main/java/service/music/filter/{CustomFilter.java => BassBoostFilter.java} (60%) diff --git a/py/vote_webhook.py b/py/vote_webhook.py index 7963188..0ebb7fc 100644 --- a/py/vote_webhook.py +++ b/py/vote_webhook.py @@ -109,6 +109,48 @@ def vote_post(): return 'success', 200 +@app.route('/dbl/', methods = ['POST']) +def vote_post_dbl(): + + headers = dict(flask.request.headers) + # Invalid Authorization code + if headers["Authorization"] != VOTE_AUTH_TOKEN: + return 'error', 401 + + connection = mysql.connector.connect(user=user, + password=password, + host='127.0.0.1', + database='nano') + cursor = connection.cursor() + + data = flask.request.get_json(force=True) + + user_id = data['id'] + + print("Upvote", data) + + # Vote history + cursor.execute(insert_vote_query.format(user_id, 0)) + connection.commit() + + # Check if user exist + cursor.execute(check_user_query.format(user_id)) + cursor.fetchall() + + # If user not exist, create new. + if cursor.rowcount == 0: + print("user does not exist") + cursor.execute(create_user_query.format(user_id)) + + cursor.execute(update_rewards_query.format(user_id)) + + connection.commit() + + cursor.close() + connection.close() + + return 'success', 200 + if __name__ == '__main__': app.run(host="0.0.0.0", port="5000") print("End") diff --git a/src/main/java/service/music/filter/CustomFilter.java b/src/main/java/service/music/filter/BassBoostFilter.java similarity index 60% rename from src/main/java/service/music/filter/CustomFilter.java rename to src/main/java/service/music/filter/BassBoostFilter.java index dadfdf1..5f01c88 100644 --- a/src/main/java/service/music/filter/CustomFilter.java +++ b/src/main/java/service/music/filter/BassBoostFilter.java @@ -1,16 +1,21 @@ package service.music.filter; import com.sedmelluq.discord.lavaplayer.filter.equalizer.EqualizerFactory; +import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; -public class CustomFilter { +public class BassBoostFilter { private static final float[] BASS_BOOST = { 0.2f, 0.15f, 0.1f, 0.05f, 0.0f, -0.05f, -0.1f, -0.1f, -0.1f, -0.1f, -0.1f, -0.1f, -0.1f, -0.1f, -0.1f }; private final EqualizerFactory equalizer; + private final AudioPlayer player; - public CustomFilter() { + public BassBoostFilter(AudioPlayer player) { this.equalizer = new EqualizerFactory(); + this.player = player; } + public void applyFilters() { + } } From 6366413301abf8e0a1ec2795ac71fcfabc11ebac Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Sun, 22 Nov 2020 16:21:52 +0700 Subject: [PATCH 2/5] Update lavaplayer version & Add lavadsp filter --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index fa848ae..107c26e 100644 --- a/build.gradle +++ b/build.gradle @@ -23,8 +23,8 @@ dependencies { compile 'com.jagrosh:jda-utilities:3.0.4' compile group: 'commons-validator', name: 'commons-validator', version: '1.4.0' compile 'joda-time:joda-time:2.10.6' -// implementation 'com.sedmelluq:lavaplayer:1.3.59' - implementation 'com.github.madeyoga:lavaplayer:1.3.61' + implementation 'com.sedmelluq:lavaplayer:1.3.61' + compile 'com.github.natanbc:lavadsp:0.7.4' implementation 'com.github.Shiroechi:YoutubeSearchApi-Java:1.2.6' implementation 'mysql:mysql-connector-java:8.0.21' implementation 'com.github.top-gg:donatebot-java-api:1.0.1' From 01b583aaad8be712030e25fb89bce135a3e2282b Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Sun, 22 Nov 2020 16:22:28 +0700 Subject: [PATCH 3/5] Update JoinCommand's reply --- src/main/java/command/music/JoinCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/command/music/JoinCommand.java b/src/main/java/command/music/JoinCommand.java index b5af492..0d185bc 100644 --- a/src/main/java/command/music/JoinCommand.java +++ b/src/main/java/command/music/JoinCommand.java @@ -39,6 +39,6 @@ protected void execute(CommandEvent event) { } } event.getGuild().getAudioManager().openAudioConnection(channel); - event.reply(":white_check_mark: | Connected to " + channel.getName()); + event.reply(":white_check_mark: | Connected to :loud_sound: `" + channel.getName() + "`"); } } From 0863420eefb5cd056f3eaa34459f4aa9c2cb72a5 Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Sun, 22 Nov 2020 17:12:32 +0700 Subject: [PATCH 4/5] Add self deafen handler --- src/main/java/command/music/JoinCommand.java | 14 ++++++ .../java/listener/MemberVoiceListener.java | 49 ++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/main/java/command/music/JoinCommand.java b/src/main/java/command/music/JoinCommand.java index 0d185bc..0634cec 100644 --- a/src/main/java/command/music/JoinCommand.java +++ b/src/main/java/command/music/JoinCommand.java @@ -3,7 +3,9 @@ import client.NanoClient; import com.jagrosh.jdautilities.command.Command; import com.jagrosh.jdautilities.command.CommandEvent; +import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.VoiceChannel; +import service.music.CustomEmbedBuilder; import service.music.GuildMusicManager; import service.music.HelpProcess; import service.music.MusicUtils; @@ -31,6 +33,7 @@ protected void execute(CommandEvent event) { } GuildMusicManager musicManager = nanoClient.getGuildAudioPlayer(event.getGuild()); + musicManager.scheduler.textChannel = event.getTextChannel(); if (musicManager.isInDjMode()) { if (!MusicUtils.hasDjRole(event.getMember())) { @@ -39,6 +42,17 @@ protected void execute(CommandEvent event) { } } event.getGuild().getAudioManager().openAudioConnection(channel); + + if (!event.getSelfMember().hasPermission(Permission.VOICE_DEAF_OTHERS) && + !event.getSelfMember().getVoiceState().isDeafened()) { + CustomEmbedBuilder embedBuilder = new CustomEmbedBuilder(); + embedBuilder.addField(":warning: Missing Permission: `Deafen Members`!", + "Please don't undeafen me! I work better by being deafened because: " + + "Less lag, more clear, better quality, and doesn't randomly disconnect", + true); + event.reply(embedBuilder.build()); + } + event.reply(":white_check_mark: | Connected to :loud_sound: `" + channel.getName() + "`"); } } diff --git a/src/main/java/listener/MemberVoiceListener.java b/src/main/java/listener/MemberVoiceListener.java index 776259e..8893440 100644 --- a/src/main/java/listener/MemberVoiceListener.java +++ b/src/main/java/listener/MemberVoiceListener.java @@ -1,16 +1,21 @@ package listener; import client.NanoClient; +import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.entities.VoiceChannel; +import net.dv8tion.jda.api.events.guild.voice.GuildVoiceDeafenEvent; import net.dv8tion.jda.api.events.guild.voice.GuildVoiceJoinEvent; import net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent; import net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import org.jetbrains.annotations.NotNull; +import service.music.CustomEmbedBuilder; import service.music.GuildMusicManager; import java.util.concurrent.*; +import java.util.regex.Pattern; public class MemberVoiceListener extends ListenerAdapter { @@ -110,6 +115,25 @@ public void onGuildVoiceMove(@NotNull GuildVoiceMoveEvent event) { @Override public void onGuildVoiceJoin(@NotNull GuildVoiceJoinEvent event) { + // if self join voice channel + if (event.getMember().getId().equals(event.getGuild().getSelfMember().getId())) { + if (event.getGuild().getSelfMember().hasPermission(Permission.VOICE_DEAF_OTHERS)) { + event.getMember().deafen(true).queue(); + } +// else { +// TextChannel textChannel = nanoClient.getGuildAudioPlayer(event.getGuild()).scheduler.textChannel; +// +// CustomEmbedBuilder embedBuilder = new CustomEmbedBuilder(); +// embedBuilder.addField(":warning: Missing Permission: `Deafen Members`!", +// "Please don't undeafen me! I work better by being deafened because: " + +// "Less lag, more clear, better quality, and doesn't randomly disconnect", +// true); +// +// textChannel.sendMessage(embedBuilder.build()).queue(); +// } + return; + } + VoiceChannel clientVoiceChannel = event.getGuild().getAudioManager().getConnectedChannel(); // Ignore if bot event. @@ -122,7 +146,7 @@ public void onGuildVoiceJoin(@NotNull GuildVoiceJoinEvent event) { return; } - // Ignore join event to other voice channel. + // Ignore join event from other voice channel. if (!clientVoiceChannel.getId().equals(event.getChannelJoined().getId())) { return; } @@ -137,6 +161,29 @@ public void onGuildVoiceJoin(@NotNull GuildVoiceJoinEvent event) { super.onGuildVoiceJoin(event); } + @Override + public void onGuildVoiceDeafen(@NotNull GuildVoiceDeafenEvent event) { + super.onGuildVoiceDeafen(event); + + // if other users try to undeafen bot. + if (!event.isDeafened() && event.getMember().getId().equals(event.getGuild().getSelfMember().getId())) { + if (event.getMember().hasPermission(Permission.VOICE_DEAF_OTHERS)) { + event.getGuild().getSelfMember().deafen(true).queue(); + } +// else { +// TextChannel textChannel = nanoClient.getGuildAudioPlayer(event.getGuild()).scheduler.textChannel; +// +// CustomEmbedBuilder embedBuilder = new CustomEmbedBuilder(); +// embedBuilder.addField(":warning: Missing Permission: `Deafen Members`!", +// "Please don't undeafen me! I work better by being deafened because: " + +// "Less lag, more clear, better quality, and doesn't randomly disconnect", +// true); +// +// textChannel.sendMessage(embedBuilder.build()).queue(); +// } + } + } + private boolean isThereAnyMemberIn(VoiceChannel channel) { boolean foundMemberFlag = false; for (Member member : channel.getMembers()) { From beb2939973e3dd0d8f8fc86da0129f70051af054 Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Sun, 22 Nov 2020 18:54:20 +0700 Subject: [PATCH 5/5] Update equalizer objects --- .../command/music/KaraokeModeCommand.java | 11 +++++++ .../command/owner/ApplyBassFilterCommand.java | 32 +++++++++++++++++++ .../service/music/filter/BassBoostFilter.java | 15 ++++++++- .../service/music/setting/BoostSetting.java | 17 ++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/main/java/command/music/KaraokeModeCommand.java create mode 100644 src/main/java/command/owner/ApplyBassFilterCommand.java create mode 100644 src/main/java/service/music/setting/BoostSetting.java diff --git a/src/main/java/command/music/KaraokeModeCommand.java b/src/main/java/command/music/KaraokeModeCommand.java new file mode 100644 index 0000000..46cd25a --- /dev/null +++ b/src/main/java/command/music/KaraokeModeCommand.java @@ -0,0 +1,11 @@ +package command.music; + +import com.jagrosh.jdautilities.command.Command; +import com.jagrosh.jdautilities.command.CommandEvent; + +public class KaraokeModeCommand extends Command { + @Override + protected void execute(CommandEvent event) { + + } +} diff --git a/src/main/java/command/owner/ApplyBassFilterCommand.java b/src/main/java/command/owner/ApplyBassFilterCommand.java new file mode 100644 index 0000000..96f1d91 --- /dev/null +++ b/src/main/java/command/owner/ApplyBassFilterCommand.java @@ -0,0 +1,32 @@ +package command.owner; + +import com.jagrosh.jdautilities.command.Command; +import com.jagrosh.jdautilities.command.CommandEvent; +import service.music.GuildMusicManager; + +public class ApplyBassFilterCommand extends Command { + public ApplyBassFilterCommand() { + this.name = "ab"; + this.category = new Category("Owner"); + this.ownerCommand = true; + } + @Override + protected void execute(CommandEvent event) { + String args = event.getArgs(); + + String[] splitArgs = args.split(" "); + + float diff = Float.parseFloat(splitArgs[1]); + + GuildMusicManager musicManager = event.getClient().getSettingsFor(event.getGuild()); + +// if (splitArgs[0].equals("h")) { +// musicManager.getBassBoostFilter().applyHighBass(diff); +// event.reply("Equalizer: HighBass filter applied with diff " + event.getArgs()); +// } +// else { +// musicManager.getBassBoostFilter().applyLowBass(diff); +// event.reply("Equalizer: LowBass filter applied with diff " + event.getArgs()); +// } + } +} diff --git a/src/main/java/service/music/filter/BassBoostFilter.java b/src/main/java/service/music/filter/BassBoostFilter.java index 5f01c88..071c0dd 100644 --- a/src/main/java/service/music/filter/BassBoostFilter.java +++ b/src/main/java/service/music/filter/BassBoostFilter.java @@ -1,9 +1,13 @@ package service.music.filter; +import com.github.natanbc.lavadsp.karaoke.KaraokePcmAudioFilter; import com.sedmelluq.discord.lavaplayer.filter.equalizer.EqualizerFactory; import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; +import java.util.Collections; + public class BassBoostFilter { + private static final float[] BASS_BOOST = { 0.2f, 0.15f, 0.1f, 0.05f, 0.0f, -0.05f, -0.1f, -0.1f, -0.1f, -0.1f, -0.1f, -0.1f, -0.1f, -0.1f, -0.1f }; @@ -13,9 +17,18 @@ public class BassBoostFilter { public BassBoostFilter(AudioPlayer player) { this.equalizer = new EqualizerFactory(); this.player = player; + this.player.setFilterFactory(equalizer); } - public void applyFilters() { + public void applyHighBass(float diff) { + for (int i = 0; i < BASS_BOOST.length; i++) { + equalizer.setGain(i, BASS_BOOST[i] + diff); + } + } + public void applyLowBass(float diff) { + for (int i = 0; i < BASS_BOOST.length; i++) { + equalizer.setGain(i, -BASS_BOOST[i] + diff); + } } } diff --git a/src/main/java/service/music/setting/BoostSetting.java b/src/main/java/service/music/setting/BoostSetting.java new file mode 100644 index 0000000..bc0aab8 --- /dev/null +++ b/src/main/java/service/music/setting/BoostSetting.java @@ -0,0 +1,17 @@ +package service.music.setting; + +public enum BoostSetting { + OFF(0.0F, 0.0F), + SOFT(0.25F, 0.15F), + HARD(0.50F, 0.25F), + EXTREME(0.75F, 0.50F), + MINDBEND(1F, 0.75F); + + public final float band1; + public final float band2; + + BoostSetting(float band1, float band2) { + this.band1 = band1; + this.band2 = band2; + } +}