All easyfix done
This commit is contained in:
parent
fbeb9b18fe
commit
53417bd700
@ -1,51 +1,46 @@
|
|||||||
package net.Broken.Api.Security;
|
package net.Broken.Api.Security;
|
||||||
|
|
||||||
|
import static org.springframework.security.config.Customizer.withDefaults;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
|
import org.springframework.security.config.http.SessionCreationPolicy;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||||
|
|
||||||
import net.Broken.Api.Security.Components.UnauthorizedHandler;
|
import net.Broken.Api.Security.Components.UnauthorizedHandler;
|
||||||
import net.Broken.Api.Security.Filters.JwtFilter;
|
import net.Broken.Api.Security.Filters.JwtFilter;
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
||||||
import org.springframework.security.config.http.SessionCreationPolicy;
|
|
||||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
|
||||||
|
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
@Configuration
|
@Configuration
|
||||||
public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
public class SecurityConfig {
|
||||||
private final UnauthorizedHandler unauthorizedHandler;
|
private final UnauthorizedHandler unauthorizedHandler;
|
||||||
public SecurityConfig(UnauthorizedHandler unauthorizedHandler) {
|
public SecurityConfig(UnauthorizedHandler unauthorizedHandler) {
|
||||||
this.unauthorizedHandler = unauthorizedHandler;
|
this.unauthorizedHandler = unauthorizedHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Bean
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
http.cors().and().csrf().disable()
|
http.cors(withDefaults()).csrf(csrf-> csrf.disable())
|
||||||
.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
|
.exceptionHandling(handling -> handling.authenticationEntryPoint(unauthorizedHandler))
|
||||||
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
|
.sessionManagement(management -> management.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||||
.authorizeRequests()
|
.authorizeHttpRequests(requests -> requests
|
||||||
.antMatchers("/api/v2/auth/**").permitAll()
|
.antMatchers("/api/v2/auth/**").permitAll()
|
||||||
.antMatchers("/api/v2/guild/inviteLink").permitAll()
|
.antMatchers("/api/v2/guild/inviteLink").permitAll()
|
||||||
.antMatchers("/swagger-ui/**").permitAll()
|
.antMatchers("/swagger-ui/**").permitAll()
|
||||||
.antMatchers("/swagger-ui.html").permitAll()
|
.antMatchers("/swagger-ui.html").permitAll()
|
||||||
.antMatchers("/v3/api-docs/**").permitAll()
|
.antMatchers("/v3/api-docs/**").permitAll()
|
||||||
.antMatchers("/actuator/**").permitAll()
|
.antMatchers("/actuator/**").permitAll()
|
||||||
.anyRequest().authenticated();
|
.anyRequest().authenticated());
|
||||||
|
|
||||||
http.addFilterBefore(jwtFilter(), UsernamePasswordAuthenticationFilter.class);
|
http.addFilterBefore(jwtFilter(), UsernamePasswordAuthenticationFilter.class);
|
||||||
|
return http.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public JwtFilter jwtFilter(){
|
public JwtFilter jwtFilter(){
|
||||||
return new JwtFilter();
|
return new JwtFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@Override
|
|
||||||
public AuthenticationManager authenticationManagerBean() throws Exception {
|
|
||||||
return super.authenticationManagerBean();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -24,17 +24,19 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
|
|||||||
|
|
||||||
import net.Broken.Tools.EmbedMessageUtils;
|
import net.Broken.Tools.EmbedMessageUtils;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.MessageBuilder;
|
|
||||||
import net.dv8tion.jda.api.entities.Emoji;
|
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.entities.User;
|
import net.dv8tion.jda.api.entities.User;
|
||||||
import net.dv8tion.jda.api.entities.VoiceChannel;
|
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
|
||||||
import net.dv8tion.jda.api.events.interaction.GenericInteractionCreateEvent;
|
import net.dv8tion.jda.api.entities.channel.unions.AudioChannelUnion;
|
||||||
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
import net.dv8tion.jda.api.entities.emoji.Emoji;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||||
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||||
import net.dv8tion.jda.api.interactions.components.Button;
|
import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
||||||
|
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
|
||||||
|
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
|
||||||
|
|
||||||
public class GuildAudioBotService {
|
public class GuildAudioBotService {
|
||||||
|
|
||||||
@ -47,7 +49,7 @@ public class GuildAudioBotService {
|
|||||||
/**
|
/**
|
||||||
* Extrem limit for playlist
|
* Extrem limit for playlist
|
||||||
*/
|
*/
|
||||||
private final int listExtremLimit = 300;
|
private static final int LIST_EXTREM_LIMIT = 300;
|
||||||
|
|
||||||
private final Guild guild;
|
private final Guild guild;
|
||||||
private final Logger logger = LogManager.getLogger();
|
private final Logger logger = LogManager.getLogger();
|
||||||
@ -66,9 +68,7 @@ public class GuildAudioBotService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static GuildAudioBotService getInstance(Guild guild) {
|
public static GuildAudioBotService getInstance(Guild guild) {
|
||||||
if (!INSTANCES.containsKey(guild)) {
|
INSTANCES.computeIfAbsent(guild, k -> new GuildAudioBotService(guild));
|
||||||
INSTANCES.put(guild, new GuildAudioBotService(guild));
|
|
||||||
}
|
|
||||||
return INSTANCES.get(guild);
|
return INSTANCES.get(guild);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,13 +80,13 @@ public class GuildAudioBotService {
|
|||||||
* @param playlistLimit Limit of playlist
|
* @param playlistLimit Limit of playlist
|
||||||
* @param onHead True for adding audio track on top of playlist
|
* @param onHead True for adding audio track on top of playlist
|
||||||
*/
|
*/
|
||||||
public void loadAndPlay(SlashCommandEvent event, VoiceChannel voiceChannel, final String trackUrl, int playlistLimit, boolean onHead) {
|
public void loadAndPlay(SlashCommandInteractionEvent event, AudioChannel voiceChannel, final String trackUrl, int playlistLimit, boolean onHead) {
|
||||||
audioPlayerManager.loadItemOrdered(guildAudioManager, trackUrl, new AudioLoadResultHandler() {
|
audioPlayerManager.loadItemOrdered(guildAudioManager, trackUrl, new AudioLoadResultHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void trackLoaded(AudioTrack track) {
|
public void trackLoaded(AudioTrack track) {
|
||||||
logger.info("[" + guild + "] Single Track detected!");
|
logger.info("[{}] Single Track detected!", guild.getName());
|
||||||
UserAudioTrack uat = new UserAudioTrack(event.getUser(), track);
|
UserAudioTrack uat = new UserAudioTrack(event.getUser(), track);
|
||||||
Message message = new MessageBuilder()
|
MessageCreateData message = new MessageCreateBuilder()
|
||||||
.setEmbeds(EmbedMessageUtils.getMusicAdded(track.getInfo(), event.getMember(), -1))
|
.setEmbeds(EmbedMessageUtils.getMusicAdded(track.getInfo(), event.getMember(), -1))
|
||||||
.build();
|
.build();
|
||||||
clearLastButton();
|
clearLastButton();
|
||||||
@ -96,10 +96,10 @@ public class GuildAudioBotService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void playlistLoaded(AudioPlaylist playlist) {
|
public void playlistLoaded(AudioPlaylist playlist) {
|
||||||
logger.info("[" + guild + "] Playlist detected! Limit: " + playlistLimit);
|
logger.info("[{}] Playlist detected! Limit: {}", guild, playlistLimit);
|
||||||
AudioTrack firstTrack = playlist.getSelectedTrack();
|
AudioTrack firstTrack = playlist.getSelectedTrack();
|
||||||
int size = Math.min(playlist.getTracks().size(), playlistLimit);
|
int size = Math.min(playlist.getTracks().size(), playlistLimit);
|
||||||
Message message = new MessageBuilder()
|
MessageCreateData message = new MessageCreateBuilder()
|
||||||
.setEmbeds(EmbedMessageUtils.getMusicAdded(firstTrack.getInfo(), event.getMember(), size))
|
.setEmbeds(EmbedMessageUtils.getMusicAdded(firstTrack.getInfo(), event.getMember(), size))
|
||||||
.build();
|
.build();
|
||||||
clearLastButton();
|
clearLastButton();
|
||||||
@ -109,16 +109,16 @@ public class GuildAudioBotService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void noMatches() {
|
public void noMatches() {
|
||||||
logger.warn("[" + guild + "] Cant find media!");
|
logger.warn("[{}] Cant find media!", guild);
|
||||||
Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicError("Video not found !")).build();
|
MessageCreateData message = new MessageCreateBuilder().setEmbeds(EmbedMessageUtils.getMusicError("Video not found !")).build();
|
||||||
event.getHook().setEphemeral(true).sendMessage(message).queue();
|
event.getHook().setEphemeral(true).sendMessage(message).queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadFailed(FriendlyException exception) {
|
public void loadFailed(FriendlyException exception) {
|
||||||
logger.error("[" + guild + "] Can't load media!");
|
logger.error("[{}] Can't load media!", guild);
|
||||||
logger.error(exception.getMessage());
|
logger.error(exception.getMessage());
|
||||||
Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicError("Playback error !")).build();
|
MessageCreateData message = new MessageCreateBuilder().setEmbeds(EmbedMessageUtils.getMusicError("Playback error !")).build();
|
||||||
event.getHook().setEphemeral(true).sendMessage(message).queue();
|
event.getHook().setEphemeral(true).sendMessage(message).queue();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -126,12 +126,12 @@ public class GuildAudioBotService {
|
|||||||
|
|
||||||
public boolean loadAndPlaySync(String trackUrl, String userId) throws ExecutionException, InterruptedException {
|
public boolean loadAndPlaySync(String trackUrl, String userId) throws ExecutionException, InterruptedException {
|
||||||
Member member = guild.getMemberById(userId);
|
Member member = guild.getMemberById(userId);
|
||||||
VoiceChannel playedChanel = guild.getAudioManager().getConnectedChannel();
|
AudioChannelUnion playedChanel = guild.getAudioManager().getConnectedChannel();
|
||||||
final String uuid = UUID.randomUUID().toString();
|
final String uuid = UUID.randomUUID().toString();
|
||||||
Future<Void> future = audioPlayerManager.loadItemOrdered(guildAudioManager, trackUrl, new AudioLoadResultHandler() {
|
Future<Void> future = audioPlayerManager.loadItemOrdered(guildAudioManager, trackUrl, new AudioLoadResultHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void trackLoaded(AudioTrack track) {
|
public void trackLoaded(AudioTrack track) {
|
||||||
logger.info("[" + guild + "] Auto add " + track.getInfo().title + " to playlist.");
|
logger.info("[{}] Auto add {} to playlist.", guild, track.getInfo().title);
|
||||||
UserAudioTrack userAudioTrack = new UserAudioTrack(member.getUser(), track);
|
UserAudioTrack userAudioTrack = new UserAudioTrack(member.getUser(), track);
|
||||||
play(guild, playedChanel, guildAudioManager, userAudioTrack, true);
|
play(guild, playedChanel, guildAudioManager, userAudioTrack, true);
|
||||||
addStatus.put(uuid, true);
|
addStatus.put(uuid, true);
|
||||||
@ -140,7 +140,7 @@ public class GuildAudioBotService {
|
|||||||
@Override
|
@Override
|
||||||
public void playlistLoaded(AudioPlaylist playlist) {
|
public void playlistLoaded(AudioPlaylist playlist) {
|
||||||
AudioTrack track = playlist.getTracks().get(0);
|
AudioTrack track = playlist.getTracks().get(0);
|
||||||
logger.info("[" + guild + "] Auto add " + track.getInfo().title + " to playlist.");
|
logger.info("[{}] Auto add {} to playlist.", guild, track.getInfo().title);
|
||||||
UserAudioTrack userAudioTrack = new UserAudioTrack(member.getUser(), track);
|
UserAudioTrack userAudioTrack = new UserAudioTrack(member.getUser(), track);
|
||||||
play(guild, playedChanel, guildAudioManager, userAudioTrack, true);
|
play(guild, playedChanel, guildAudioManager, userAudioTrack, true);
|
||||||
addStatus.put(uuid, true);
|
addStatus.put(uuid, true);
|
||||||
@ -148,13 +148,13 @@ public class GuildAudioBotService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void noMatches() {
|
public void noMatches() {
|
||||||
logger.warn("[" + guild + "] Track not found: " + trackUrl);
|
logger.warn("[{}] Track not found: {}", guild, trackUrl);
|
||||||
addStatus.put(uuid, false);
|
addStatus.put(uuid, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadFailed(FriendlyException exception) {
|
public void loadFailed(FriendlyException exception) {
|
||||||
logger.error("[" + guild + "] Cant load media!");
|
logger.error("[{}] Cant load media!", guild);
|
||||||
logger.error(exception.getMessage());
|
logger.error(exception.getMessage());
|
||||||
addStatus.put(uuid, false);
|
addStatus.put(uuid, false);
|
||||||
}
|
}
|
||||||
@ -174,7 +174,7 @@ public class GuildAudioBotService {
|
|||||||
*/
|
*/
|
||||||
public void playListLoader(AudioPlaylist playlist, int playlistLimit, User user, boolean onHead) {
|
public void playListLoader(AudioPlaylist playlist, int playlistLimit, User user, boolean onHead) {
|
||||||
|
|
||||||
VoiceChannel playedChanel = guild.getAudioManager().getConnectedChannel();
|
AudioChannelUnion playedChanel = guild.getAudioManager().getConnectedChannel();
|
||||||
List<AudioTrack> tracks = playlist.getTracks();
|
List<AudioTrack> tracks = playlist.getTracks();
|
||||||
if (onHead)
|
if (onHead)
|
||||||
Collections.reverse(tracks);
|
Collections.reverse(tracks);
|
||||||
@ -183,7 +183,7 @@ public class GuildAudioBotService {
|
|||||||
for (AudioTrack track : playlist.getTracks()) {
|
for (AudioTrack track : playlist.getTracks()) {
|
||||||
UserAudioTrack uat = new UserAudioTrack(user, track);
|
UserAudioTrack uat = new UserAudioTrack(user, track);
|
||||||
play(guild, playedChanel, guildAudioManager, uat, onHead);
|
play(guild, playedChanel, guildAudioManager, uat, onHead);
|
||||||
if ((playlistLimit != -1 && i >= playlistLimit) || i > listExtremLimit)
|
if ((playlistLimit != -1 && i >= playlistLimit) || i > LIST_EXTREM_LIMIT)
|
||||||
break;
|
break;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@ -199,7 +199,7 @@ public class GuildAudioBotService {
|
|||||||
* @param track Track to add to playlist
|
* @param track Track to add to playlist
|
||||||
* @param onHead True for adding audio track on top of playlist
|
* @param onHead True for adding audio track on top of playlist
|
||||||
*/
|
*/
|
||||||
public void play(Guild guild, VoiceChannel channel, GuildAudioManager musicManager, UserAudioTrack track, boolean onHead) {
|
public void play(Guild guild, AudioChannel channel, GuildAudioManager musicManager, UserAudioTrack track, boolean onHead) {
|
||||||
if (!guild.getAudioManager().isConnected())
|
if (!guild.getAudioManager().isConnected())
|
||||||
guild.getAudioManager().openAudioConnection(channel);
|
guild.getAudioManager().openAudioConnection(channel);
|
||||||
if (!onHead)
|
if (!onHead)
|
||||||
@ -208,39 +208,39 @@ public class GuildAudioBotService {
|
|||||||
musicManager.scheduler.addNext(track);
|
musicManager.scheduler.addNext(track);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(SlashCommandEvent event, String url, int playListLimit, boolean onHead) {
|
public void add(SlashCommandInteractionEvent event, String url, int playListLimit, boolean onHead) {
|
||||||
if (guild.getAudioManager().isConnected()) {
|
if (guild.getAudioManager().isConnected()) {
|
||||||
loadAndPlay(event, guild.getAudioManager().getConnectedChannel(), url, playListLimit, onHead);
|
loadAndPlay(event, guild.getAudioManager().getConnectedChannel(), url, playListLimit, onHead);
|
||||||
} else {
|
} else {
|
||||||
Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicError("Not connected to vocal chanel !")).build();
|
MessageCreateData message = new MessageCreateBuilder().setEmbeds(EmbedMessageUtils.getMusicError("Not connected to vocal chanel !")).build();
|
||||||
event.getHook().setEphemeral(true).sendMessage(message).queue();
|
event.getHook().setEphemeral(true).sendMessage(message).queue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connect(VoiceChannel voiceChannel) {
|
public void connect(AudioChannel voiceChannel) {
|
||||||
guild.getAudioManager().openAudioConnection(voiceChannel);
|
guild.getAudioManager().openAudioConnection(voiceChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pause(GenericInteractionCreateEvent event) {
|
public void pause(InteractionHook hook) {
|
||||||
pause();
|
pause();
|
||||||
Message message = new MessageBuilder().setEmbeds(
|
MessageCreateData message = new MessageCreateBuilder().setEmbeds(
|
||||||
EmbedMessageUtils.buildStandar(
|
EmbedMessageUtils.buildStandar(
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setTitle(":pause_button: Playback paused")
|
.setTitle(":pause_button: Playback paused")
|
||||||
.setColor(Color.green)
|
.setColor(Color.green)
|
||||||
)).build();
|
)).build();
|
||||||
clearLastButton();
|
clearLastButton();
|
||||||
lastMessageWithButton = event.getHook().sendMessage(message).addActionRow(getActionButton()).complete();
|
lastMessageWithButton = hook.sendMessage(message).addActionRow(getActionButton()).complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pause() {
|
public void pause() {
|
||||||
guildAudioManager.scheduler.pause();
|
guildAudioManager.scheduler.pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resume(GenericInteractionCreateEvent event) {
|
public void resume(InteractionHook hook) {
|
||||||
Message message;
|
MessageCreateData message;
|
||||||
if (guildAudioManager.player.getPlayingTrack() == null) {
|
if (guildAudioManager.player.getPlayingTrack() == null) {
|
||||||
message = new MessageBuilder().setEmbeds(
|
message = new MessageCreateBuilder().setEmbeds(
|
||||||
EmbedMessageUtils.buildStandar(
|
EmbedMessageUtils.buildStandar(
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setTitle(":warning: Nothing to play, playlist is empty !")
|
.setTitle(":warning: Nothing to play, playlist is empty !")
|
||||||
@ -248,7 +248,7 @@ public class GuildAudioBotService {
|
|||||||
)).build();
|
)).build();
|
||||||
} else {
|
} else {
|
||||||
resume();
|
resume();
|
||||||
message = new MessageBuilder().setEmbeds(
|
message = new MessageCreateBuilder().setEmbeds(
|
||||||
EmbedMessageUtils.buildStandar(
|
EmbedMessageUtils.buildStandar(
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setTitle(":arrow_forward: Playback resumed")
|
.setTitle(":arrow_forward: Playback resumed")
|
||||||
@ -256,39 +256,39 @@ public class GuildAudioBotService {
|
|||||||
)).build();
|
)).build();
|
||||||
}
|
}
|
||||||
clearLastButton();
|
clearLastButton();
|
||||||
lastMessageWithButton = event.getHook().sendMessage(message).addActionRow(getActionButton()).complete();
|
lastMessageWithButton = hook.sendMessage(message).addActionRow(getActionButton()).complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resume() {
|
public void resume() {
|
||||||
guildAudioManager.scheduler.resume();
|
guildAudioManager.scheduler.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void skipTrack(GenericInteractionCreateEvent event) {
|
public void skipTrack(InteractionHook hook) {
|
||||||
skipTrack();
|
skipTrack();
|
||||||
Message message = new MessageBuilder().setEmbeds(
|
MessageCreateData message = new MessageCreateBuilder().setEmbeds(
|
||||||
EmbedMessageUtils.buildStandar(
|
EmbedMessageUtils.buildStandar(
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setTitle(":track_next: Next Track")
|
.setTitle(":track_next: Next Track")
|
||||||
.setColor(Color.green)
|
.setColor(Color.green)
|
||||||
)).build();
|
)).build();
|
||||||
clearLastButton();
|
clearLastButton();
|
||||||
lastMessageWithButton = event.getHook().sendMessage(message).addActionRow(getActionButton()).complete();
|
lastMessageWithButton = hook.sendMessage(message).addActionRow(getActionButton()).complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void skipTrack() {
|
public void skipTrack() {
|
||||||
guildAudioManager.scheduler.nextTrack();
|
guildAudioManager.scheduler.nextTrack();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop(GenericInteractionCreateEvent event) {
|
public void stop(InteractionHook hook) {
|
||||||
stop();
|
stop();
|
||||||
Message message = new MessageBuilder().setEmbeds(
|
MessageCreateData message = new MessageCreateBuilder().setEmbeds(
|
||||||
EmbedMessageUtils.buildStandar(
|
EmbedMessageUtils.buildStandar(
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setTitle(":stop_button: Playback stopped")
|
.setTitle(":stop_button: Playback stopped")
|
||||||
.setColor(Color.green)
|
.setColor(Color.green)
|
||||||
)).build();
|
)).build();
|
||||||
clearLastButton();
|
clearLastButton();
|
||||||
lastMessageWithButton = event.getHook().sendMessage(message).addActionRow(getActionButton()).complete();
|
lastMessageWithButton = hook.sendMessage(message).addActionRow(getActionButton()).complete();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,16 +298,16 @@ public class GuildAudioBotService {
|
|||||||
clearLastButton();
|
clearLastButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disconnect(GenericInteractionCreateEvent event) {
|
public void disconnect(InteractionHook hook) {
|
||||||
disconnect();
|
disconnect();
|
||||||
Message message = new MessageBuilder().setEmbeds(
|
MessageCreateData message = new MessageCreateBuilder().setEmbeds(
|
||||||
EmbedMessageUtils.buildStandar(
|
EmbedMessageUtils.buildStandar(
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setTitle(":eject: Disconnected")
|
.setTitle(":eject: Disconnected")
|
||||||
.setColor(Color.green)
|
.setColor(Color.green)
|
||||||
)).build();
|
)).build();
|
||||||
clearLastButton();
|
clearLastButton();
|
||||||
event.getHook().sendMessage(message).queue();
|
hook.sendMessage(message).queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
@ -316,24 +316,24 @@ public class GuildAudioBotService {
|
|||||||
guild.getAudioManager().closeAudioConnection();
|
guild.getAudioManager().closeAudioConnection();
|
||||||
clearLastButton();
|
clearLastButton();
|
||||||
}
|
}
|
||||||
public void info(GenericInteractionCreateEvent event) {
|
public void info(InteractionHook hook) {
|
||||||
AudioTrackInfo info = guildAudioManager.scheduler.getInfo();
|
AudioTrackInfo info = guildAudioManager.scheduler.getInfo();
|
||||||
UserAudioTrack userAudioTrack = guildAudioManager.scheduler.getCurrentPlayingTrack();
|
UserAudioTrack userAudioTrack = guildAudioManager.scheduler.getCurrentPlayingTrack();
|
||||||
Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicInfo(info, userAudioTrack)).build();
|
MessageCreateData message = new MessageCreateBuilder().setEmbeds(EmbedMessageUtils.getMusicInfo(info, userAudioTrack)).build();
|
||||||
clearLastButton();
|
clearLastButton();
|
||||||
lastMessageWithButton = event.getHook().sendMessage(message).addActionRow(getActionButton()).complete();
|
lastMessageWithButton = hook.sendMessage(message).addActionRow(getActionButton()).complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flush(GenericInteractionCreateEvent event) {
|
public void flush(InteractionHook hook) {
|
||||||
guildAudioManager.scheduler.flush();
|
guildAudioManager.scheduler.flush();
|
||||||
Message message = new MessageBuilder().setEmbeds(
|
MessageCreateData message = new MessageCreateBuilder().setEmbeds(
|
||||||
EmbedMessageUtils.buildStandar(
|
EmbedMessageUtils.buildStandar(
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setTitle(":wastebasket: Playlist flushed")
|
.setTitle(":wastebasket: Playlist flushed")
|
||||||
.setColor(Color.green)
|
.setColor(Color.green)
|
||||||
)).build();
|
)).build();
|
||||||
clearLastButton();
|
clearLastButton();
|
||||||
lastMessageWithButton = event.getHook().sendMessage(message).addActionRow(getActionButton()).complete();
|
lastMessageWithButton = hook.sendMessage(message).addActionRow(getActionButton()).complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -341,18 +341,18 @@ public class GuildAudioBotService {
|
|||||||
*
|
*
|
||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
public void list(GenericInteractionCreateEvent event) {
|
public void list(InteractionHook hook) {
|
||||||
List<UserAudioTrack> list = guildAudioManager.scheduler.getList();
|
List<UserAudioTrack> list = guildAudioManager.scheduler.getList();
|
||||||
|
|
||||||
if (list.size() == 0) {
|
if (list.isEmpty()) {
|
||||||
Message message = new MessageBuilder().setEmbeds(
|
MessageCreateData message = new MessageCreateBuilder().setEmbeds(
|
||||||
EmbedMessageUtils.buildStandar(
|
EmbedMessageUtils.buildStandar(
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setTitle(":scroll: Playlist")
|
.setTitle(":scroll: Playlist")
|
||||||
.setColor(Color.green)
|
.setColor(Color.green)
|
||||||
.setDescription("Oh no ! The playlist is empty !")
|
.setDescription("Oh no ! The playlist is empty !")
|
||||||
)).build();
|
)).build();
|
||||||
event.getHook().sendMessage(message).queue();
|
hook.sendMessage(message).queue();
|
||||||
} else {
|
} else {
|
||||||
StringBuilder resp = new StringBuilder();
|
StringBuilder resp = new StringBuilder();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -370,14 +370,14 @@ public class GuildAudioBotService {
|
|||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
Message message = new MessageBuilder().setEmbeds(
|
MessageCreateData message = new MessageCreateBuilder().setEmbeds(
|
||||||
EmbedMessageUtils.buildStandar(
|
EmbedMessageUtils.buildStandar(
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setTitle(":scroll: Playlist")
|
.setTitle(":scroll: Playlist")
|
||||||
.setColor(Color.green)
|
.setColor(Color.green)
|
||||||
.setDescription(resp.toString())
|
.setDescription(resp.toString())
|
||||||
)).build();
|
)).build();
|
||||||
event.getHook().sendMessage(message).queue();
|
hook.sendMessage(message).queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,13 @@
|
|||||||
package net.Broken;
|
package net.Broken;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
|
||||||
import net.Broken.Audio.GuildAudioBotService;
|
import net.Broken.Audio.GuildAudioBotService;
|
||||||
import net.Broken.DB.Entity.GuildPreferenceEntity;
|
import net.Broken.DB.Entity.GuildPreferenceEntity;
|
||||||
import net.Broken.DB.Repository.GuildPreferenceRepository;
|
import net.Broken.DB.Repository.GuildPreferenceRepository;
|
||||||
@ -7,12 +15,13 @@ import net.Broken.Tools.AutoVoiceChannel;
|
|||||||
import net.Broken.Tools.EmbedMessageUtils;
|
import net.Broken.Tools.EmbedMessageUtils;
|
||||||
import net.Broken.Tools.UserManager.Stats.UserStatsUtils;
|
import net.Broken.Tools.UserManager.Stats.UserStatsUtils;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.entities.*;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
|
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||||
|
import net.dv8tion.jda.api.entities.Role;
|
||||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||||
import net.dv8tion.jda.api.events.guild.GuildJoinEvent;
|
import net.dv8tion.jda.api.events.guild.GuildJoinEvent;
|
||||||
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
|
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
|
||||||
import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleRemoveEvent;
|
import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleRemoveEvent;
|
||||||
import net.dv8tion.jda.api.events.guild.voice.GenericGuildVoiceEvent;
|
|
||||||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent;
|
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
|
||||||
@ -22,15 +31,6 @@ import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
|||||||
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
|
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
|
||||||
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
|
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bot Listener
|
* Bot Listener
|
||||||
*/
|
*/
|
||||||
@ -57,9 +57,9 @@ public class BotListener extends ListenerAdapter {
|
|||||||
if (guildPref.isDefaultRole()) {
|
if (guildPref.isDefaultRole()) {
|
||||||
logger.info("[{}] : {} join the guild, adding default role !", event.getGuild().getName(),
|
logger.info("[{}] : {} join the guild, adding default role !", event.getGuild().getName(),
|
||||||
event.getUser().getName());
|
event.getUser().getName());
|
||||||
Role default_role = event.getGuild().getRoleById(guildPref.getDefaultRoleId());
|
Role defaultRole = event.getGuild().getRoleById(guildPref.getDefaultRoleId());
|
||||||
if (default_role != null) {
|
if (defaultRole != null) {
|
||||||
event.getGuild().addRoleToMember(event.getMember(), default_role).queue();
|
event.getGuild().addRoleToMember(event.getMember(), defaultRole).queue();
|
||||||
} else {
|
} else {
|
||||||
logger.fatal("[{}] : Default role is null !", event.getGuild().getName());
|
logger.fatal("[{}] : Default role is null !", event.getGuild().getName());
|
||||||
}
|
}
|
||||||
@ -144,11 +144,11 @@ public class BotListener extends ListenerAdapter {
|
|||||||
event.deferReply().queue();
|
event.deferReply().queue();
|
||||||
GuildAudioBotService guildAudioBotService = GuildAudioBotService.getInstance(event.getGuild());
|
GuildAudioBotService guildAudioBotService = GuildAudioBotService.getInstance(event.getGuild());
|
||||||
switch (event.getComponentId()) {
|
switch (event.getComponentId()) {
|
||||||
case "pause" -> guildAudioBotService.pause(event);
|
case "pause" -> guildAudioBotService.pause(event.getHook());
|
||||||
case "play" -> guildAudioBotService.resume(event);
|
case "play" -> guildAudioBotService.resume(event.getHook());
|
||||||
case "next" -> guildAudioBotService.skipTrack(event);
|
case "next" -> guildAudioBotService.skipTrack(event.getHook());
|
||||||
case "stop" -> guildAudioBotService.stop(event);
|
case "stop" -> guildAudioBotService.stop(event.getHook());
|
||||||
case "disconnect" -> guildAudioBotService.disconnect(event);
|
case "disconnect" -> guildAudioBotService.disconnect(event.getHook());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,132 +0,0 @@
|
|||||||
package net.Broken.Commands;
|
|
||||||
|
|
||||||
import net.Broken.Commande;
|
|
||||||
import net.Broken.Tools.EmbedMessageUtils;
|
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
|
||||||
import net.dv8tion.jda.api.entities.TextChannel;
|
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public class ChannelsReview implements Commande {
|
|
||||||
final Logger logger = LogManager.getLogger();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void action(String[] args, MessageReceivedEvent event) {
|
|
||||||
DateFormat format = new SimpleDateFormat("dd.MM.yyyy");
|
|
||||||
event.getTextChannel().sendMessage("Number of channels found in total : " + event.getGuild().getTextChannels().size()).queue();
|
|
||||||
if (args.length >= 1) {
|
|
||||||
try {
|
|
||||||
SendBackBefore(format.parse(args[0]), event, format);
|
|
||||||
} catch (ParseException e) {
|
|
||||||
logger.warn("Can't parse date : " + e.getMessage());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
SendBack(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void SendBackBefore(Date beforeDate, MessageReceivedEvent event, DateFormat format) {
|
|
||||||
HashMap<String, String> result = new HashMap<>();
|
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy").withLocale(Locale.ENGLISH);
|
|
||||||
int charCtl = 0;
|
|
||||||
for (TextChannel textChannel : event.getGuild().getTextChannels()) {
|
|
||||||
if (textChannel.hasLatestMessage()) {
|
|
||||||
String lastMessageId = textChannel.getLatestMessageId();
|
|
||||||
try {
|
|
||||||
Message lastMessage = textChannel.retrieveMessageById(lastMessageId).complete();
|
|
||||||
if (beforeDate.compareTo(format.parse(lastMessage.getTimeCreated().format(formatter))) > 0) {
|
|
||||||
logger.debug("Last message in channel " + textChannel + " is " + lastMessageId);
|
|
||||||
String date = lastMessage.getTimeCreated().format(formatter);
|
|
||||||
charCtl += textChannel.getName().length() + date.length();
|
|
||||||
result.put(textChannel.getName(), date);
|
|
||||||
}
|
|
||||||
} catch (RuntimeException | ParseException e) {
|
|
||||||
logger.warn("Can't find message with id: " + lastMessageId);
|
|
||||||
result.put(textChannel.getName(), "ERROR");
|
|
||||||
charCtl += textChannel.getName().length() + 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
result.put(textChannel.getName(), "No message or access denied.");
|
|
||||||
charCtl += textChannel.getName().length() + 30;
|
|
||||||
}
|
|
||||||
if (charCtl > 3000) {
|
|
||||||
event.getTextChannel().sendMessage(EmbedMessageUtils.getLastMessageFromTextChannel(result)).complete();
|
|
||||||
result = new HashMap<>();
|
|
||||||
charCtl = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (charCtl != 0)
|
|
||||||
event.getTextChannel().sendMessage(EmbedMessageUtils.getLastMessageFromTextChannel(result)).queue();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SendBack(MessageReceivedEvent event) {
|
|
||||||
HashMap<String, String> result = new HashMap<>();
|
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd MMMM yyyy").withLocale(Locale.ENGLISH);
|
|
||||||
int charCtl = 0;
|
|
||||||
for (TextChannel textChannel : event.getGuild().getTextChannels()) {
|
|
||||||
if (textChannel.hasLatestMessage()) {
|
|
||||||
String lastMessageId = textChannel.getLatestMessageId();
|
|
||||||
logger.debug("Last message in channel " + textChannel + " is " + lastMessageId);
|
|
||||||
|
|
||||||
try {
|
|
||||||
Message lastMessage = textChannel.retrieveMessageById(lastMessageId).complete();
|
|
||||||
String date = lastMessage.getTimeCreated().format(formatter);
|
|
||||||
charCtl += textChannel.getName().length() + date.length();
|
|
||||||
result.put(textChannel.getName(), date);
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
logger.warn("Can't find message with id: " + lastMessageId);
|
|
||||||
result.put(textChannel.getName(), "ERROR");
|
|
||||||
charCtl += textChannel.getName().length() + 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
result.put(textChannel.getName(), "No message or access denied.");
|
|
||||||
charCtl += textChannel.getName().length() + 30;
|
|
||||||
}
|
|
||||||
if (charCtl > 3000) {
|
|
||||||
event.getTextChannel().sendMessage(EmbedMessageUtils.getLastMessageFromTextChannel(result)).queue();
|
|
||||||
event.getTextChannel().sendTyping().queue();
|
|
||||||
result = new HashMap<>();
|
|
||||||
charCtl = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (charCtl != 0)
|
|
||||||
event.getTextChannel().sendMessage(EmbedMessageUtils.getLastMessageFromTextChannel(result)).queue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPrivateUsable() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAdminCmd() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines if the command is usable only by bot level admin user
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean isBotAdminCmd() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isNSFW() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
package net.Broken.Commands;
|
|
||||||
|
|
||||||
import net.Broken.Commande;
|
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
|
||||||
|
|
||||||
public class Ordre66 implements Commande {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void action(String[] args, MessageReceivedEvent event) {
|
|
||||||
Message rest = event.getTextChannel().sendMessage("Très bien maître " + event.getAuthor().getAsMention() + ". J'arrive ! ").complete();
|
|
||||||
Message reste = event.getTextChannel().sendMessage("https://media2.giphy.com/media/UfzTayIyH7g5hk2BA2/giphy.gif\n").complete();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPrivateUsable() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAdminCmd() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines if the command is usable only by bot level admin user
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean isBotAdminCmd() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isNSFW() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
package net.Broken.Commands;
|
|
||||||
|
|
||||||
import net.Broken.Commande;
|
|
||||||
import net.Broken.Tools.EmbedMessageUtils;
|
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
|
||||||
import net.dv8tion.jda.api.requests.RestAction;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
|
|
||||||
public class ReportUsers implements Commande {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void action(String[] args, MessageReceivedEvent event) {
|
|
||||||
|
|
||||||
event.getGuild().loadMembers().onSuccess(members -> {
|
|
||||||
if (event.getMessage().getMentionedRoles().size() == 1 && args.length == 1) {
|
|
||||||
RestAction<Void> restAction = null;
|
|
||||||
for (Member member : members) {
|
|
||||||
if (member.getRoles().size() == 1) { //check if the member has a role
|
|
||||||
if (member.getRoles().contains(event.getMessage().getMentionedRoles().get(0))) { //check if the mentioned role is the same as the member's role
|
|
||||||
restAction = Objects.requireNonNullElseGet(restAction, () -> event.getTextChannel().sendMessage("List des membres : "))
|
|
||||||
.and(event.getTextChannel().sendMessage(member.getEffectiveName()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (restAction != null)
|
|
||||||
restAction.queue();
|
|
||||||
} else if (args.length == 0) {
|
|
||||||
|
|
||||||
for (Member member : members) {
|
|
||||||
if (member.getRoles().size() == 0) {
|
|
||||||
event.getTextChannel().sendMessage(member.getEffectiveName()).complete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
event.getTextChannel().sendMessage(EmbedMessageUtils.getReportUsersError()).complete();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPrivateUsable() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAdminCmd() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines if the command is usable only by bot level admin user
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean isBotAdminCmd() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isNSFW() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -11,8 +11,6 @@ import org.apache.logging.log4j.Logger;
|
|||||||
import net.Broken.SlashCommand;
|
import net.Broken.SlashCommand;
|
||||||
import net.Broken.Audio.GuildAudioBotService;
|
import net.Broken.Audio.GuildAudioBotService;
|
||||||
import net.Broken.Tools.EmbedMessageUtils;
|
import net.Broken.Tools.EmbedMessageUtils;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
|
||||||
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
|
|
||||||
import net.dv8tion.jda.api.entities.channel.unions.AudioChannelUnion;
|
import net.dv8tion.jda.api.entities.channel.unions.AudioChannelUnion;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
||||||
@ -65,26 +63,26 @@ public class Music implements SlashCommand {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "pause":
|
case "pause":
|
||||||
audio.pause(event);
|
audio.pause(event.getHook());
|
||||||
break;
|
break;
|
||||||
case "resume":
|
case "resume":
|
||||||
audio.resume(event);
|
audio.resume(event.getHook());
|
||||||
break;
|
break;
|
||||||
case "next":
|
case "next":
|
||||||
audio.skipTrack(event);
|
audio.skipTrack(event.getHook());
|
||||||
break;
|
break;
|
||||||
case "stop":
|
case "stop":
|
||||||
case "disconnect":
|
case "disconnect":
|
||||||
audio.stop(event);
|
audio.stop(event.getHook());
|
||||||
break;
|
break;
|
||||||
case "info":
|
case "info":
|
||||||
audio.info(event);
|
audio.info(event.getHook());
|
||||||
break;
|
break;
|
||||||
case "flush":
|
case "flush":
|
||||||
audio.flush(event);
|
audio.flush(event.getHook());
|
||||||
break;
|
break;
|
||||||
case "list":
|
case "list":
|
||||||
audio.list(event);
|
audio.list(event.getHook());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,21 @@
|
|||||||
package net.Broken.Tools;
|
package net.Broken.Tools;
|
||||||
|
|
||||||
|
|
||||||
import net.Broken.DB.Entity.GuildPreferenceEntity;
|
import static net.Broken.MainBot.jda;
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
|
||||||
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
|
|
||||||
import net.dv8tion.jda.api.requests.RestAction;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static net.Broken.MainBot.jda;
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import net.Broken.DB.Entity.GuildPreferenceEntity;
|
||||||
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
|
||||||
|
import net.dv8tion.jda.api.requests.RestAction;
|
||||||
|
|
||||||
public class AutoVoiceChannel {
|
public class AutoVoiceChannel {
|
||||||
private static final HashMap<String, AutoVoiceChannel> INSTANCE_MAP = new HashMap<>();
|
private static final HashMap<String, AutoVoiceChannel> INSTANCE_MAP = new HashMap<>();
|
||||||
@ -34,14 +35,14 @@ public class AutoVoiceChannel {
|
|||||||
return INSTANCE_MAP.get(guild.getId());
|
return INSTANCE_MAP.get(guild.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void join(VoiceChannel voiceChannel) {
|
public void join(AudioChannel voiceChannel) {
|
||||||
Guild guild = jda.getGuildById(guildID);
|
Guild guild = jda.getGuildById(guildID);
|
||||||
if (guild == null)
|
if (guild == null)
|
||||||
return;
|
return;
|
||||||
GuildPreferenceEntity pref = SettingsUtils.getInstance().getPreference(guild);
|
GuildPreferenceEntity pref = SettingsUtils.getInstance().getPreference(guild);
|
||||||
if (pref.isAutoVoice() && voiceChannel.getId().equals(pref.getAutoVoiceChannelID())) {
|
if (pref.isAutoVoice() && voiceChannel.getId().equals(pref.getAutoVoiceChannelID())) {
|
||||||
logger.info("Creating new voice channel for Guild : {}", guild.getName());
|
logger.info("Creating new voice channel for Guild : {}", guild.getName());
|
||||||
VoiceChannel newChannel = voiceChannel.createCopy().complete();
|
AudioChannel newChannel = (AudioChannel) voiceChannel.createCopy().complete();
|
||||||
int next = getNextNumber();
|
int next = getNextNumber();
|
||||||
String title = pref.getAutoVoiceChannelTitle();
|
String title = pref.getAutoVoiceChannelTitle();
|
||||||
if (title.isEmpty()) {
|
if (title.isEmpty()) {
|
||||||
@ -56,7 +57,7 @@ public class AutoVoiceChannel {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void leave(VoiceChannel voiceChannel) {
|
public void leave(AudioChannel voiceChannel) {
|
||||||
if (voiceChannel.getMembers().isEmpty()) {
|
if (voiceChannel.getMembers().isEmpty()) {
|
||||||
String id = voiceChannel.getId();
|
String id = voiceChannel.getId();
|
||||||
for (Map.Entry<Integer, String> entry : createdChannels.entrySet()) {
|
for (Map.Entry<Integer, String> entry : createdChannels.entrySet()) {
|
||||||
@ -79,7 +80,7 @@ public class AutoVoiceChannel {
|
|||||||
return 999;
|
return 999;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void moveMembers(List<Member> members, VoiceChannel destination) {
|
private void moveMembers(List<Member> members, AudioChannel destination) {
|
||||||
logger.debug("Moving Members to new voice channel...");
|
logger.debug("Moving Members to new voice channel...");
|
||||||
RestAction<Void> restAction = null;
|
RestAction<Void> restAction = null;
|
||||||
for (Member member : members) {
|
for (Member member : members) {
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
package net.Broken.Tools.UserManager;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
public class UserUtils {
|
|
||||||
|
|
||||||
private static final UserUtils INSTANCE = new UserUtils();
|
|
||||||
private final Logger logger = LogManager.getLogger();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Private default constructor
|
|
||||||
*/
|
|
||||||
private UserUtils() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Singleton
|
|
||||||
*
|
|
||||||
* @return Unique UserUtils instance
|
|
||||||
*/
|
|
||||||
public static UserUtils getInstance() {
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user