use of net.dv8tion.jda.api.interactions.commands.Command in project TechDiscordBot by TechsCode-Team.
the class GetReleaseCommand method onCommand.
@Override
public void onCommand(TextChannel channel, Member m, SlashCommandEvent e) {
String plugin = e.getOption("plugin").getAsString();
if (plugin.equals("error"))
return;
if (SUPPORT_CATEGORIES.query().stream().anyMatch(c -> c.getId().equals(channel.getParent().getId()))) {
e.reply("Getting release... please wait.").queue(q -> {
GithubRelease release = GitHubUtil.getLatestRelease(plugin);
if (release == null) {
q.editOriginal("**Failed!** Could not get the release!\n\n**Possible reasons:**\n- The repo isn't valid.\n- There is no release in the repo.\n- Github is down.").queue();
} else if (release.getFile() != null) {
q.editOriginal(release.getFile(), plugin + ".jar").queue(msg2 -> release.getFile().delete());
q.editOriginalEmbeds(new TechEmbedBuilder(release.getRelease().getName()).text("```" + (release.getRelease().getBody().isEmpty() ? "No changes specified." : release.getRelease().getBody().replaceAll(" \\|\\| ", "\n")) + "```").build()).queue();
} else {
q.editOriginal("**Failed!** Could not get the file!\n\n**Possible reasons:**\n- The developer messed up.\n- The release has no files for some reason.\n- GitHub is down.").queue();
}
});
} else {
StringBuilder channels = new StringBuilder();
SUPPORT_CATEGORIES.query().forEach(c -> channels.append("\n - ").append(c.getAsMention()));
e.replyEmbeds(new TechEmbedBuilder("Get Release - Error").text("You can not use this command in this channel's category.\n\n**Available Categories:**" + channels).error().build()).setEphemeral(true).queue();
}
}
use of net.dv8tion.jda.api.interactions.commands.Command in project SqueethDiscordBot by AlphaSerpentis.
the class CommandsHandler method checkAndSetSlashCommands.
public static void checkAndSetSlashCommands() {
JDA api = Launcher.api;
List<Command> listOfActiveCommands = api.retrieveCommands().complete();
List<String> detectedCommandNames = new ArrayList<>();
// Checks for the detected commands
for (Iterator<Command> it = listOfActiveCommands.iterator(); it.hasNext(); ) {
Command cmd = it.next();
if (mappingOfCommands.containsKey(cmd.getName())) {
mappingOfCommands.get(cmd.getName()).setCommandId(cmd.getIdLong());
detectedCommandNames.add(cmd.getName());
it.remove();
}
}
// Fills in any gaps or removes any commands
for (Command cmd : listOfActiveCommands) {
// Removes unused commands
System.out.println("[CommandsHandler] Removing slash command: " + cmd.getName());
api.deleteCommandById(cmd.getId()).complete();
}
if (detectedCommandNames.size() < mappingOfCommands.size()) {
// Adds new commands
List<String> missingCommands = new ArrayList<>(mappingOfCommands.keySet());
missingCommands.removeAll(detectedCommandNames);
for (String cmdName : missingCommands) {
System.out.println("[CommandsHandler] Adding new slash command: " + cmdName);
Command cmd = api.upsertCommand(cmdName, mappingOfCommands.get(cmdName).getDescription()).complete();
mappingOfCommands.get(cmdName).setCommandId(cmd.getIdLong());
}
}
}
Aggregations