Updated the jdrbot to be at the same standard as potatos
This commit was merged in pull request #1.
This commit is contained in:
54
src/main/java/.idea/workspace.xml
generated
54
src/main/java/.idea/workspace.xml
generated
@@ -1,54 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AutoImportSettings">
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="92be5a76-72cc-4791-b8e0-146745624e77" name="Default Changelist" comment="" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="ExternalProjectsData">
|
||||
<projectState path="$PROJECT_DIR$">
|
||||
<ProjectState />
|
||||
</projectState>
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/../../.." />
|
||||
</component>
|
||||
<component name="ProjectId" id="1ptZSIDZd86tmu17YY146ADRTUU" />
|
||||
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
|
||||
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
||||
<property name="settings.editor.selected.configurable" value="Errors" />
|
||||
</component>
|
||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="92be5a76-72cc-4791-b8e0-146745624e77" name="Default Changelist" comment="" />
|
||||
<created>1616004344851</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1616004344851</updated>
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
<option name="TAB_STATES">
|
||||
<map>
|
||||
<entry key="MAIN">
|
||||
<value>
|
||||
<State />
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
@@ -1,25 +1,24 @@
|
||||
package fr.Skydust.JdrBot;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Timer;
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
||||
import fr.Skydust.JdrBot.cmds.*;
|
||||
import fr.Skydust.JdrBot.cmds.playmusic.*;
|
||||
import fr.Skydust.JdrBot.cmds.record.CancelRecord;
|
||||
import fr.Skydust.JdrBot.cmds.record.Record;
|
||||
import fr.Skydust.JdrBot.cmds.record.StopRecord;
|
||||
import fr.Skydust.JdrBot.stock.Command;
|
||||
import fr.Skydust.JdrBot.utils.HeartbeatTask;
|
||||
import fr.Skydust.JdrBot.bases.command.Command;
|
||||
import fr.Skydust.JdrBot.bases.command.CommandSpec;
|
||||
import fr.Skydust.JdrBot.tasks.HeartbeatTask;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.entities.Activity;
|
||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||
import net.dv8tion.jda.api.utils.cache.CacheFlag;
|
||||
import org.reflections.Reflections;
|
||||
|
||||
public class JdrBot {
|
||||
public static String Version = "3.1";
|
||||
public static String Version = "4.0";
|
||||
|
||||
public static JDA jda;
|
||||
public static LocalDateTime basedate;
|
||||
@@ -29,7 +28,7 @@ public class JdrBot {
|
||||
|
||||
public static boolean debugMode = false;
|
||||
|
||||
public static void main(String args[]) {
|
||||
public static void main(String[] args) {
|
||||
for (int i=0;i<args.length;i++) {
|
||||
if(args[i].equalsIgnoreCase("--heartbeat")) {
|
||||
if(i == args.length-1) { // Check for an argument after heartbeat
|
||||
@@ -61,32 +60,38 @@ public class JdrBot {
|
||||
|
||||
jda = JDABuilder.createDefault(token)
|
||||
.setActivity(Activity.playing("un jeu de rôle"))
|
||||
.enableIntents(GatewayIntent.MESSAGE_CONTENT)
|
||||
.enableCache(CacheFlag.VOICE_STATE).build();
|
||||
|
||||
jda.awaitReady();
|
||||
commandList = new ArrayList<Command>();
|
||||
|
||||
registerCommand(new Aide());
|
||||
registerCommand(new Etat());
|
||||
registerCommand(new Roll());
|
||||
registerCommand(new Record());
|
||||
registerCommand(new StopRecord());
|
||||
registerCommand(new CancelRecord());
|
||||
registerCommand(new Emote());
|
||||
registerCommand(new PlayMusic());
|
||||
registerCommand(new StopMusic());
|
||||
registerCommand(new FLoad());
|
||||
registerCommand(new FLoadLoop());
|
||||
registerCommands();
|
||||
|
||||
jda.addEventListener(new JdrBotListener());
|
||||
} catch (LoginException e) {
|
||||
System.out.println("The login token is wrong");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerCommand(Command cmd) {
|
||||
commandList.add(cmd);
|
||||
/**
|
||||
* Finds every class annotated with CommandSpec and registers them as a command.
|
||||
*/
|
||||
public static void registerCommands() {
|
||||
commandList = new ArrayList<Command>();
|
||||
|
||||
Reflections reflections = new Reflections("fr.Skydust.JdrBot.cmds");
|
||||
Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(CommandSpec.class);
|
||||
|
||||
for (Class<?> command: annotated) {
|
||||
try {
|
||||
Command cmd = (Command) command.getDeclaredConstructor().newInstance();
|
||||
commandList.add(cmd);
|
||||
|
||||
System.out.println("Registered command "+ cmd.cmdName);
|
||||
} catch (InstantiationException | NoSuchMethodException | InvocationTargetException |
|
||||
IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
package fr.Skydust.JdrBot;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import fr.Skydust.JdrBot.bases.command.Command;
|
||||
import fr.Skydust.JdrBot.cmds.LastTimeOnline;
|
||||
import fr.Skydust.JdrBot.cmds.playmusic.StopMusic;
|
||||
import fr.Skydust.JdrBot.menu.MenuSystem;
|
||||
import fr.Skydust.JdrBot.stock.Command;
|
||||
import fr.Skydust.JdrBot.utils.HeartbeatTask;
|
||||
import fr.Skydust.JdrBot.tasks.HeartbeatTask;
|
||||
import net.dv8tion.jda.api.events.GatewayPingEvent;
|
||||
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.GuildVoiceUpdateEvent;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
|
||||
import net.dv8tion.jda.api.events.user.update.UserUpdateOnlineStatusEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class JdrBotListener extends ListenerAdapter {
|
||||
@Override
|
||||
@@ -38,24 +36,21 @@ public class JdrBotListener extends ListenerAdapter {
|
||||
|
||||
/* LastTimeOnline listener */
|
||||
@Override
|
||||
public void onUserUpdateOnlineStatus(UserUpdateOnlineStatusEvent e) {
|
||||
public void onUserUpdateOnlineStatus(@NotNull UserUpdateOnlineStatusEvent e) {
|
||||
LastTimeOnline.onUserUpdateOnlineStatus(e);
|
||||
}
|
||||
|
||||
/* Empty voice channel listener */
|
||||
@Override
|
||||
public void onGuildVoiceMove(GuildVoiceMoveEvent e) {
|
||||
StopMusic.onGuildVoiceMove(e);
|
||||
}
|
||||
@Override
|
||||
public void onGuildVoiceLeave(GuildVoiceLeaveEvent e) {
|
||||
StopMusic.onGuildVoiceLeave(e);
|
||||
public void onGuildVoiceUpdate(@NotNull GuildVoiceUpdateEvent e) {
|
||||
StopMusic.onGuildVoiceUpdate(e);
|
||||
}
|
||||
/* Menu system listener */
|
||||
@Override
|
||||
public void onMessageReactionAdd(MessageReactionAddEvent e) { MenuSystem.onMessageReactionAdd(e); }
|
||||
public void onMessageReactionAdd(@NotNull MessageReactionAddEvent e) { MenuSystem.onMessageReactionAdd(e); }
|
||||
/* Heartbeat command listener */
|
||||
@Override
|
||||
public void onGatewayPing(GatewayPingEvent e) { HeartbeatTask.HeartbeatUpdateEvent(e); }
|
||||
public void onGatewayPing(@NotNull GatewayPingEvent e) { HeartbeatTask.HeartbeatUpdateEvent(e); }
|
||||
|
||||
public boolean isACommand(String message, String cmd) {
|
||||
return message.matches("^("+ JdrBot.startcmdchar +")("+ cmd +")( .*|)$");
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package fr.Skydust.JdrBot.audio.handler;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame;
|
||||
import fr.Skydust.JdrBot.cmds.record.Record;
|
||||
import fr.Skydust.JdrBot.stock.RecordState;
|
||||
import net.dv8tion.jda.api.audio.AudioReceiveHandler;
|
||||
import net.dv8tion.jda.api.audio.CombinedAudio;
|
||||
import net.dv8tion.jda.api.audio.UserAudio;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class JdrBotARH implements AudioReceiveHandler {
|
||||
private final RecordState recordState;
|
||||
@@ -20,21 +18,10 @@ public class JdrBotARH implements AudioReceiveHandler {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceiveUser() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCombinedAudio(CombinedAudio arg0) {
|
||||
@Override
|
||||
public void handleCombinedAudio(@NotNull CombinedAudio combinedAudio) {
|
||||
if(recordState.isRecording) {
|
||||
recordState.addBytes(arg0.getAudioData(1.0));
|
||||
recordState.addBytes(combinedAudio.getAudioData(1.0));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUserAudio(UserAudio arg0) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
33
src/main/java/fr/Skydust/JdrBot/bases/command/Command.java
Executable file
33
src/main/java/fr/Skydust/JdrBot/bases/command/Command.java
Executable file
@@ -0,0 +1,33 @@
|
||||
package fr.Skydust.JdrBot.bases.command;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public abstract class Command {
|
||||
public String cmdName;
|
||||
public String cmdDesc;
|
||||
public String cmdUsage = "";
|
||||
public boolean hidden = false;
|
||||
|
||||
public Command() {
|
||||
if (!getClass().isAnnotationPresent(CommandSpec.class)) {
|
||||
throw new WrongCommandSpecException("The command spec was not declared ! (@CommandSpec)");
|
||||
}
|
||||
|
||||
CommandSpec specs = getClass().getAnnotation(CommandSpec.class);
|
||||
if (specs.name().isEmpty()) {
|
||||
throw new WrongCommandSpecException("The command name is invalid.");
|
||||
}
|
||||
|
||||
cmdName = specs.name();
|
||||
cmdDesc = specs.description();
|
||||
cmdUsage = specs.usage();
|
||||
|
||||
if (getClass().isAnnotationPresent(HideCommand.class)) {
|
||||
hidden = true;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void call(MessageReceivedEvent e);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package fr.Skydust.JdrBot.bases.command;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface CommandSpec {
|
||||
String name() default "";
|
||||
|
||||
String description() default "Empty description";
|
||||
|
||||
String usage() default "";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package fr.Skydust.JdrBot.bases.command;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface HideCommand {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package fr.Skydust.JdrBot.bases.command;
|
||||
|
||||
public class WrongCommandSpecException extends RuntimeException {
|
||||
public WrongCommandSpecException(String errorMessage) {
|
||||
super(errorMessage);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,17 @@
|
||||
package fr.Skydust.JdrBot.cmds;
|
||||
|
||||
import fr.Skydust.JdrBot.stock.Command;
|
||||
import fr.Skydust.JdrBot.bases.command.Command;
|
||||
import fr.Skydust.JdrBot.bases.command.CommandSpec;
|
||||
import fr.Skydust.JdrBot.bases.command.HideCommand;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
@HideCommand // While its not ready
|
||||
@CommandSpec(
|
||||
name = "addsong",
|
||||
usage = "[Chemin] [URL]",
|
||||
description = "(Admin) Ajoute une musique au jukebox"
|
||||
)
|
||||
public class AddSong extends Command {
|
||||
public AddSong() {
|
||||
SetName("addsong");
|
||||
SetUsage("[Chemin] [URL]");
|
||||
SetDesc("(Admin) Ajoute une musique au jukebox");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(MessageReceivedEvent e) {
|
||||
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
package fr.Skydust.JdrBot.cmds;
|
||||
|
||||
import fr.Skydust.JdrBot.JdrBot;
|
||||
import fr.Skydust.JdrBot.stock.Command;
|
||||
import fr.Skydust.JdrBot.bases.command.Command;
|
||||
import fr.Skydust.JdrBot.bases.command.CommandSpec;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
|
||||
|
||||
import java.awt.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
@CommandSpec(
|
||||
name = "aide",
|
||||
description = "Pour avoir de l'aide !"
|
||||
)
|
||||
public class Aide extends Command {
|
||||
public Aide() {
|
||||
SetName("aide");
|
||||
SetDesc("Pour avoir de l'aide !");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(MessageReceivedEvent e) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@@ -24,11 +24,14 @@ public class Aide extends Command {
|
||||
{
|
||||
Command cmd = JdrBot.commandList.get(i);
|
||||
if(!cmd.hidden) {
|
||||
sb.append("`"+cmd.cmdName + ((cmd.cmdUsage.equals("")) ? "" : " "+cmd.cmdUsage) +"` - *"+cmd.cmdDesc+"*"+ ((i != JdrBot.commandList.size()-1) ? "\n" : ""));
|
||||
sb.append("`"+cmd.cmdName
|
||||
+ ((cmd.cmdUsage.isEmpty()) ? "" : " "+cmd.cmdUsage)
|
||||
+"` - *"+cmd.cmdDesc+"*"
|
||||
+ ((i != JdrBot.commandList.size()-1) ? "\n" : ""));
|
||||
}
|
||||
}
|
||||
|
||||
e.getChannel().sendMessage(new MessageBuilder().setEmbeds(new EmbedBuilder()
|
||||
e.getChannel().sendMessage(new MessageCreateBuilder().setEmbeds(new EmbedBuilder()
|
||||
.setDescription(sb.toString())
|
||||
.setTitle("Aide", null)
|
||||
.setFooter("Fait le " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy 'a' HH:mm:ss")), e.getJDA().getSelfUser().getAvatarUrl())
|
||||
|
||||
@@ -2,15 +2,18 @@ package fr.Skydust.JdrBot.cmds;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import fr.Skydust.JdrBot.stock.Command;
|
||||
import fr.Skydust.JdrBot.bases.command.Command;
|
||||
import fr.Skydust.JdrBot.bases.command.CommandSpec;
|
||||
import fr.Skydust.JdrBot.bases.command.HideCommand;
|
||||
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
@HideCommand
|
||||
@CommandSpec(
|
||||
name = "emote",
|
||||
description = "Donne les informations techniques d'une emote"
|
||||
)
|
||||
public class Emote extends Command {
|
||||
public Emote() {
|
||||
SetName("emote");
|
||||
SetDesc("Donne les informations techniques d'une emote");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(MessageReceivedEvent e) {
|
||||
String[] args = Arrays.copyOfRange(e.getMessage().getContentRaw().split(" "), 1, e.getMessage().getContentRaw().split(" ").length);
|
||||
@@ -19,7 +22,7 @@ public class Emote extends Command {
|
||||
if(str.matches("<:.*:\\d+>"))
|
||||
{
|
||||
String id = str.replaceAll("<:.*:(\\d+)>", "$1");
|
||||
net.dv8tion.jda.api.entities.Emote emote = e.getJDA().getEmoteById(id);
|
||||
RichCustomEmoji emote = e.getJDA().getEmojiById(id);
|
||||
if(emote==null)
|
||||
{
|
||||
e.getChannel().sendMessage("Unknown emote:\n"
|
||||
|
||||
@@ -10,23 +10,24 @@ import java.util.Arrays;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.tools.PlayerLibrary;
|
||||
import fr.Skydust.JdrBot.JdrBot;
|
||||
import fr.Skydust.JdrBot.stock.Command;
|
||||
import fr.Skydust.JdrBot.bases.command.Command;
|
||||
import fr.Skydust.JdrBot.bases.command.CommandSpec;
|
||||
import fr.Skydust.JdrBot.utils.DurationUtils;
|
||||
import fr.Skydust.JdrBot.utils.Utils;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.JDAInfo;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
|
||||
import oshi.SystemInfo;
|
||||
import oshi.hardware.HardwareAbstractionLayer;
|
||||
|
||||
@CommandSpec(
|
||||
name = "status",
|
||||
description = "Donne le status du bot et du serveur"
|
||||
)
|
||||
public class Etat extends Command {
|
||||
private static final DecimalFormat df = new DecimalFormat("###.##");
|
||||
|
||||
public Etat() {
|
||||
SetName("status");
|
||||
SetDesc("Donne le status du bot et du serveur");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(MessageReceivedEvent e) {
|
||||
SystemInfo si = new SystemInfo();
|
||||
@@ -37,7 +38,7 @@ public class Etat extends Command {
|
||||
LocalDateTime currentDate = LocalDateTime.now();
|
||||
Duration difference = Duration.between(JdrBot.basedate, currentDate);
|
||||
|
||||
e.getChannel().sendMessage(new MessageBuilder().setEmbeds(new EmbedBuilder()
|
||||
e.getChannel().sendMessage(new MessageCreateBuilder().setEmbeds(new EmbedBuilder()
|
||||
.setAuthor("Etat de "+ e.getGuild().getSelfMember().getEffectiveName())
|
||||
.addBlankField(false)
|
||||
.addField("CPU","-----", false)
|
||||
@@ -53,7 +54,7 @@ public class Etat extends Command {
|
||||
.addBlankField(false)
|
||||
.addField("Servers",e.getJDA().getGuilds().size()+"",true)
|
||||
.addField("Versions", "JdrBot: "+ JdrBot.Version +" - JDA: "+ JDAInfo.VERSION +" - Lavaplayer: "+ PlayerLibrary.VERSION, true)
|
||||
.addField("Uptime", Utils.formatDuration(difference), true)
|
||||
.addField("Uptime", DurationUtils.formatDuration(difference), true)
|
||||
.setFooter("*Fait le "+ currentDate.format(DateTimeFormatter.ofPattern("dd/MM/yyyy à HH:mm:ss")) +"*", e.getJDA().getSelfUser().getAvatarUrl())
|
||||
.setColor(Color.BLUE)
|
||||
.build()).build()).queue();
|
||||
|
||||
@@ -4,25 +4,25 @@ import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
|
||||
import fr.Skydust.JdrBot.stock.Command;
|
||||
import fr.Skydust.JdrBot.utils.Utils;
|
||||
import fr.Skydust.JdrBot.bases.command.Command;
|
||||
import fr.Skydust.JdrBot.bases.command.CommandSpec;
|
||||
import fr.Skydust.JdrBot.utils.DurationUtils;
|
||||
import net.dv8tion.jda.api.OnlineStatus;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.events.user.update.UserUpdateOnlineStatusEvent;
|
||||
|
||||
@CommandSpec(
|
||||
name = "lasttimeonline|lto",
|
||||
usage = "[Mention]",
|
||||
description = "Dit depuis combien de temps un utilisateur est en ligne/hors-ligne"
|
||||
)
|
||||
public class LastTimeOnline extends Command {
|
||||
static HashMap<Long, LocalDateTime> AllUsers = new HashMap<>();
|
||||
|
||||
public LastTimeOnline() {
|
||||
SetName("lasttimeonline|lto");
|
||||
SetDesc("Dit depuis combien de temps un utilisateur est en ligne/hors-ligne");
|
||||
SetUsage("[Mention]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(MessageReceivedEvent e) {
|
||||
if(e.getMessage().getMentions().getUsers().size() < 1) {
|
||||
if(e.getMessage().getMentions().getUsers().isEmpty()) {
|
||||
e.getChannel().sendMessage("Vous n'avez pas mentionne d'utilisateur !").queue();
|
||||
return;
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public class LastTimeOnline extends Command {
|
||||
} else {
|
||||
sb.append(u.getAsMention()+" est en ligne depuis ");
|
||||
}
|
||||
sb.append(Utils.formatDurationSmooth(Duration.between(UserDate, LocalDateTime.now())));
|
||||
sb.append(DurationUtils.formatDurationSmooth(Duration.between(UserDate, LocalDateTime.now())));
|
||||
|
||||
e.getChannel().sendMessage(sb.toString()).queue();
|
||||
}
|
||||
|
||||
@@ -2,19 +2,19 @@ package fr.Skydust.JdrBot.cmds;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import fr.Skydust.JdrBot.stock.Command;
|
||||
import fr.Skydust.JdrBot.bases.command.Command;
|
||||
import fr.Skydust.JdrBot.bases.command.CommandSpec;
|
||||
import fr.Skydust.JdrBot.utils.Utils;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
@CommandSpec(
|
||||
name = "r|roll",
|
||||
usage = "[NombreDés]d[NombreFaces] OU [NombreFaces]",
|
||||
description = "Lance un dé"
|
||||
)
|
||||
public class Roll extends Command {
|
||||
static Random r = new Random();
|
||||
|
||||
public Roll() {
|
||||
SetName("r|roll");
|
||||
SetDesc("Lance un dé");
|
||||
SetUsage("[NombreDés]d[NombreFaces] OU [NombreFaces]");
|
||||
}
|
||||
|
||||
public void call(MessageReceivedEvent e) {
|
||||
if (e.getMessage().getContentRaw().split(" ").length != 1)
|
||||
{
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
package fr.Skydust.JdrBot.cmds.playmusic;
|
||||
|
||||
import fr.Skydust.JdrBot.stock.Command;
|
||||
import fr.Skydust.JdrBot.utils.MessageType;
|
||||
import fr.Skydust.JdrBot.bases.command.Command;
|
||||
import fr.Skydust.JdrBot.bases.command.CommandSpec;
|
||||
import fr.Skydust.JdrBot.bases.command.HideCommand;
|
||||
import fr.Skydust.JdrBot.enums.MessageType;
|
||||
import fr.Skydust.JdrBot.utils.Utils;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@HideCommand
|
||||
@CommandSpec(
|
||||
name = "fload",
|
||||
description = "/!\\ Commande test /!\\ Permet de charger une musique de force",
|
||||
usage = "[URL/Recherche]"
|
||||
)
|
||||
public class FLoad extends Command {
|
||||
public FLoad() {
|
||||
SetName("fload");
|
||||
SetDesc("/!\\ Commande test /!\\ Permet de charger une musique de force");
|
||||
SetUsage("[URL/Recherche]");
|
||||
Hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(MessageReceivedEvent e) {
|
||||
if(e.getMember().getVoiceState().getChannel() != null) {
|
||||
@@ -24,7 +26,7 @@ public class FLoad extends Command {
|
||||
e.getGuild().getAudioManager().openAudioConnection(e.getMember().getVoiceState().getChannel());
|
||||
//ytsearch:query
|
||||
|
||||
PlayMusic.loadAndPlay(e.getGuild(), e.getChannel(), args, false, false);
|
||||
PlayMusic.loadAndPlay(e.getGuild(), (TextChannel) e.getChannel(), args, false, false);
|
||||
|
||||
Utils.sendMessage(e.getChannel(), MessageType.NORMAL, "Forçage du lancement de "+args);
|
||||
} else {
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
package fr.Skydust.JdrBot.cmds.playmusic;
|
||||
|
||||
import fr.Skydust.JdrBot.stock.Command;
|
||||
import fr.Skydust.JdrBot.utils.MessageType;
|
||||
import fr.Skydust.JdrBot.bases.command.Command;
|
||||
import fr.Skydust.JdrBot.bases.command.CommandSpec;
|
||||
import fr.Skydust.JdrBot.bases.command.HideCommand;
|
||||
import fr.Skydust.JdrBot.enums.MessageType;
|
||||
import fr.Skydust.JdrBot.utils.Utils;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@HideCommand
|
||||
@CommandSpec(
|
||||
name = "floadloop",
|
||||
description = "/!\\ Commande test /!\\ Permet de charger une musique de force",
|
||||
usage = "[URL/Recherche]"
|
||||
)
|
||||
public class FLoadLoop extends Command {
|
||||
public FLoadLoop() {
|
||||
SetName("floadloop");
|
||||
SetDesc("/!\\ Commande test /!\\ Permet de charger une musique de force");
|
||||
SetUsage("[URL/Recherche]");
|
||||
Hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(MessageReceivedEvent e) {
|
||||
if(e.getMember().getVoiceState().getChannel() != null) {
|
||||
@@ -26,7 +28,7 @@ public class FLoadLoop extends Command {
|
||||
if(!args.matches(".*(https?)://.*")) {
|
||||
args = "ytsearch:"+args;
|
||||
}
|
||||
PlayMusic.loadAndPlay(e.getGuild(), e.getChannel(), StringUtils.join(args," "), true, false);
|
||||
PlayMusic.loadAndPlay(e.getGuild(), (TextChannel) e.getChannel(), StringUtils.join(args," "), true, false);
|
||||
} else {
|
||||
Utils.sendMessage(e.getChannel(), MessageType.ERROR, "Vous n'êtes dans un salon vocal");
|
||||
}
|
||||
|
||||
@@ -3,11 +3,12 @@ package fr.Skydust.JdrBot.cmds.playmusic;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import fr.Skydust.JdrBot.bases.command.Command;
|
||||
import fr.Skydust.JdrBot.bases.command.CommandSpec;
|
||||
import fr.Skydust.JdrBot.jukebox.JukeboxSystem;
|
||||
import fr.Skydust.JdrBot.stock.Command;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
|
||||
@@ -20,6 +21,10 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
|
||||
import fr.Skydust.JdrBot.audio.GuildMusicManager;
|
||||
|
||||
@CommandSpec(
|
||||
name = "playmusic|pm",
|
||||
description = "(Admin) Demarre le jukebox"
|
||||
)
|
||||
public class PlayMusic extends Command {
|
||||
private static final AudioPlayerManager playerManager = new DefaultAudioPlayerManager();
|
||||
static Map<Long, GuildMusicManager> musicManagers;
|
||||
@@ -27,12 +32,11 @@ public class PlayMusic extends Command {
|
||||
public static HashMap<Long, JukeboxSystem> jukeboxSystems = new HashMap<>();
|
||||
|
||||
public PlayMusic() {
|
||||
super();
|
||||
|
||||
musicManagers = new HashMap<>();
|
||||
AudioSourceManagers.registerRemoteSources(playerManager);
|
||||
AudioSourceManagers.registerLocalSource(playerManager);
|
||||
|
||||
SetName("playmusic|pm");
|
||||
SetDesc("(Admin) Demarre le jukebox");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,7 +68,7 @@ public class PlayMusic extends Command {
|
||||
return jukeboxSystems.get(guild.getIdLong());
|
||||
}
|
||||
|
||||
public static void loadAndPlay(final Guild guild, final MessageChannel channel, final String trackUrl, boolean loop, boolean nomsg) {
|
||||
public static void loadAndPlay(final Guild guild, final TextChannel channel, final String trackUrl, boolean loop, boolean nomsg) {
|
||||
System.out.println(trackUrl);
|
||||
|
||||
GuildMusicManager musicManager = getGuildAudioPlayer(guild);
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
package fr.Skydust.JdrBot.cmds.playmusic;
|
||||
|
||||
import fr.Skydust.JdrBot.bases.command.Command;
|
||||
import fr.Skydust.JdrBot.bases.command.CommandSpec;
|
||||
import fr.Skydust.JdrBot.cmds.record.Record;
|
||||
import fr.Skydust.JdrBot.jukebox.JukeboxSystem;
|
||||
import fr.Skydust.JdrBot.stock.Command;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
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.GuildVoiceUpdateEvent;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
@CommandSpec(
|
||||
name = "stopmusic|sm",
|
||||
description = "(Admin) Arrete le jukebox et supprime son message"
|
||||
)
|
||||
public class StopMusic extends Command {
|
||||
public StopMusic() {
|
||||
SetName("stopmusic|sm");
|
||||
SetDesc("(Admin) Arrete le jukebox et supprime son message");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(MessageReceivedEvent e) {
|
||||
if(!e.getGuild().getAudioManager().isConnected() || !e.getMember().hasPermission(Permission.ADMINISTRATOR)) {
|
||||
@@ -24,15 +23,12 @@ public class StopMusic extends Command {
|
||||
stopMusic(e.getGuild());
|
||||
}
|
||||
|
||||
public static void onGuildVoiceLeave(GuildVoiceLeaveEvent e) {
|
||||
if(e.getGuild().getAudioManager().isConnected() && e.getChannelLeft().getIdLong() == e.getGuild().getAudioManager().getConnectedChannel().getIdLong() && e.getChannelLeft().getMembers().size() == 1) {
|
||||
stopMusic(e.getGuild());
|
||||
}
|
||||
}
|
||||
|
||||
public static void onGuildVoiceMove(GuildVoiceMoveEvent e) {
|
||||
if(e.getGuild().getAudioManager().isConnected() && e.getChannelLeft().getIdLong() == e.getGuild().getAudioManager().getConnectedChannel().getIdLong() && e.getChannelLeft().getMembers().size() == 1) {
|
||||
stopMusic(e.getGuild());
|
||||
public static void onGuildVoiceUpdate(GuildVoiceUpdateEvent e) {
|
||||
if(e.getChannelLeft() != null) {
|
||||
if (e.getGuild().getAudioManager().isConnected() && e.getChannelLeft().getIdLong() == e.getGuild().getAudioManager().getConnectedChannel().getIdLong() && e.getChannelLeft().getMembers().size() == 1) {
|
||||
stopMusic(e.getGuild());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
package fr.Skydust.JdrBot.cmds.record;
|
||||
|
||||
import fr.Skydust.JdrBot.bases.command.Command;
|
||||
import fr.Skydust.JdrBot.bases.command.CommandSpec;
|
||||
import fr.Skydust.JdrBot.cmds.playmusic.PlayMusic;
|
||||
import fr.Skydust.JdrBot.stock.Command;
|
||||
import fr.Skydust.JdrBot.stock.RecordState;
|
||||
import fr.Skydust.JdrBot.utils.MessageType;
|
||||
import fr.Skydust.JdrBot.enums.MessageType;
|
||||
import fr.Skydust.JdrBot.utils.Utils;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
@CommandSpec(
|
||||
name = "crecord|cr",
|
||||
description = "Annule l'enregistrement"
|
||||
)
|
||||
public class CancelRecord extends Command {
|
||||
public CancelRecord() {
|
||||
SetName("crecord|cr");
|
||||
SetDesc("Annule l'enregistrement");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(MessageReceivedEvent e) {
|
||||
RecordState rs = Record.getGuildRecordState(e.getGuild());
|
||||
|
||||
@@ -4,22 +4,22 @@ import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
import fr.Skydust.JdrBot.audio.handler.JdrBotARH;
|
||||
import fr.Skydust.JdrBot.bases.command.Command;
|
||||
import fr.Skydust.JdrBot.bases.command.CommandSpec;
|
||||
import fr.Skydust.JdrBot.stock.RecordState;
|
||||
import fr.Skydust.JdrBot.stock.Command;
|
||||
import fr.Skydust.JdrBot.utils.MessageType;
|
||||
import fr.Skydust.JdrBot.enums.MessageType;
|
||||
import fr.Skydust.JdrBot.utils.Utils;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
@CommandSpec(
|
||||
name = "record",
|
||||
description = "(Admin) Enregistre le chat vocal"
|
||||
)
|
||||
public class Record extends Command {
|
||||
public static HashMap<Long, RecordState> recordStates = new HashMap<>();
|
||||
|
||||
public Record() {
|
||||
SetName("record");
|
||||
SetDesc("(Admin) Enregistre le chat vocal");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(MessageReceivedEvent e)
|
||||
{
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
package fr.Skydust.JdrBot.cmds.record;
|
||||
|
||||
import fr.Skydust.JdrBot.bases.command.Command;
|
||||
import fr.Skydust.JdrBot.bases.command.CommandSpec;
|
||||
import fr.Skydust.JdrBot.cmds.playmusic.PlayMusic;
|
||||
import fr.Skydust.JdrBot.stock.Command;
|
||||
import fr.Skydust.JdrBot.stock.RecordState;
|
||||
import fr.Skydust.JdrBot.utils.MessageType;
|
||||
import fr.Skydust.JdrBot.enums.MessageType;
|
||||
import fr.Skydust.JdrBot.utils.Utils;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
@CommandSpec(
|
||||
name = "stoprecord|sr",
|
||||
description = "Arrete et archive l'enregistrement"
|
||||
)
|
||||
public class StopRecord extends Command {
|
||||
public StopRecord() {
|
||||
SetName("stoprecord|sr");
|
||||
SetDesc("Arrete l'enregistrement");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(MessageReceivedEvent e) {
|
||||
RecordState rs = Record.getGuildRecordState(e.getGuild());
|
||||
@@ -20,7 +21,7 @@ public class StopRecord extends Command {
|
||||
if(PlayMusic.getGuildsJukebox(e.getGuild()) == null) {
|
||||
e.getGuild().getAudioManager().closeAudioConnection();
|
||||
}
|
||||
rs.endRecord(e.getGuild(), e.getChannel());
|
||||
rs.endRecord(e.getGuild(), (TextChannel) e.getChannel());
|
||||
} else {
|
||||
Utils.sendMessage(e.getChannel(), MessageType.ERROR, "Il n'y a aucun enregistrement en cours");
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.Skydust.JdrBot.utils;
|
||||
package fr.Skydust.JdrBot.enums;
|
||||
|
||||
public enum MessageType {
|
||||
ERROR,
|
||||
@@ -3,9 +3,10 @@ package fr.Skydust.JdrBot.jukebox;
|
||||
import fr.Skydust.JdrBot.cmds.playmusic.PlayMusic;
|
||||
import fr.Skydust.JdrBot.menu.Menu;
|
||||
import fr.Skydust.JdrBot.menu.MenuSystem;
|
||||
import fr.Skydust.JdrBot.utils.Utils;
|
||||
import fr.Skydust.JdrBot.utils.UnicodeEmotes;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
@@ -42,7 +43,7 @@ public class JukeboxSystem {
|
||||
|
||||
// If it isn't the root folder, place the return button
|
||||
if(isntInRootFolder()) {
|
||||
items.add(Utils.ReturnUnicode + " Retour");
|
||||
items.add(UnicodeEmotes.ReturnUnicode + " Retour");
|
||||
}
|
||||
if(files != null) {
|
||||
// Sort files by alphabetical order with directories first
|
||||
@@ -59,9 +60,9 @@ public class JukeboxSystem {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (file.isDirectory())
|
||||
sb.append(Utils.FolderUnicode);
|
||||
sb.append(UnicodeEmotes.FolderUnicode);
|
||||
else
|
||||
sb.append(Utils.SongUnicode);
|
||||
sb.append(UnicodeEmotes.SongUnicode);
|
||||
|
||||
sb.append(" ");
|
||||
sb.append(file.getName().replaceAll(".mp3", ""));
|
||||
@@ -80,7 +81,7 @@ public class JukeboxSystem {
|
||||
String str = items[itemId];
|
||||
|
||||
// Loop back to open a subfolder
|
||||
if (str.contains(Utils.FolderUnicode)) {
|
||||
if (str.contains(UnicodeEmotes.FolderUnicode)) {
|
||||
openFolder(currentFolder + "/" + getFileNameFromItem(str));
|
||||
return;
|
||||
}
|
||||
@@ -95,25 +96,29 @@ public class JukeboxSystem {
|
||||
}
|
||||
|
||||
// If not already playing
|
||||
if (str.contains(Utils.SongUnicode)) {
|
||||
if (str.contains(UnicodeEmotes.SongUnicode)) {
|
||||
if(!songPlayedPath.equals("")) {
|
||||
String folder = songPlayedPath.substring(0, songPlayedPath.lastIndexOf("/"));
|
||||
int previousSongItemID = Integer.parseInt(songPlayedPath.substring(songPlayedPath.lastIndexOf("/")+1));
|
||||
|
||||
Menu previousMenu = linkedPath.get(folder);
|
||||
previousMenu.items[previousSongItemID] = previousMenu.items[previousSongItemID].replace(Utils.PlayUnicode, Utils.SongUnicode);
|
||||
previousMenu.items[previousSongItemID] =
|
||||
previousMenu.items[previousSongItemID].replace(
|
||||
UnicodeEmotes.PlayUnicode,
|
||||
UnicodeEmotes.SongUnicode
|
||||
);
|
||||
}
|
||||
items[itemId] = items[itemId].replace(Utils.SongUnicode, Utils.PlayUnicode);
|
||||
items[itemId] = items[itemId].replace(UnicodeEmotes.SongUnicode, UnicodeEmotes.PlayUnicode);
|
||||
|
||||
String songPath = currentFolder + "/" + getFileNameFromItem(str) + ".mp3";
|
||||
|
||||
PlayMusic.loadAndPlay(msg.getGuild(), msg.getTextChannel(), songPath, true, true);
|
||||
PlayMusic.loadAndPlay(msg.getGuild(), (TextChannel) msg.getChannel(), songPath, true, true);
|
||||
|
||||
// Format: Songs/Folder/SubFolder/2
|
||||
songPlayedPath = currentFolder + "/" + itemId;
|
||||
} else {
|
||||
//If already playing, stop the song
|
||||
items[itemId] = items[itemId].replace(Utils.PlayUnicode, Utils.SongUnicode);
|
||||
items[itemId] = items[itemId].replace(UnicodeEmotes.PlayUnicode, UnicodeEmotes.SongUnicode);
|
||||
PlayMusic.getGuildAudioPlayer(member.getGuild()).scheduler.stop();
|
||||
}
|
||||
// Reload the current menu
|
||||
@@ -125,7 +130,7 @@ public class JukeboxSystem {
|
||||
|
||||
// Reget the message to update it
|
||||
Menu finalMenu = menu;
|
||||
jukeboxMessage.getTextChannel().retrieveMessageById(jukeboxMessage.getIdLong()).queue(msg -> {
|
||||
jukeboxMessage.getChannel().retrieveMessageById(jukeboxMessage.getIdLong()).queue(msg -> {
|
||||
MenuSystem.changeMenu(msg, finalMenu);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package fr.Skydust.JdrBot.menu;
|
||||
|
||||
import fr.Skydust.JdrBot.utils.Utils;
|
||||
import fr.Skydust.JdrBot.utils.UnicodeEmotes;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
|
||||
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
@@ -25,17 +26,17 @@ public class Menu {
|
||||
public void onButtonClicked(Member member, Message msg, int itemId) { }
|
||||
|
||||
/** Builds the menu message */
|
||||
public Message makeMessage() {
|
||||
public MessageCreateData makeMessage() {
|
||||
StringBuilder str = new StringBuilder();
|
||||
|
||||
int i = 0;
|
||||
for (String s : items) {
|
||||
str.append(Utils.CharsUnicodeArray[i] +" "+ s +"\n");
|
||||
str.append(UnicodeEmotes.CharsUnicodeArray[i] +" "+ s +"\n");
|
||||
i++;
|
||||
}
|
||||
|
||||
return new MessageBuilder()
|
||||
.append(name)
|
||||
return new MessageCreateBuilder()
|
||||
.addContent(name)
|
||||
.setEmbeds(
|
||||
new EmbedBuilder()
|
||||
.setThumbnail(thumbnail)
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package fr.Skydust.JdrBot.menu;
|
||||
|
||||
import fr.Skydust.JdrBot.utils.Utils;
|
||||
import fr.Skydust.JdrBot.utils.UnicodeEmotes;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.emoji.Emoji;
|
||||
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
|
||||
import net.dv8tion.jda.api.utils.messages.MessageEditData;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -13,7 +15,7 @@ public class MenuSystem {
|
||||
/** Action Listening */
|
||||
public static void onMessageReactionAdd(MessageReactionAddEvent e) {
|
||||
if (e.getChannel() instanceof TextChannel) {
|
||||
if(e.getUser().isBot())
|
||||
if(e.getUser() != null && e.getUser().isBot())
|
||||
return;
|
||||
|
||||
e.getChannel().retrieveMessageById(e.getMessageId()).queue(msg -> {
|
||||
@@ -26,14 +28,16 @@ public class MenuSystem {
|
||||
|
||||
// Check if the emote is valid and get id
|
||||
int emoteId = 0;
|
||||
for(String s : Utils.CharsUnicodeArray){
|
||||
if(s.equals(e.getReaction().getReactionEmote().getEmoji().replace("(null)","").replace("RE:",""))) {
|
||||
for(String emote : UnicodeEmotes.CharsUnicodeArray){
|
||||
String cleanedUpEmote = UnicodeEmotes.cleanUpDiscordEmote(
|
||||
e.getReaction().getEmoji().getAsReactionCode());
|
||||
if(emote.equals(cleanedUpEmote)) {
|
||||
break;
|
||||
}
|
||||
emoteId++;
|
||||
}
|
||||
// Do not proceed if not valid
|
||||
if(emoteId > Utils.CharsUnicodeArray.length) {
|
||||
if(emoteId > UnicodeEmotes.CharsUnicodeArray.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -50,7 +54,7 @@ public class MenuSystem {
|
||||
System.out.println("Error: No menu on this message");
|
||||
return;
|
||||
}
|
||||
currentMessage.editMessage(newMenu.makeMessage()).queue();
|
||||
currentMessage.editMessage(MessageEditData.fromCreateData(newMenu.makeMessage())).queue();
|
||||
updateReactions(currentMessage, newMenu);
|
||||
}
|
||||
|
||||
@@ -61,7 +65,7 @@ public class MenuSystem {
|
||||
}
|
||||
// Adds missing reactions
|
||||
for (int i = msg.getReactions().size(); i < menu.items.length; i++) {
|
||||
msg.addReaction(Utils.CharsUnicodeArray[i]).queue();
|
||||
msg.addReaction(Emoji.fromUnicode(UnicodeEmotes.CharsUnicodeArray[i])).queue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +77,7 @@ public class MenuSystem {
|
||||
return;
|
||||
}
|
||||
|
||||
currentMessage.editMessage(newMenu.makeMessage()).queue();
|
||||
currentMessage.editMessage(MessageEditData.fromCreateData(newMenu.makeMessage())).queue();
|
||||
updateReactions(currentMessage, newMenu);
|
||||
menuHash.put(currentMessage, newMenu);
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package fr.Skydust.JdrBot.stock;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public abstract class Command {
|
||||
public String cmdName;
|
||||
public String cmdDesc;
|
||||
public String cmdUsage = "";
|
||||
public boolean hidden = false;
|
||||
|
||||
public abstract void call(MessageReceivedEvent e);
|
||||
|
||||
public void Hide() {
|
||||
hidden = true;
|
||||
}
|
||||
|
||||
public void SetName(String name) {
|
||||
this.cmdName = name;
|
||||
}
|
||||
|
||||
public void SetDesc(String desc) {
|
||||
this.cmdDesc = desc;
|
||||
}
|
||||
|
||||
public void SetUsage(String usage) {
|
||||
this.cmdUsage = usage;
|
||||
}
|
||||
}
|
||||
@@ -5,16 +5,15 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import fr.Skydust.JdrBot.utils.MessageType;
|
||||
import fr.Skydust.JdrBot.enums.MessageType;
|
||||
import fr.Skydust.JdrBot.utils.Utils;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import net.dv8tion.jda.api.utils.FileUpload;
|
||||
import net.lingala.zip4j.ZipFile;
|
||||
import net.lingala.zip4j.model.ZipParameters;
|
||||
import net.lingala.zip4j.model.enums.CompressionLevel;
|
||||
import net.lingala.zip4j.model.enums.CompressionMethod;
|
||||
import org.apache.commons.codec.EncoderException;
|
||||
import ws.schild.jave.Encoder;
|
||||
import ws.schild.jave.MultimediaObject;
|
||||
import ws.schild.jave.encode.AudioAttributes;
|
||||
@@ -26,7 +25,6 @@ import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
|
||||
public class RecordState {
|
||||
private static final int RECORDER_SAMPLERATE = 44100;
|
||||
public boolean isRecording;
|
||||
private ByteArrayOutputStream recordData;
|
||||
public boolean isProcessing;
|
||||
@@ -61,7 +59,7 @@ public class RecordState {
|
||||
}
|
||||
}
|
||||
|
||||
public void endRecord(Guild g, MessageChannel tc) {
|
||||
public void endRecord(Guild g, TextChannel tc) {
|
||||
isRecording = false;
|
||||
isProcessing = true;
|
||||
|
||||
@@ -86,7 +84,7 @@ public class RecordState {
|
||||
}).start();
|
||||
}
|
||||
|
||||
public void processRecording(MessageChannel tc) throws IOException, IllegalArgumentException, EncoderException, ws.schild.jave.EncoderException {
|
||||
public void processRecording(TextChannel tc) throws IOException, IllegalArgumentException, ws.schild.jave.EncoderException {
|
||||
//BigEndian, 16 bit signed, 44100hz
|
||||
String OriginalName = new Date().toString().replaceAll(":", "-");
|
||||
|
||||
@@ -130,12 +128,14 @@ public class RecordState {
|
||||
tc.sendMessage("Envoi du fichier audio(Via plusieurs fichiers zip)...").queue();
|
||||
for(Object file : zipFile.getSplitZipFiles()) {
|
||||
File currentFile = new File(file+"");
|
||||
tc.sendFile(currentFile, "").queue(msg -> currentFile.delete());
|
||||
FileUpload fileUpload = FileUpload.fromData(currentFile, currentFile.getName());
|
||||
tc.sendFiles(fileUpload).queue(msg -> currentFile.delete());
|
||||
}
|
||||
} else {
|
||||
tc.sendMessage("Envoi du fichier audio(Via un fichier zip)...").queue();
|
||||
File currentFile = new File(zipFile.getSplitZipFiles().get(0)+"");
|
||||
tc.sendFile(currentFile, currentFile.getName()).queue(msg -> currentFile.delete());
|
||||
FileUpload fileUpload = FileUpload.fromData(currentFile, currentFile.getName());
|
||||
tc.sendFiles(fileUpload).queue(msg -> currentFile.delete());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.Skydust.JdrBot.utils;
|
||||
package fr.Skydust.JdrBot.tasks;
|
||||
|
||||
import fr.Skydust.JdrBot.JdrBot;
|
||||
import net.dv8tion.jda.api.events.GatewayPingEvent;
|
||||
30
src/main/java/fr/Skydust/JdrBot/utils/DurationUtils.java
Normal file
30
src/main/java/fr/Skydust/JdrBot/utils/DurationUtils.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package fr.Skydust.JdrBot.utils;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
public class DurationUtils {
|
||||
|
||||
public static String formatDuration(Duration duration) {
|
||||
long seconds = duration.getSeconds();
|
||||
long absSeconds = Math.abs(seconds);
|
||||
String positive = String.format(
|
||||
"%d:%02d:%02d",
|
||||
absSeconds / 3600,
|
||||
(absSeconds % 3600) / 60,
|
||||
absSeconds % 60);
|
||||
return seconds < 0 ? "-" + positive : positive;
|
||||
}
|
||||
|
||||
public static String formatDurationSmooth(Duration duration) {
|
||||
long absSeconds = Math.abs(duration.getSeconds());
|
||||
|
||||
if((absSeconds/3600) == 0) {//Hours
|
||||
if(((absSeconds%3600)/60) == 0)
|
||||
{//Minutes
|
||||
return String.format("%d secondes", absSeconds % 60);
|
||||
}
|
||||
return String.format("%d minutes", (absSeconds % 3600) / 60);
|
||||
}
|
||||
return String.format("%d heures", (absSeconds /3600));
|
||||
}
|
||||
}
|
||||
19
src/main/java/fr/Skydust/JdrBot/utils/UnicodeEmotes.java
Normal file
19
src/main/java/fr/Skydust/JdrBot/utils/UnicodeEmotes.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package fr.Skydust.JdrBot.utils;
|
||||
|
||||
public class UnicodeEmotes {
|
||||
/*0to10*/
|
||||
public static final String[] CharsUnicodeArray = {"\u0030\u20E3","\u0031\u20E3","\u0032\u20E3","\u0033\u20E3","\u0034\u20E3","\u0035\u20E3","\u0036\u20E3","\u0037\u20E3","\u0038\u20E3","\u0039\u20E3","\uD83D\uDD1F",
|
||||
/*Alphabet*/ "\uD83C\uDDE6","\uD83C\uDDE7","\uD83C\uDDE8","\uD83C\uDDE9","\uD83C\uDDEA","\uD83C\uDDEB","\uD83C\uDDEC","\uD83C\uDDED","\uD83C\uDDEE","\uD83C\uDDEF","\uD83C\uDDF0","\uD83C\uDDF1","\uD83C\uDDF2","\uD83C\uDDF3","\uD83C\uDDF4","\uD83C\uDDF5","\uD83C\uDDF6","\uD83C\uDDF7","\uD83C\uDDF8","\uD83C\uDDF9","\uD83C\uDDFA","\uD83C\uDDFB","\uD83C\uDDFC","\uD83C\uDDFD","\uD83C\uDDFE","\uD83C\uDDFF"};
|
||||
|
||||
public static final String PlayUnicode = "\uD83D\uDD09";
|
||||
public static final String SongUnicode = "\uD83C\uDFB5";
|
||||
public static final String FolderUnicode = "\uD83D\uDCC1";
|
||||
public static final String ReturnUnicode = "\uD83D\uDCC2";
|
||||
|
||||
public static final String ProgressBarForeground = "\uD83D\uDFE9";
|
||||
public static final String ProgressBarBackground = "\u2B1C";
|
||||
|
||||
public static String cleanUpDiscordEmote(String discordReactionString) {
|
||||
return discordReactionString.replace("(null)","").replace("RE:","");
|
||||
}
|
||||
}
|
||||
@@ -1,59 +1,35 @@
|
||||
package fr.Skydust.JdrBot.utils;
|
||||
|
||||
import fr.Skydust.JdrBot.JdrBot;
|
||||
import fr.Skydust.JdrBot.enums.MessageType;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
|
||||
|
||||
import java.awt.*;
|
||||
import java.time.Duration;
|
||||
|
||||
public class Utils {
|
||||
/*0to10*/
|
||||
public static final String[] CharsUnicodeArray = {"\u0030\u20E3","\u0031\u20E3","\u0032\u20E3","\u0033\u20E3","\u0034\u20E3","\u0035\u20E3","\u0036\u20E3","\u0037\u20E3","\u0038\u20E3","\u0039\u20E3","\uD83D\uDD1F",
|
||||
/*Alphabet*/ "\uD83C\uDDE6","\uD83C\uDDE7","\uD83C\uDDE8","\uD83C\uDDE9","\uD83C\uDDEA","\uD83C\uDDEB","\uD83C\uDDEC","\uD83C\uDDED","\uD83C\uDDEE","\uD83C\uDDEF","\uD83C\uDDF0","\uD83C\uDDF1","\uD83C\uDDF2","\uD83C\uDDF3","\uD83C\uDDF4","\uD83C\uDDF5","\uD83C\uDDF6","\uD83C\uDDF7","\uD83C\uDDF8","\uD83C\uDDF9","\uD83C\uDDFA","\uD83C\uDDFB","\uD83C\uDDFC","\uD83C\uDDFD","\uD83C\uDDFE","\uD83C\uDDFF"};
|
||||
|
||||
public static final String PlayUnicode = "\uD83D\uDD09";
|
||||
public static final String SongUnicode = "\uD83C\uDFB5";
|
||||
public static final String FolderUnicode = "\uD83D\uDCC1";
|
||||
public static final String ReturnUnicode = "\uD83D\uDCC2";
|
||||
|
||||
public static final String ProgressBarForeground = "\uD83D\uDFE9";
|
||||
public static final String ProgressBarBackground = "\u2B1C";
|
||||
|
||||
public static boolean IsInt(String info) {
|
||||
/**
|
||||
* Simple function to check if a string is parseable as an integer.
|
||||
* @param str The string to try to parse.
|
||||
* @return True is the string is parseable, false otherwise.
|
||||
*/
|
||||
public static boolean IsInt(String str) {
|
||||
try {
|
||||
Integer.parseInt(info);
|
||||
Integer.parseInt(str);
|
||||
return true;
|
||||
} catch(Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static String formatDuration(Duration duration) {
|
||||
long seconds = duration.getSeconds();
|
||||
long absSeconds = Math.abs(seconds);
|
||||
String positive = String.format(
|
||||
"%d:%02d:%02d",
|
||||
absSeconds / 3600,
|
||||
(absSeconds % 3600) / 60,
|
||||
absSeconds % 60);
|
||||
return seconds < 0 ? "-" + positive : positive;
|
||||
}
|
||||
|
||||
public static String formatDurationSmooth(Duration duration) {
|
||||
long absSeconds = Math.abs(duration.getSeconds());
|
||||
|
||||
if((absSeconds/3600) == 0) {//Hours
|
||||
if(((absSeconds%3600)/60) == 0)
|
||||
{//Minutes
|
||||
return String.format("%d secondes", absSeconds % 60);
|
||||
}
|
||||
return String.format("%d minutes", (absSeconds % 3600) / 60);
|
||||
}
|
||||
return String.format("%d heures", (absSeconds /3600));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* An utility function to send a message into a discord channel.
|
||||
* @param channel The channel to send the message to.
|
||||
* @param msgType The type of message to send.
|
||||
* @param message The message.
|
||||
*/
|
||||
public static void sendMessage(MessageChannel channel, MessageType msgType, String message) {
|
||||
Color c = Color.GREEN;
|
||||
String title = "Message";
|
||||
@@ -63,7 +39,7 @@ public class Utils {
|
||||
title = "Erreur";
|
||||
}
|
||||
|
||||
channel.sendMessage(new MessageBuilder().setEmbeds(new EmbedBuilder().
|
||||
channel.sendMessage(new MessageCreateBuilder().setEmbeds(new EmbedBuilder().
|
||||
setDescription(message)
|
||||
.setTitle(title, null)
|
||||
.setFooter("", JdrBot.jda.getSelfUser().getAvatarUrl())
|
||||
|
||||
Reference in New Issue
Block a user