Skip to content

Commit

Permalink
Merge pull request #69 from nano-devs/development
Browse files Browse the repository at this point in the history
Development: Deafened by default
  • Loading branch information
madeyoga authored Nov 22, 2020
2 parents dca0e5a + beb2939 commit 2794b51
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 20 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
42 changes: 42 additions & 0 deletions py/vote_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
16 changes: 15 additions & 1 deletion src/main/java/command/music/JoinCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())) {
Expand All @@ -39,6 +42,17 @@ protected void execute(CommandEvent event) {
}
}
event.getGuild().getAudioManager().openAudioConnection(channel);
event.reply(":white_check_mark: | Connected to " + channel.getName());

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() + "`");
}
}
11 changes: 11 additions & 0 deletions src/main/java/command/music/KaraokeModeCommand.java
Original file line number Diff line number Diff line change
@@ -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) {

}
}
32 changes: 32 additions & 0 deletions src/main/java/command/owner/ApplyBassFilterCommand.java
Original file line number Diff line number Diff line change
@@ -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());
// }
}
}
49 changes: 48 additions & 1 deletion src/main/java/listener/MemberVoiceListener.java
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -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.
Expand All @@ -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;
}
Expand All @@ -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()) {
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/service/music/filter/BassBoostFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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 };

private final EqualizerFactory equalizer;
private final AudioPlayer player;

public BassBoostFilter(AudioPlayer player) {
this.equalizer = new EqualizerFactory();
this.player = player;
this.player.setFilterFactory(equalizer);
}

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);
}
}
}
16 changes: 0 additions & 16 deletions src/main/java/service/music/filter/CustomFilter.java

This file was deleted.

17 changes: 17 additions & 0 deletions src/main/java/service/music/setting/BoostSetting.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 2794b51

Please sign in to comment.