Migrate invite to slash command

This commit is contained in:
SebClem 2022-05-15 19:06:55 +02:00
parent 872dde7695
commit d9d5e5d880
Signed by: sebclem
GPG Key ID: 5A4308F6A359EA50
5 changed files with 45 additions and 110 deletions

View File

@ -1,65 +0,0 @@
package net.Broken.Commands;
import net.Broken.Commande;
import net.Broken.Tools.EmbedMessageUtils;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* Command to flush X last message on channel.
*/
public class Flush implements Commande {
Logger logger = LogManager.getLogger();
@Override
public void action(String[] args, MessageReceivedEvent event) {
if (args.length < 1) {
event.getTextChannel().sendMessage(EmbedMessageUtils.getFlushError("Missing argument!")).queue();
} else {
if (event.getMember().hasPermission(Permission.ADMINISTRATOR)) {
try {
int limit = Integer.parseInt(args[0]) + 1;
MessageChannel chanel = event.getChannel();
chanel.getIterableHistory().takeAsync(limit).thenAccept(chanel::purgeMessages);
} catch (NumberFormatException e) {
event.getTextChannel().sendMessage(EmbedMessageUtils.getFlushError("Argument unknown!")).queue();
}
} else {
event.getTextChannel().sendMessage(EmbedMessageUtils.getFlushError("You are not a supreme being, you cannot do that !")).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;
}
}

View File

@ -1,41 +0,0 @@
package net.Broken.Commands;
import net.Broken.Commande;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import org.apache.logging.log4j.LogManager;
public class Invite implements Commande {
@Override
public void action(String[] args, MessageReceivedEvent event) {
// if (event.getChannelType().isGuild()) {
// event.getTextChannel().sendMessage("You can invite me whit this link:\nhttps://discordapp.com/oauth2/authorize?client_id=" + event.getJDA().getSelfUser().getId() + "&scope=bot&permissions=8").complete();
// } else {
// PrivateMessage.send(event.getAuthor(), "You can invite me whit this link:\nhttps://discordapp.com/oauth2/authorize?client_id=" + event.getJDA().getSelfUser().getId() + "&scope=bot&permissions=8", LogManager.getLogger());
// }
}
@Override
public boolean isPrivateUsable() {
return true;
}
@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;
}
}

View 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;
}
}

View File

@ -44,7 +44,7 @@ public class Music implements SlashCommand {
} }
} else { } else {
Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicError("You are not in a voice channel !")).build(); Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicError("You are not in a voice channel !")).build();
event.getHook().sendMessage(message).queue(); event.getHook().setEphemeral(true).sendMessage(message).queue();
} }
break; break;
case "add": case "add":

View File

@ -104,7 +104,7 @@ public class AudioM {
public void noMatches() { public void noMatches() {
logger.warn("[" + guild + "] Cant find media!"); logger.warn("[" + guild + "] Cant find media!");
Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicError("Video not found !")).build(); Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicError("Video not found !")).build();
event.getHook().sendMessage(message).queue(); event.getHook().setEphemeral(true).sendMessage(message).queue();
} }
@Override @Override
@ -112,7 +112,7 @@ public class AudioM {
logger.error("[" + guild + "] Can't load media!"); logger.error("[" + guild + "] Can't load media!");
logger.error(exception.getMessage()); logger.error(exception.getMessage());
Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicError("Playback error !")).build(); Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicError("Playback error !")).build();
event.getHook().sendMessage(message).queue(); event.getHook().setEphemeral(true).sendMessage(message).queue();
} }
}); });
} }
@ -293,7 +293,7 @@ public class AudioM {
loadAndPlay(event, playedChanel, url, playListLimit, onHead); loadAndPlay(event, playedChanel, url, playListLimit, onHead);
} else { } else {
Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicError("Not connected to vocal chanel !")).build(); Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicError("Not connected to vocal chanel !")).build();
event.getHook().sendMessage(message).queue(); event.getHook().setEphemeral(true).sendMessage(message).queue();
} }
} }