Compare commits
No commits in common. "92c30173cb018cd06ccd4c246f722d7c099a0b2d" and "79c6f1b5ae782ceb4db7ee5c5f480af5c4e848f4" have entirely different histories.
92c30173cb
...
79c6f1b5ae
@ -8,7 +8,10 @@ import net.Broken.Tools.UserManager.Stats.UserStatsUtils;
|
|||||||
import net.Broken.audio.AudioM;
|
import net.Broken.audio.AudioM;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.MessageBuilder;
|
import net.dv8tion.jda.api.MessageBuilder;
|
||||||
import net.dv8tion.jda.api.entities.*;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.entities.Role;
|
||||||
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
import net.dv8tion.jda.api.events.ReadyEvent;
|
import net.dv8tion.jda.api.events.ReadyEvent;
|
||||||
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;
|
||||||
@ -16,7 +19,6 @@ import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleRemoveEvent;
|
|||||||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceJoinEvent;
|
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.GuildVoiceLeaveEvent;
|
||||||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent;
|
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.ButtonClickEvent;
|
|
||||||
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
@ -67,7 +69,7 @@ public class BotListener extends ListenerAdapter {
|
|||||||
String message = guildPref.getWelcomeMessage().replaceAll("@name", event.getMember().getAsMention());
|
String message = guildPref.getWelcomeMessage().replaceAll("@name", event.getMember().getAsMention());
|
||||||
logger.debug(message);
|
logger.debug(message);
|
||||||
chanel.sendMessage(message).queue();
|
chanel.sendMessage(message).queue();
|
||||||
} else {
|
}else {
|
||||||
logger.fatal("[" + event.getGuild().getName() + "] : Welcome chanel is null !");
|
logger.fatal("[" + event.getGuild().getName() + "] : Welcome chanel is null !");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,8 +121,6 @@ public class BotListener extends ListenerAdapter {
|
|||||||
logger.debug("I'm alone, close audio connection.");
|
logger.debug("I'm alone, close audio connection.");
|
||||||
AudioM.getInstance(event.getGuild()).stop();
|
AudioM.getInstance(event.getGuild()).stop();
|
||||||
}
|
}
|
||||||
} else if (event.getMember().getUser() == MainBot.jda.getSelfUser()) {
|
|
||||||
AudioM.getInstance(event.getGuild()).clearLastButton();
|
|
||||||
}
|
}
|
||||||
AutoVoiceChannel autoVoiceChannel = AutoVoiceChannel.getInstance(event.getGuild());
|
AutoVoiceChannel autoVoiceChannel = AutoVoiceChannel.getInstance(event.getGuild());
|
||||||
autoVoiceChannel.leave(event.getChannelLeft());
|
autoVoiceChannel.leave(event.getChannelLeft());
|
||||||
@ -141,48 +141,12 @@ public class BotListener extends ListenerAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onButtonClick(@NotNull ButtonClickEvent event) {
|
|
||||||
super.onButtonClick(event);
|
|
||||||
event.deferReply().queue();
|
|
||||||
AudioM audioM = AudioM.getInstance(event.getGuild());
|
|
||||||
switch (event.getComponentId()) {
|
|
||||||
case "pause" -> audioM.pause(event);
|
|
||||||
case "play" -> audioM.resume(event);
|
|
||||||
case "next" -> audioM.skipTrack(event);
|
|
||||||
case "stop" -> audioM.stop(event);
|
|
||||||
case "disconnect" -> audioM.disconect(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSlashCommand(@NotNull SlashCommandEvent event) {
|
public void onSlashCommand(@NotNull SlashCommandEvent event) {
|
||||||
HashMap<String, SlashCommand> commands = MainBot.slashCommands;
|
HashMap<String, SlashCommand> commands = MainBot.slashCommands;
|
||||||
super.onSlashCommand(event);
|
super.onSlashCommand(event);
|
||||||
if (commands.containsKey(event.getName())) {
|
if (commands.containsKey(event.getName())) {
|
||||||
SlashCommand commandRunner = commands.get(event.getName());
|
commands.get(event.getName()).action(event);
|
||||||
// It's form private message
|
|
||||||
if (!event.isFromGuild()) {
|
|
||||||
if (commandRunner.isPrivateUsable()) {
|
|
||||||
commandRunner.action(event);
|
|
||||||
} else {
|
|
||||||
MessageEmbed message = EmbedMessageUtils.buildStandar(new EmbedBuilder()
|
|
||||||
.setTitle(":no_entry_sign: This command is not usable in private message")
|
|
||||||
.setColor(Color.red)
|
|
||||||
);
|
|
||||||
event.replyEmbeds(message).setEphemeral(true).queue();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!commandRunner.isNSFW() || event.getTextChannel().isNSFW()) {
|
|
||||||
commandRunner.action(event);
|
|
||||||
} else {
|
|
||||||
MessageEmbed message = EmbedMessageUtils.buildStandar(new EmbedBuilder()
|
|
||||||
.setTitle(":underage: This command is only usable in NSFW channels")
|
|
||||||
.setColor(Color.red)
|
|
||||||
);
|
|
||||||
event.replyEmbeds(message).setEphemeral(true).queue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,5 +186,4 @@ public class BotListener extends ListenerAdapter {
|
|||||||
return guildPref;
|
return guildPref;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
48
src/main/java/net/Broken/Commands/DayTrigger.java
Normal file
48
src/main/java/net/Broken/Commands/DayTrigger.java
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package net.Broken.Commands;
|
||||||
|
|
||||||
|
import net.Broken.Commande;
|
||||||
|
import net.Broken.Tools.DayListener.DayListener;
|
||||||
|
import net.dv8tion.jda.api.entities.ChannelType;
|
||||||
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Admin command to manually trigger daily action(s)
|
||||||
|
*/
|
||||||
|
public class DayTrigger implements Commande {
|
||||||
|
Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void action(String[] args, MessageReceivedEvent event) {
|
||||||
|
if (!event.isFromType(ChannelType.PRIVATE))
|
||||||
|
event.getMessage().delete().queue();
|
||||||
|
DayListener.getInstance().trigger();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isNSFW() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
47
src/main/java/net/Broken/Commands/Over18/Ass.java
Normal file
47
src/main/java/net/Broken/Commands/Over18/Ass.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package net.Broken.Commands.Over18;
|
||||||
|
|
||||||
|
import net.Broken.Tools.Command.NoDev;
|
||||||
|
import net.Broken.Tools.Command.NumberedCommande;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ass command, return random picture from les400culs.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
@NoDev()
|
||||||
|
public class Ass extends NumberedCommande {
|
||||||
|
|
||||||
|
public Ass() {
|
||||||
|
super(LogManager.getLogger(), "http://les400culs.com/", "-2/", "featured-img", "img");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Ass";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPrivateUsable() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAdminCmd() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 true;
|
||||||
|
}
|
||||||
|
}
|
@ -1,26 +1,39 @@
|
|||||||
package net.Broken.SlashCommands.Over18;
|
package net.Broken.Commands.Over18;
|
||||||
|
|
||||||
import net.Broken.Tools.Command.Ignore;
|
|
||||||
import net.Broken.Tools.Command.NoDev;
|
import net.Broken.Tools.Command.NoDev;
|
||||||
import net.Broken.Tools.Command.NumberedSlashCommand;
|
import net.Broken.Tools.Command.NumberedCommande;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
@NoDev
|
/**
|
||||||
@Ignore
|
* Boobs command, return random picture from lesaintdesseins.fr
|
||||||
public class Boobs extends NumberedSlashCommand {
|
*/
|
||||||
Logger logger = LogManager.getLogger();
|
@NoDev()
|
||||||
|
public class Boobs extends NumberedCommande {
|
||||||
|
|
||||||
public Boobs() {
|
public Boobs() {
|
||||||
super(LogManager.getLogger(), "http://lesaintdesseins.fr/", "-2/", "featured-img", "img");
|
super(LogManager.getLogger(), "http://lesaintdesseins.fr/", "-2/", "featured-img", "img");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() {
|
public String toString() {
|
||||||
return "Return random image from les400culs.com";
|
return "Boobs";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPrivateUsable() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAdminCmd() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if the command is usable only by bot level admin user
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isBotAdminCmd() {
|
public boolean isBotAdminCmd() {
|
||||||
return false;
|
return false;
|
||||||
@ -30,14 +43,4 @@ public class Boobs extends NumberedSlashCommand {
|
|||||||
public boolean isNSFW() {
|
public boolean isNSFW() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPrivateUsable() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDisableByDefault() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,21 +1,55 @@
|
|||||||
package net.Broken.SlashCommands.Over18;
|
package net.Broken.Commands.Over18;
|
||||||
|
|
||||||
import net.Broken.Tools.Command.Ignore;
|
|
||||||
import net.Broken.Tools.Command.NoDev;
|
import net.Broken.Tools.Command.NoDev;
|
||||||
import net.Broken.Tools.Command.NumberedSlashCommand;
|
import net.Broken.Tools.Command.NumberedCommande;
|
||||||
import net.Broken.Tools.FindContentOnWebPage;
|
import net.Broken.Tools.FindContentOnWebPage;
|
||||||
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Madame command that return random picture from dites.bonjourmadame.fr
|
||||||
|
*/
|
||||||
@NoDev
|
@NoDev
|
||||||
public class Madame extends NumberedSlashCommand {
|
public class Madame extends NumberedCommande {
|
||||||
|
public String HELP = "Yo really? Just type Madame to see some :cat:";
|
||||||
Logger logger = LogManager.getLogger();
|
Logger logger = LogManager.getLogger();
|
||||||
|
MessageReceivedEvent event;
|
||||||
|
|
||||||
public Madame() {
|
public Madame() {
|
||||||
super(LogManager.getLogger(), "https://www.bonjourmadame.fr/page/", "/");
|
super(LogManager.getLogger(), "https://www.bonjourmadame.fr/page/", "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPrivateUsable() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAdminCmd() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detect if picture link go to Tepeee
|
* Detect if picture link go to Tepeee
|
||||||
*
|
*
|
||||||
@ -73,29 +107,4 @@ public class Madame extends NumberedSlashCommand {
|
|||||||
imgUrl = removeParams(imgUrl);
|
imgUrl = removeParams(imgUrl);
|
||||||
return imgUrl;
|
return imgUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDescription() {
|
|
||||||
return "Return random image from bonjourmadame.fr";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isBotAdminCmd() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isNSFW() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPrivateUsable() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDisableByDefault() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
40
src/main/java/net/Broken/Commands/Rank.java
Normal file
40
src/main/java/net/Broken/Commands/Rank.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package net.Broken.Commands;
|
||||||
|
|
||||||
|
import net.Broken.Commande;
|
||||||
|
import net.Broken.Tools.UserManager.Stats.UserStatsUtils;
|
||||||
|
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||||
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
|
|
||||||
|
public class Rank implements Commande {
|
||||||
|
@Override
|
||||||
|
public void action(String[] args, MessageReceivedEvent event) {
|
||||||
|
UserStatsUtils userStats = UserStatsUtils.getINSTANCE();
|
||||||
|
MessageEmbed msg = userStats.getRankMessage(event.getMember());
|
||||||
|
event.getTextChannel().sendMessage(msg).queue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPrivateUsable() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAdminCmd() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
@ -65,6 +65,4 @@ public class ReportUsers implements Commande {
|
|||||||
public boolean isNSFW() {
|
public boolean isNSFW() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
63
src/main/java/net/Broken/Commands/Settings.java
Normal file
63
src/main/java/net/Broken/Commands/Settings.java
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package net.Broken.Commands;
|
||||||
|
|
||||||
|
import net.Broken.Commande;
|
||||||
|
import net.Broken.DB.Repository.GuildPreferenceRepository;
|
||||||
|
import net.Broken.MainBot;
|
||||||
|
import net.Broken.SpringContext;
|
||||||
|
import net.Broken.Tools.EmbedMessageUtils;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class Settings implements Commande {
|
||||||
|
|
||||||
|
private Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
|
private GuildPreferenceRepository guildPreferenceRepository;
|
||||||
|
|
||||||
|
public Settings() {
|
||||||
|
|
||||||
|
ApplicationContext context = SpringContext.getAppContext();
|
||||||
|
guildPreferenceRepository = (GuildPreferenceRepository) context.getBean("guildPreferenceRepository");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void action(String[] args, MessageReceivedEvent event) {
|
||||||
|
|
||||||
|
EmbedBuilder builder = new EmbedBuilder()
|
||||||
|
.setTitle("Settings")
|
||||||
|
.setDescription("You can do all the configuration on the web page in the \"Bot Settings\" menu.\nhttps://" + MainBot.url).setColor(Color.green);
|
||||||
|
event.getTextChannel().sendMessage(EmbedMessageUtils.buildStandar(builder)).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;
|
||||||
|
}
|
||||||
|
}
|
@ -93,6 +93,7 @@ public class Init {
|
|||||||
jda.addEventListener(new BotListener());
|
jda.addEventListener(new BotListener());
|
||||||
jda.getPresence().setPresence(OnlineStatus.ONLINE, Activity.playing(MainBot.url));
|
jda.getPresence().setPresence(OnlineStatus.ONLINE, Activity.playing(MainBot.url));
|
||||||
|
|
||||||
|
|
||||||
logger.info("-----------------------END INIT-----------------------");
|
logger.info("-----------------------END INIT-----------------------");
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,9 +38,5 @@ public interface SlashCommand {
|
|||||||
*/
|
*/
|
||||||
boolean isNSFW();
|
boolean isNSFW();
|
||||||
|
|
||||||
boolean isPrivateUsable();
|
|
||||||
|
|
||||||
|
|
||||||
boolean isDisableByDefault();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -81,14 +81,4 @@ public class Cat implements SlashCommand {
|
|||||||
public boolean isNSFW() {
|
public boolean isNSFW() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPrivateUsable() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDisableByDefault() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -55,14 +55,4 @@ public class Clear implements SlashCommand {
|
|||||||
public boolean isNSFW() {
|
public boolean isNSFW() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPrivateUsable() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDisableByDefault() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
41
src/main/java/net/Broken/SlashCommands/Invite.java
Normal file
41
src/main/java/net/Broken/SlashCommands/Invite.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package net.Broken.SlashCommands;
|
||||||
|
|
||||||
|
import net.Broken.SlashCommand;
|
||||||
|
import net.dv8tion.jda.api.Permission;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Invite implements SlashCommand {
|
||||||
|
@Override
|
||||||
|
public void action(SlashCommandEvent event) {
|
||||||
|
event.reply(event.getJDA().setRequiredScopes("bot", "applications.commands").getInviteUrl(Permission.ADMINISTRATOR)).setEphemeral(true).queue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return "Get the link to invite this bot to your server";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<OptionData> getOptions() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SubcommandData> getSubcommands() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isBotAdminCmd() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isNSFW() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -130,14 +130,4 @@ public class Music implements SlashCommand {
|
|||||||
public boolean isNSFW() {
|
public boolean isNSFW() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPrivateUsable() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDisableByDefault() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
package net.Broken.SlashCommands.Over18;
|
|
||||||
|
|
||||||
import net.Broken.Tools.Command.Ignore;
|
|
||||||
import net.Broken.Tools.Command.NoDev;
|
|
||||||
import net.Broken.Tools.Command.NumberedSlashCommand;
|
|
||||||
import net.Broken.Tools.FindContentOnWebPage;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
@NoDev
|
|
||||||
@Ignore
|
|
||||||
public class Ass extends NumberedSlashCommand {
|
|
||||||
Logger logger = LogManager.getLogger();
|
|
||||||
|
|
||||||
public Ass() {
|
|
||||||
super(LogManager.getLogger(), "http://les400culs.com/", "-2/", "featured-img", "img");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDescription() {
|
|
||||||
return "Return random image from les400culs.com";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isBotAdminCmd() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isNSFW() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPrivateUsable() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDisableByDefault() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
package net.Broken.SlashCommands;
|
|
||||||
|
|
||||||
import net.Broken.MainBot;
|
|
||||||
import net.Broken.SlashCommand;
|
|
||||||
import net.Broken.Tools.UserManager.Stats.UserStatsUtils;
|
|
||||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
|
||||||
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
|
||||||
import net.dv8tion.jda.api.interactions.components.Button;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Rank implements SlashCommand {
|
|
||||||
@Override
|
|
||||||
public void action(SlashCommandEvent event) {
|
|
||||||
event.deferReply().queue();
|
|
||||||
UserStatsUtils userStats = UserStatsUtils.getINSTANCE();
|
|
||||||
MessageEmbed messageEmbed = userStats.getRankMessage(event.getMember());
|
|
||||||
event.getHook().sendMessageEmbeds(messageEmbed).addActionRow(
|
|
||||||
Button.link("https://" + MainBot.url + "/rank", "More stats")
|
|
||||||
).queue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDescription() {
|
|
||||||
return "Get the top 5 ranking of this server";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<OptionData> getOptions() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<SubcommandData> getSubcommands() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isBotAdminCmd() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isNSFW() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPrivateUsable() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDisableByDefault() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
152
src/main/java/net/Broken/Tools/Command/NumberedCommande.java
Normal file
152
src/main/java/net/Broken/Tools/Command/NumberedCommande.java
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
package net.Broken.Tools.Command;
|
||||||
|
|
||||||
|
import net.Broken.Commande;
|
||||||
|
import net.Broken.Tools.FindContentOnWebPage;
|
||||||
|
import net.Broken.Tools.LimitChecker;
|
||||||
|
import net.Broken.Tools.TrueRandom;
|
||||||
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstact class used for all command that need to find the max number of page on a web site.
|
||||||
|
*/
|
||||||
|
@Ignore
|
||||||
|
public abstract class NumberedCommande implements Commande {
|
||||||
|
protected int minNumber = 1;
|
||||||
|
protected int maxNumber = -1;
|
||||||
|
protected String baseURL;
|
||||||
|
protected String divClass;
|
||||||
|
protected String htmlType;
|
||||||
|
protected String urlSuffix;
|
||||||
|
protected LinkedBlockingQueue<Integer> randomQueue = new LinkedBlockingQueue<>();
|
||||||
|
private Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor
|
||||||
|
*
|
||||||
|
* @param logger Logger used for logs
|
||||||
|
* @param baseURL WebSite base url
|
||||||
|
* @param divClass DivClass to search to extract image
|
||||||
|
* @param htmlType HTML tag to extract image (img)
|
||||||
|
*/
|
||||||
|
public NumberedCommande(Logger logger, String baseURL, String urlSuffix, String divClass, String htmlType) {
|
||||||
|
this.logger = logger;
|
||||||
|
this.baseURL = baseURL;
|
||||||
|
this.divClass = divClass;
|
||||||
|
this.htmlType = htmlType;
|
||||||
|
this.urlSuffix = urlSuffix;
|
||||||
|
try {
|
||||||
|
logger.debug("Checking max...");
|
||||||
|
maxNumber = LimitChecker.doYourJob(baseURL, 2, urlSuffix);
|
||||||
|
logger.info("Limit is " + maxNumber);
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.catching(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public NumberedCommande(Logger logger, String baseURL, String urlSuffix) {
|
||||||
|
this(logger, baseURL, urlSuffix, null, null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void action(String[] args, MessageReceivedEvent event) {
|
||||||
|
try {
|
||||||
|
if (args.length == 0) {
|
||||||
|
String result = poll();
|
||||||
|
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n" + result).queue();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
switch (args[0].toLowerCase()) {
|
||||||
|
case "update":
|
||||||
|
logger.info("update commande from " + event.getMessage().getAuthor().getName());
|
||||||
|
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:arrow_right: Updating...").queue();
|
||||||
|
|
||||||
|
int newNumber = maxNumber;
|
||||||
|
try {
|
||||||
|
newNumber = LimitChecker.doYourJob(baseURL, maxNumber, urlSuffix);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
if (newNumber == maxNumber) {
|
||||||
|
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:arrow_right: 0 new picture found :cry:").queue();
|
||||||
|
} else if (newNumber - maxNumber == 1)
|
||||||
|
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:arrow_right: " + (newNumber - maxNumber) + " picture has been found :kissing_heart:").queue();
|
||||||
|
else
|
||||||
|
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:arrow_right: " + (newNumber - maxNumber) + " pictures has been found :kissing_heart:").queue();
|
||||||
|
logger.info((newNumber - maxNumber) + " new image(s) found.");
|
||||||
|
maxNumber = newNumber;
|
||||||
|
break;
|
||||||
|
case "get":
|
||||||
|
if (args.length >= 2) {
|
||||||
|
|
||||||
|
int number = -1;
|
||||||
|
try {
|
||||||
|
number = Integer.parseInt(args[1]);
|
||||||
|
URL url = new URL(baseURL + number + "-2/");
|
||||||
|
HttpURLConnection huc = (HttpURLConnection) url.openConnection();
|
||||||
|
huc.setRequestMethod("GET");
|
||||||
|
huc.connect();
|
||||||
|
int result = huc.getResponseCode();
|
||||||
|
if (result == 200) {
|
||||||
|
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n" + baseURL + number + urlSuffix).queue();
|
||||||
|
} else {
|
||||||
|
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Error__** :warning:\n:arrow_right: Page not found (404)").queue();
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Error__** :warning:\n:arrow_right: Bad argument. `//help " + this.toString().toLowerCase() + "` for more info ").queue();
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.catching(e);
|
||||||
|
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Error__** :warning:\n:arrow_right: Internal error...").queue();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Error__** :warning:\n:arrow_right: Bad argument. `//help " + this.toString().toLowerCase() + "` for more info ").queue();
|
||||||
|
logger.warn("Bad Argument: " + event.getMessage().getContentRaw() + " From " + event.getAuthor().getName());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Error__** :warning:\n:arrow_right: Bad argument. `//help " + this.toString().toLowerCase() + "` for more info ").queue();
|
||||||
|
logger.warn("Bad Argument: " + event.getMessage().getContentRaw() + " From " + event.getAuthor().getName());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.catching(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void completeRandom() throws IOException {
|
||||||
|
TrueRandom trueRandom = TrueRandom.getINSTANCE();
|
||||||
|
ArrayList<Integer> numbers = trueRandom.getNumbers(minNumber, maxNumber);
|
||||||
|
|
||||||
|
randomQueue.addAll(numbers);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void checkRandom() throws IOException {
|
||||||
|
logger.trace("Queue size: " + randomQueue.size());
|
||||||
|
if (randomQueue.isEmpty()) {
|
||||||
|
logger.debug("Queue empty, update it.");
|
||||||
|
completeRandom();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String poll() throws IOException {
|
||||||
|
checkRandom();
|
||||||
|
int randomResult = randomQueue.poll();
|
||||||
|
return FindContentOnWebPage.doYourJob(baseURL + randomResult + urlSuffix, divClass, htmlType);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,112 +0,0 @@
|
|||||||
package net.Broken.Tools.Command;
|
|
||||||
|
|
||||||
import net.Broken.Commande;
|
|
||||||
import net.Broken.SlashCommand;
|
|
||||||
import net.Broken.Tools.EmbedMessageUtils;
|
|
||||||
import net.Broken.Tools.FindContentOnWebPage;
|
|
||||||
import net.Broken.Tools.LimitChecker;
|
|
||||||
import net.Broken.Tools.TrueRandom;
|
|
||||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
|
||||||
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Abstact class used for all command that need to find the max number of page on a web site.
|
|
||||||
*/
|
|
||||||
@Ignore
|
|
||||||
public abstract class NumberedSlashCommand implements SlashCommand {
|
|
||||||
protected int minNumber = 1;
|
|
||||||
protected int maxNumber = -1;
|
|
||||||
protected String baseURL;
|
|
||||||
protected String divClass;
|
|
||||||
protected String htmlType;
|
|
||||||
protected String urlSuffix;
|
|
||||||
protected LinkedBlockingQueue<Integer> randomQueue = new LinkedBlockingQueue<>();
|
|
||||||
private Logger logger = LogManager.getLogger();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default constructor
|
|
||||||
*
|
|
||||||
* @param logger Logger used for logs
|
|
||||||
* @param baseURL WebSite base url
|
|
||||||
* @param divClass DivClass to search to extract image
|
|
||||||
* @param htmlType HTML tag to extract image (img)
|
|
||||||
*/
|
|
||||||
public NumberedSlashCommand(Logger logger, String baseURL, String urlSuffix, String divClass, String htmlType) {
|
|
||||||
this.logger = logger;
|
|
||||||
this.baseURL = baseURL;
|
|
||||||
this.divClass = divClass;
|
|
||||||
this.htmlType = htmlType;
|
|
||||||
this.urlSuffix = urlSuffix;
|
|
||||||
try {
|
|
||||||
logger.debug("Checking max...");
|
|
||||||
maxNumber = LimitChecker.doYourJob(baseURL, 2, urlSuffix);
|
|
||||||
logger.info("Limit is " + maxNumber);
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.catching(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public NumberedSlashCommand(Logger logger, String baseURL, String urlSuffix) {
|
|
||||||
this(logger, baseURL, urlSuffix, null, null);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void action(SlashCommandEvent event) {
|
|
||||||
event.deferReply().queue();
|
|
||||||
try {
|
|
||||||
String result = poll();
|
|
||||||
event.getHook().sendMessage(event.getMember().getAsMention() + "\n" + result).queue();
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.catching(e);
|
|
||||||
MessageEmbed message = EmbedMessageUtils.getInternalError();
|
|
||||||
event.getHook().setEphemeral(true).sendMessageEmbeds(message).queue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void fillRandomQueue() throws IOException {
|
|
||||||
TrueRandom trueRandom = TrueRandom.getINSTANCE();
|
|
||||||
ArrayList<Integer> numbers = trueRandom.getNumbers(minNumber, maxNumber);
|
|
||||||
|
|
||||||
randomQueue.addAll(numbers);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void checkRandom() throws IOException {
|
|
||||||
logger.trace("Queue size: " + randomQueue.size());
|
|
||||||
if (randomQueue.isEmpty()) {
|
|
||||||
logger.debug("Queue empty, update it.");
|
|
||||||
fillRandomQueue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String poll() throws IOException {
|
|
||||||
checkRandom();
|
|
||||||
int randomResult = randomQueue.poll();
|
|
||||||
return FindContentOnWebPage.doYourJob(baseURL + randomResult + urlSuffix, divClass, htmlType);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<OptionData> getOptions() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<SubcommandData> getSubcommands() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -50,10 +50,13 @@ public class SlashCommandLoader {
|
|||||||
NoSuchMethodException e) {
|
NoSuchMethodException e) {
|
||||||
logger.error("Failed to load " + name + "!");
|
logger.error("Failed to load " + name + "!");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
logger.trace("Ignored command: " + name);
|
logger.trace("Ignored command: " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,10 +68,8 @@ public class SlashCommandLoader {
|
|||||||
if (v.getSubcommands() != null) {
|
if (v.getSubcommands() != null) {
|
||||||
command.addSubcommands(v.getSubcommands());
|
command.addSubcommands(v.getSubcommands());
|
||||||
}
|
}
|
||||||
command.setDefaultEnabled(!v.isDisableByDefault());
|
|
||||||
commandListUpdateAction.addCommands(command);
|
commandListUpdateAction.addCommands(command);
|
||||||
});
|
});
|
||||||
commandListUpdateAction.queue();
|
commandListUpdateAction.queue();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package net.Broken.Tools.DayListener.Listeners;
|
package net.Broken.Tools.DayListener.Listeners;
|
||||||
|
|
||||||
|
import net.Broken.Commands.Over18.Madame;
|
||||||
import net.Broken.DB.Entity.GuildPreferenceEntity;
|
import net.Broken.DB.Entity.GuildPreferenceEntity;
|
||||||
import net.Broken.DB.Repository.GuildPreferenceRepository;
|
import net.Broken.DB.Repository.GuildPreferenceRepository;
|
||||||
import net.Broken.MainBot;
|
import net.Broken.MainBot;
|
||||||
import net.Broken.SlashCommands.Over18.Madame;
|
|
||||||
import net.Broken.SpringContext;
|
import net.Broken.SpringContext;
|
||||||
import net.Broken.Tools.DayListener.NewDayListener;
|
import net.Broken.Tools.DayListener.NewDayListener;
|
||||||
import net.Broken.Tools.FindContentOnWebPage;
|
import net.Broken.Tools.FindContentOnWebPage;
|
||||||
@ -50,7 +50,7 @@ public class DailyMadame implements NewDayListener {
|
|||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Madame command = (Madame) MainBot.slashCommands.get("madame");
|
Madame command = (Madame) MainBot.commandes.get("madame");
|
||||||
imgUrl = command.poll();
|
imgUrl = command.poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ public class EmbedMessageUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static MessageEmbed getMusicInfo(AudioTrackInfo info, UserAudioTrack userAudioTrack) {
|
public static MessageEmbed getMusicInfo(AudioTrackInfo info, UserAudioTrack userAudioTrack) {
|
||||||
EmbedBuilder temp = new EmbedBuilder().setTitle(":information_source: Currently playing")
|
EmbedBuilder temp = new EmbedBuilder().setTitle(":loud_sound: Currently playing")
|
||||||
.addField("Title", info.title, false)
|
.addField("Title", info.title, false)
|
||||||
.addField("Author", info.author, false)
|
.addField("Author", info.author, false)
|
||||||
.addField("URL", info.uri, false)
|
.addField("URL", info.uri, false)
|
||||||
|
126
src/main/java/net/Broken/Tools/TableRenderer.java
Normal file
126
src/main/java/net/Broken/Tools/TableRenderer.java
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
package net.Broken.Tools;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utils to render table in block code
|
||||||
|
*/
|
||||||
|
public class TableRenderer {
|
||||||
|
|
||||||
|
private int width;
|
||||||
|
private List<Object> header;
|
||||||
|
private List<List<Object>> table = new ArrayList<>();
|
||||||
|
|
||||||
|
private String empty = "";
|
||||||
|
|
||||||
|
public TableRenderer() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Table header(s)
|
||||||
|
*
|
||||||
|
* @param header Header(s) as String
|
||||||
|
*/
|
||||||
|
public void setHeader(Object... header) {
|
||||||
|
this.header = Arrays.asList(header);
|
||||||
|
if (header.length > this.width)
|
||||||
|
this.width = header.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add row to table
|
||||||
|
*
|
||||||
|
* @param content Content(s) as string
|
||||||
|
*/
|
||||||
|
public void addRow(Object... content) {
|
||||||
|
List<Object> objects = Arrays.asList(content);
|
||||||
|
table.add(objects);
|
||||||
|
if (content.length > this.width)
|
||||||
|
this.width = content.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change default empty string
|
||||||
|
*
|
||||||
|
* @param str
|
||||||
|
*/
|
||||||
|
public void setEmptyString(String str) {
|
||||||
|
this.empty = str;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[][] normalizeTable() {
|
||||||
|
int height = header == null ? table.size() : (table.size() + 1);
|
||||||
|
String[][] normalized = new String[height][width];
|
||||||
|
|
||||||
|
int vIndex = 0;
|
||||||
|
if (header != null) {
|
||||||
|
for (int hIndex = 0; hIndex < width; hIndex++) {
|
||||||
|
if (header.size() > hIndex)
|
||||||
|
normalized[vIndex][hIndex] = header.get(hIndex).toString();
|
||||||
|
else
|
||||||
|
normalized[vIndex][hIndex] = this.empty;
|
||||||
|
}
|
||||||
|
vIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (List<Object> obj : table) {
|
||||||
|
for (int hIndex = 0; hIndex < width; hIndex++) {
|
||||||
|
if (obj.size() > hIndex)
|
||||||
|
normalized[vIndex][hIndex] = obj.get(hIndex).toString();
|
||||||
|
else
|
||||||
|
normalized[vIndex][hIndex] = this.empty + "s";
|
||||||
|
}
|
||||||
|
vIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int[] getCollumnWidths(String[][] table, int padding) {
|
||||||
|
int collums[] = new int[width];
|
||||||
|
for (int vIndex = 0; vIndex < table.length; vIndex++)
|
||||||
|
for (int hIndex = 0; hIndex < width; hIndex++)
|
||||||
|
if (table[vIndex][hIndex].length() + padding > collums[hIndex])
|
||||||
|
collums[hIndex] = table[vIndex][hIndex].length() + padding;
|
||||||
|
collums[collums.length - 1] -= padding;
|
||||||
|
return collums;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String buildElement(String element, int width, String emptyChar) {
|
||||||
|
String result = element;
|
||||||
|
if (result.length() < width)
|
||||||
|
result += StringUtils.repeat(emptyChar, width - result.length());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildLine(String[] strings, int[] widths, boolean header) {
|
||||||
|
String line = IntStream.range(0, strings.length)
|
||||||
|
.mapToObj((i) -> buildElement(strings[i], widths[i], " "))
|
||||||
|
.collect(Collectors.joining("│ "));
|
||||||
|
line = "│ " + line + " │";
|
||||||
|
if (header) {
|
||||||
|
String seperator = IntStream.range(0, strings.length)
|
||||||
|
.mapToObj((i) -> buildElement("", widths[i], "═"))
|
||||||
|
.collect(Collectors.joining("╪"));
|
||||||
|
line += "\n" + "╪═" + seperator + "══╪";
|
||||||
|
}
|
||||||
|
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String build() {
|
||||||
|
String[][] table = normalizeTable();
|
||||||
|
int[] widths = getCollumnWidths(table, 1);
|
||||||
|
return IntStream.range(0, table.length)
|
||||||
|
.mapToObj(i -> buildLine(table[i], widths, header != null && i == 0))
|
||||||
|
.collect(Collectors.joining("\n"));
|
||||||
|
}
|
||||||
|
}
|
@ -249,7 +249,7 @@ public class UserStatsUtils {
|
|||||||
|
|
||||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||||
embedBuilder.setColor(Color.yellow);
|
embedBuilder.setColor(Color.yellow);
|
||||||
embedBuilder.setTitle(":trophy: " + member.getGuild().getName() + " Ranking");
|
embedBuilder.setTitle(member.getGuild().getName() + " Ranking");
|
||||||
embedBuilder.addField("Top 5:", stringBuilder.toString(), false);
|
embedBuilder.addField("Top 5:", stringBuilder.toString(), false);
|
||||||
String rank;
|
String rank;
|
||||||
switch (pack.selfStats.rank) {
|
switch (pack.selfStats.rank) {
|
||||||
@ -269,6 +269,7 @@ public class UserStatsUtils {
|
|||||||
|
|
||||||
|
|
||||||
embedBuilder.addField("Your stats:", rank + " with " + pack.selfStats.total + " points", false);
|
embedBuilder.addField("Your stats:", rank + " with " + pack.selfStats.total + " points", false);
|
||||||
|
embedBuilder.addField("More stats:", "https://" + MainBot.url + "/rank", false);
|
||||||
return EmbedMessageUtils.buildStandar(embedBuilder);
|
return EmbedMessageUtils.buildStandar(embedBuilder);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,17 +13,14 @@ import net.Broken.RestApi.Data.UserAudioTrackData;
|
|||||||
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.MessageBuilder;
|
||||||
import net.dv8tion.jda.api.entities.*;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
import net.dv8tion.jda.api.events.interaction.GenericInteractionCreateEvent;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.entities.User;
|
||||||
|
import net.dv8tion.jda.api.entities.VoiceChannel;
|
||||||
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
||||||
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
|
||||||
import net.dv8tion.jda.api.interactions.components.Button;
|
|
||||||
import net.dv8tion.jda.api.interactions.components.ComponentLayout;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -57,8 +54,6 @@ public class AudioM {
|
|||||||
private Guild guild;
|
private Guild guild;
|
||||||
private Logger logger = LogManager.getLogger();
|
private Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
private Message lastMessageWithButton;
|
|
||||||
|
|
||||||
private AudioM(Guild guild) {
|
private AudioM(Guild guild) {
|
||||||
this.playerManager = new DefaultAudioPlayerManager();
|
this.playerManager = new DefaultAudioPlayerManager();
|
||||||
AudioSourceManagers.registerRemoteSources(playerManager);
|
AudioSourceManagers.registerRemoteSources(playerManager);
|
||||||
@ -95,8 +90,7 @@ public class AudioM {
|
|||||||
Message message = new MessageBuilder()
|
Message message = new MessageBuilder()
|
||||||
.setEmbeds(EmbedMessageUtils.getMusicAdded(track.getInfo(), event.getMember(), -1))
|
.setEmbeds(EmbedMessageUtils.getMusicAdded(track.getInfo(), event.getMember(), -1))
|
||||||
.build();
|
.build();
|
||||||
clearLastButton();
|
event.getHook().sendMessage(message).queue();
|
||||||
lastMessageWithButton = event.getHook().sendMessage(message).addActionRow(getActionButton()).complete();
|
|
||||||
play(guild, voiceChannel, musicManager, uat, onHead);
|
play(guild, voiceChannel, musicManager, uat, onHead);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,8 +102,7 @@ public class AudioM {
|
|||||||
Message message = new MessageBuilder()
|
Message message = new MessageBuilder()
|
||||||
.setEmbeds(EmbedMessageUtils.getMusicAdded(firstTrack.getInfo(), event.getMember(), size))
|
.setEmbeds(EmbedMessageUtils.getMusicAdded(firstTrack.getInfo(), event.getMember(), size))
|
||||||
.build();
|
.build();
|
||||||
clearLastButton();
|
event.getHook().sendMessage(message).queue();
|
||||||
lastMessageWithButton = event.getHook().sendMessage(message).addActionRow(getActionButton()).complete();
|
|
||||||
playListLoader(playlist, playlistLimit, event.getUser(), onHead);
|
playListLoader(playlist, playlistLimit, event.getUser(), onHead);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,17 +211,11 @@ public class AudioM {
|
|||||||
*
|
*
|
||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
public void skipTrack(GenericInteractionCreateEvent event) {
|
public void skipTrack(SlashCommandEvent event) {
|
||||||
GuildMusicManager musicManager = getGuildAudioPlayer();
|
GuildMusicManager musicManager = getGuildAudioPlayer();
|
||||||
musicManager.scheduler.nextTrack();
|
musicManager.scheduler.nextTrack();
|
||||||
Message message = new MessageBuilder().setEmbeds(
|
Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicOk("Next music !")).build();
|
||||||
EmbedMessageUtils.buildStandar(
|
event.getHook().sendMessage(message).queue();
|
||||||
new EmbedBuilder()
|
|
||||||
.setTitle(":track_next: Next Track")
|
|
||||||
.setColor(Color.green)
|
|
||||||
)).build();
|
|
||||||
clearLastButton();
|
|
||||||
lastMessageWithButton = event.getHook().sendMessage(message).addActionRow(getActionButton()).complete();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -236,17 +223,11 @@ public class AudioM {
|
|||||||
*
|
*
|
||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
public void pause(GenericInteractionCreateEvent event) {
|
public void pause(SlashCommandEvent event) {
|
||||||
GuildMusicManager musicManager = getGuildAudioPlayer();
|
GuildMusicManager musicManager = getGuildAudioPlayer();
|
||||||
musicManager.scheduler.pause();
|
musicManager.scheduler.pause();
|
||||||
Message message = new MessageBuilder().setEmbeds(
|
Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicOk("Playback paused")).build();
|
||||||
EmbedMessageUtils.buildStandar(
|
event.getHook().sendMessage(message).queue();
|
||||||
new EmbedBuilder()
|
|
||||||
.setTitle(":pause_button: Playback paused")
|
|
||||||
.setColor(Color.green)
|
|
||||||
)).build();
|
|
||||||
clearLastButton();
|
|
||||||
lastMessageWithButton = event.getHook().sendMessage(message).addActionRow(getActionButton()).complete();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -256,27 +237,11 @@ public class AudioM {
|
|||||||
*
|
*
|
||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
public void resume(GenericInteractionCreateEvent event) {
|
public void resume(SlashCommandEvent event) {
|
||||||
GuildMusicManager musicManager = getGuildAudioPlayer();
|
GuildMusicManager musicManager = getGuildAudioPlayer();
|
||||||
Message message;
|
musicManager.scheduler.resume();
|
||||||
if(musicManager.player.getPlayingTrack() == null){
|
Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicOk("Playback resumed")).build();
|
||||||
message = new MessageBuilder().setEmbeds(
|
event.getHook().sendMessage(message).queue();
|
||||||
EmbedMessageUtils.buildStandar(
|
|
||||||
new EmbedBuilder()
|
|
||||||
.setTitle(":warning: Nothing to play, playlist is empty !")
|
|
||||||
.setColor(Color.green)
|
|
||||||
)).build();
|
|
||||||
}else{
|
|
||||||
musicManager.scheduler.resume();
|
|
||||||
message = new MessageBuilder().setEmbeds(
|
|
||||||
EmbedMessageUtils.buildStandar(
|
|
||||||
new EmbedBuilder()
|
|
||||||
.setTitle(":arrow_forward: Playback resumed")
|
|
||||||
.setColor(Color.green)
|
|
||||||
)).build();
|
|
||||||
}
|
|
||||||
clearLastButton();
|
|
||||||
lastMessageWithButton = event.getHook().sendMessage(message).addActionRow(getActionButton()).complete();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -284,26 +249,19 @@ public class AudioM {
|
|||||||
*
|
*
|
||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
public void info(GenericInteractionCreateEvent event) {
|
public void info(SlashCommandEvent event) {
|
||||||
GuildMusicManager musicManager = getGuildAudioPlayer();
|
GuildMusicManager musicManager = getGuildAudioPlayer();
|
||||||
AudioTrackInfo info = musicManager.scheduler.getInfo();
|
AudioTrackInfo info = musicManager.scheduler.getInfo();
|
||||||
UserAudioTrack userAudioTrack = musicManager.scheduler.getCurrentPlayingTrack();
|
UserAudioTrack userAudioTrack = musicManager.scheduler.getCurrentPlayingTrack();
|
||||||
Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicInfo(info, userAudioTrack)).build();
|
Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicInfo(info, userAudioTrack)).build();
|
||||||
clearLastButton();
|
event.getHook().sendMessage(message).queue();
|
||||||
lastMessageWithButton = event.getHook().sendMessage(message).addActionRow(getActionButton()).complete();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flush(GenericInteractionCreateEvent event) {
|
public void flush(SlashCommandEvent event) {
|
||||||
GuildMusicManager musicManager = getGuildAudioPlayer();
|
GuildMusicManager musicManager = getGuildAudioPlayer();
|
||||||
musicManager.scheduler.flush();
|
musicManager.scheduler.flush();
|
||||||
Message message = new MessageBuilder().setEmbeds(
|
Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicOk("Flush playlist!")).build();
|
||||||
EmbedMessageUtils.buildStandar(
|
event.getHook().sendMessage(message).queue();
|
||||||
new EmbedBuilder()
|
|
||||||
.setTitle(":wastebasket: Playlist flushed")
|
|
||||||
.setColor(Color.green)
|
|
||||||
)).build();
|
|
||||||
clearLastButton();
|
|
||||||
lastMessageWithButton = event.getHook().sendMessage(message).addActionRow(getActionButton()).complete();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -311,46 +269,21 @@ public class AudioM {
|
|||||||
*
|
*
|
||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
public void list(GenericInteractionCreateEvent event) {
|
public void list(SlashCommandEvent event) {
|
||||||
GuildMusicManager musicManager = getGuildAudioPlayer();
|
GuildMusicManager musicManager = getGuildAudioPlayer();
|
||||||
List<UserAudioTrackData> list = musicManager.scheduler.getList();
|
List<UserAudioTrackData> list = musicManager.scheduler.getList();
|
||||||
|
StringBuilder resp = new StringBuilder();
|
||||||
if (list.size() == 0) {
|
if (list.size() == 0) {
|
||||||
Message message = new MessageBuilder().setEmbeds(
|
resp.append("Oh my god!\nThe playlist is empty ! \n:astonished: ");
|
||||||
EmbedMessageUtils.buildStandar(
|
|
||||||
new EmbedBuilder()
|
|
||||||
.setTitle(":scroll: Playlist")
|
|
||||||
.setColor(Color.green)
|
|
||||||
.setDescription("Oh no ! The playlist is empty !")
|
|
||||||
)).build();
|
|
||||||
event.getHook().sendMessage(message).queue();
|
|
||||||
} else {
|
} else {
|
||||||
StringBuilder resp = new StringBuilder();
|
|
||||||
int i = 0;
|
|
||||||
for (UserAudioTrackData trackInfo : list) {
|
for (UserAudioTrackData trackInfo : list) {
|
||||||
resp.append(":arrow_right: ");
|
resp.append("- ");
|
||||||
resp.append(trackInfo.getAudioTrackInfo().title);
|
resp.append(trackInfo.getAudioTrackInfo().title);
|
||||||
resp.append(" - ");
|
resp.append("\n");
|
||||||
resp.append(trackInfo.getAudioTrackInfo().author);
|
|
||||||
resp.append("\n\n");
|
|
||||||
if (i >= 5) {
|
|
||||||
resp.append(":arrow_forward: And ");
|
|
||||||
resp.append(list.size() - 5);
|
|
||||||
resp.append(" other tracks ...");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
Message message = new MessageBuilder().setEmbeds(
|
|
||||||
EmbedMessageUtils.buildStandar(
|
|
||||||
new EmbedBuilder()
|
|
||||||
.setTitle(":scroll: Playlist")
|
|
||||||
.setColor(Color.green)
|
|
||||||
.setDescription(resp.toString())
|
|
||||||
)).build();
|
|
||||||
event.getHook().sendMessage(message).queue();
|
|
||||||
}
|
}
|
||||||
|
Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicOk("Playlist:\n\n" + resp.toString())).build();
|
||||||
|
event.getHook().sendMessage(message).queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -375,39 +308,16 @@ public class AudioM {
|
|||||||
*
|
*
|
||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
public void stop(GenericInteractionCreateEvent event) {
|
public void stop(SlashCommandEvent event) {
|
||||||
musicManager.scheduler.stop();
|
musicManager.scheduler.stop();
|
||||||
musicManager.scheduler.flush();
|
musicManager.scheduler.flush();
|
||||||
|
|
||||||
if (event != null) {
|
if (event != null) {
|
||||||
Message message = new MessageBuilder().setEmbeds(
|
Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicOk("Music stopped")).build();
|
||||||
EmbedMessageUtils.buildStandar(
|
event.getHook().sendMessage(message).queue();
|
||||||
new EmbedBuilder()
|
|
||||||
.setTitle(":stop_button: Playback stopped")
|
|
||||||
.setColor(Color.green)
|
|
||||||
)).build();
|
|
||||||
clearLastButton();
|
|
||||||
lastMessageWithButton = event.getHook().sendMessage(message).addActionRow(getActionButton()).complete();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disconect(GenericInteractionCreateEvent event){
|
|
||||||
GuildMusicManager musicManager = getGuildAudioPlayer();
|
|
||||||
musicManager.scheduler.stop();
|
|
||||||
musicManager.scheduler.flush();
|
|
||||||
playedChanel = null;
|
|
||||||
guild.getAudioManager().closeAudioConnection();
|
|
||||||
clearLastButton();
|
|
||||||
Message message = new MessageBuilder().setEmbeds(
|
|
||||||
EmbedMessageUtils.buildStandar(
|
|
||||||
new EmbedBuilder()
|
|
||||||
.setTitle(":eject: Disconnected")
|
|
||||||
.setColor(Color.green)
|
|
||||||
)).build();
|
|
||||||
clearLastButton();
|
|
||||||
event.getHook().sendMessage(message).queue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop current playing track and flush playlist (no confirmation message)
|
* Stop current playing track and flush playlist (no confirmation message)
|
||||||
*/
|
*/
|
||||||
@ -418,7 +328,6 @@ public class AudioM {
|
|||||||
musicManager.scheduler.flush();
|
musicManager.scheduler.flush();
|
||||||
playedChanel = null;
|
playedChanel = null;
|
||||||
guild.getAudioManager().closeAudioConnection();
|
guild.getAudioManager().closeAudioConnection();
|
||||||
clearLastButton();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuildMusicManager getGuildMusicManager() {
|
public GuildMusicManager getGuildMusicManager() {
|
||||||
@ -443,38 +352,4 @@ public class AudioM {
|
|||||||
public void setPlayedChanel(VoiceChannel playedChanel) {
|
public void setPlayedChanel(VoiceChannel playedChanel) {
|
||||||
this.playedChanel = playedChanel;
|
this.playedChanel = playedChanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearLastButton() {
|
|
||||||
if (lastMessageWithButton != null){
|
|
||||||
this.lastMessageWithButton.editMessageComponents(new ArrayList<>()).queue();
|
|
||||||
this.lastMessageWithButton = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
public void updateLastButton(){
|
|
||||||
if (lastMessageWithButton != null)
|
|
||||||
lastMessageWithButton = lastMessageWithButton.editMessageComponents(ActionRow.of(getActionButton())).complete();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private List<Button> getActionButton(){
|
|
||||||
ArrayList<Button> buttonArrayList = new ArrayList<>();
|
|
||||||
if(musicManager.player.getPlayingTrack() == null){
|
|
||||||
buttonArrayList.add(Button.success("play", Emoji.fromUnicode("▶️")).withDisabled(true));
|
|
||||||
buttonArrayList.add(Button.primary("next", Emoji.fromUnicode("⏭️")).withDisabled(true));
|
|
||||||
buttonArrayList.add(Button.primary("stop", Emoji.fromUnicode("⏹️")).withDisabled(true));
|
|
||||||
buttonArrayList.add(Button.danger("disconnect", Emoji.fromUnicode("⏏️")));
|
|
||||||
return buttonArrayList;
|
|
||||||
}
|
|
||||||
if(musicManager.player.isPaused()){
|
|
||||||
buttonArrayList.add(Button.success("play", Emoji.fromUnicode("▶️")));
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
buttonArrayList.add(Button.success("pause", Emoji.fromUnicode("⏸️")));
|
|
||||||
}
|
|
||||||
buttonArrayList.add(Button.primary("next", Emoji.fromUnicode("⏭️")));
|
|
||||||
buttonArrayList.add(Button.primary("stop", Emoji.fromUnicode("⏹️")));
|
|
||||||
buttonArrayList.add(Button.danger("disconnect", Emoji.fromUnicode("⏏️")));
|
|
||||||
return buttonArrayList;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package net.Broken.audio;
|
|||||||
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
|
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
|
||||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||||
import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter;
|
import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter;
|
||||||
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
|
|
||||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason;
|
import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason;
|
||||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
|
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
|
||||||
@ -164,11 +163,10 @@ public class TrackScheduler extends AudioEventAdapter {
|
|||||||
// Start the next track, regardless of if something is already playing or not. In case queue was empty, we are
|
// Start the next track, regardless of if something is already playing or not. In case queue was empty, we are
|
||||||
// giving null to startTrack, which is a valid argument and will simply stop the player.
|
// giving null to startTrack, which is a valid argument and will simply stop the player.
|
||||||
UserAudioTrack track = queue.poll();
|
UserAudioTrack track = queue.poll();
|
||||||
if (track != null){
|
if (track != null)
|
||||||
this.currentPlayingTrack = track;
|
this.currentPlayingTrack = track;
|
||||||
|
if (track != null)
|
||||||
player.startTrack(track.getAudioTrack(), false);
|
player.startTrack(track.getAudioTrack(), false);
|
||||||
}
|
|
||||||
|
|
||||||
needAutoPlay();
|
needAutoPlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,48 +174,11 @@ public class TrackScheduler extends AudioEventAdapter {
|
|||||||
public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) {
|
public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) {
|
||||||
// Only start the next track if the end reason is suitable for it (FINISHED or LOAD_FAILED)
|
// Only start the next track if the end reason is suitable for it (FINISHED or LOAD_FAILED)
|
||||||
if (endReason.mayStartNext) {
|
if (endReason.mayStartNext) {
|
||||||
if(queue.isEmpty()){
|
logger.debug("[" + guild + "] End of track, start next.");
|
||||||
logger.debug("[" + guild.getName() + "] End of track, Playlist empty.");
|
nextTrack();
|
||||||
AudioM.getInstance(guild).updateLastButton();
|
|
||||||
}else{
|
|
||||||
logger.debug("[" + guild.getName() + "] End of track, start next.");
|
|
||||||
nextTrack();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTrackStart(AudioPlayer player, AudioTrack track) {
|
|
||||||
super.onTrackStart(player, track);
|
|
||||||
AudioM.getInstance(guild).updateLastButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPlayerPause(AudioPlayer player) {
|
|
||||||
super.onPlayerPause(player);
|
|
||||||
AudioM.getInstance(guild).updateLastButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPlayerResume(AudioPlayer player) {
|
|
||||||
super.onPlayerResume(player);
|
|
||||||
AudioM.getInstance(guild).updateLastButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTrackException(AudioPlayer player, AudioTrack track, FriendlyException exception) {
|
|
||||||
super.onTrackException(player, track, exception);
|
|
||||||
AudioM.getInstance(guild).updateLastButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTrackStuck(AudioPlayer player, AudioTrack track, long thresholdMs) {
|
|
||||||
super.onTrackStuck(player, track, thresholdMs);
|
|
||||||
AudioM.getInstance(guild).updateLastButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void needAutoPlay() {
|
private void needAutoPlay() {
|
||||||
if ((queue.size() < 1) && autoFlow && currentPlayingTrack != null) {
|
if ((queue.size() < 1) && autoFlow && currentPlayingTrack != null) {
|
||||||
logger.debug("[" + guild.getName() + "] Auto add needed!");
|
logger.debug("[" + guild.getName() + "] Auto add needed!");
|
||||||
|
Loading…
Reference in New Issue
Block a user