|
1 | | -package me.TechsCode.TechDiscordBot.module.cmds; |
2 | | - |
3 | | -import me.TechsCode.TechDiscordBot.TechDiscordBot; |
4 | | -import me.TechsCode.TechDiscordBot.github.GitHubUtil; |
5 | | -import me.TechsCode.TechDiscordBot.github.GithubRelease; |
6 | | -import me.TechsCode.TechDiscordBot.module.CommandModule; |
7 | | -import me.TechsCode.TechDiscordBot.objects.DefinedQuery; |
8 | | -import me.TechsCode.TechDiscordBot.objects.Query; |
9 | | -import me.TechsCode.TechDiscordBot.util.TechEmbedBuilder; |
10 | | -import net.dv8tion.jda.api.entities.Category; |
11 | | -import net.dv8tion.jda.api.entities.Member; |
12 | | -import net.dv8tion.jda.api.entities.Role; |
13 | | -import net.dv8tion.jda.api.entities.TextChannel; |
14 | | -import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; |
15 | | -import net.dv8tion.jda.api.interactions.commands.Command; |
16 | | -import net.dv8tion.jda.api.interactions.commands.OptionType; |
17 | | -import net.dv8tion.jda.api.interactions.commands.build.OptionData; |
18 | | -import net.dv8tion.jda.api.interactions.commands.privileges.CommandPrivilege; |
19 | | - |
20 | | -import java.util.stream.Collectors; |
21 | | - |
22 | | -public class GetReleaseCommand extends CommandModule { |
23 | | - |
24 | | - private final DefinedQuery<Role> SUPPORT_ROLES = new DefinedQuery<Role>() { |
25 | | - @Override |
26 | | - protected Query<Role> newQuery() { return bot.getRoles("Supporter", "Senior Supporter", "Assistant", "Developer", "\uD83D\uDCBB Coding Wizard"); } |
27 | | - }; |
28 | | - |
29 | | - private final DefinedQuery<Category> SUPPORT_CATEGORIES = new DefinedQuery<Category>() { |
30 | | - @Override |
31 | | - protected Query<Category> newQuery() { return bot.getCategories("🎫 ︱Tickets", "📦︱Paid Plugin Support", "📦︱Free Plugin Support", "staff discussions"); } |
32 | | - }; |
33 | | - |
34 | | - public GetReleaseCommand(TechDiscordBot bot) { |
35 | | - super(bot); |
36 | | - } |
37 | | - |
38 | | - @Override |
39 | | - public String getName() { |
40 | | - return "release"; |
41 | | - } |
42 | | - |
43 | | - @Override |
44 | | - public String getDescription() { |
45 | | - return "Get a plugin's latest GitHub jar file."; |
46 | | - } |
47 | | - |
48 | | - @Override |
49 | | - public CommandPrivilege[] getCommandPrivileges() { |
50 | | - return SUPPORT_ROLES.query().stream().map(CommandPrivilege::enable).toArray(CommandPrivilege[]::new); |
51 | | - } |
52 | | - |
53 | | - @Override |
54 | | - public OptionData[] getOptions() { |
55 | | - if(TechDiscordBot.getSpigotStatus().isUsable()){ |
56 | | - return new OptionData[] { |
57 | | - new OptionData(OptionType.STRING, "plugin", "The plugin name.", true) |
58 | | - .addChoices(TechDiscordBot.getSpigotAPI().getSpigotResources().stream().map(r -> new Command.Choice(r.getName().replace(" ", ""), r.getName().replace(" ", ""))).collect(Collectors.toList())) |
59 | | - }; |
60 | | - }else{ |
61 | | - return new OptionData[] { |
62 | | - new OptionData(OptionType.STRING, "plugin", "The plugin name.", true) |
63 | | - .addChoice("Error getting plugins", "error") |
64 | | - }; |
65 | | - } |
66 | | - } |
67 | | - |
68 | | - @Override |
69 | | - public int getCooldown() { |
70 | | - return 4; |
71 | | - } |
72 | | - |
73 | | - @Override |
74 | | - public void onCommand(TextChannel channel, Member m, SlashCommandEvent e) { |
75 | | - String plugin = e.getOption("plugin").getAsString(); |
76 | | - if(plugin.equals("error")) |
77 | | - return; |
78 | | - |
79 | | - if (SUPPORT_CATEGORIES.query().stream().anyMatch(c -> c.getId().equals(channel.getParent().getId()))) { |
80 | | - e.reply("Getting release... please wait.").queue(q -> { |
81 | | - GithubRelease release = GitHubUtil.getLatestRelease(plugin); |
82 | | - |
83 | | - if (release == null) { |
84 | | - 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(); |
85 | | - } else if (release.getFile() != null) { |
86 | | - q.editOriginal(release.getFile(), plugin + ".jar") |
87 | | - .queue(msg2 -> release.getFile().delete()); |
88 | | - q.editOriginalEmbeds( |
89 | | - new TechEmbedBuilder(release.getRelease().getName()) |
90 | | - .text("```" + (release.getRelease().getBody().isEmpty() ? "No changes specified." : release.getRelease().getBody().replaceAll(" \\|\\| ", "\n")) + "```") |
91 | | - .build() |
92 | | - ).queue(); |
93 | | - } else { |
94 | | - 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(); |
95 | | - } |
96 | | - }); |
97 | | - } else { |
98 | | - StringBuilder channels = new StringBuilder(); |
99 | | - SUPPORT_CATEGORIES.query().forEach(c -> channels.append("\n - ").append(c.getAsMention())); |
100 | | - |
101 | | - e.replyEmbeds( |
102 | | - new TechEmbedBuilder("Get Release - Error") |
103 | | - .text("You can not use this command in this channel's category.\n\n**Available Categories:**" + channels) |
104 | | - .error() |
105 | | - .build() |
106 | | - ).setEphemeral(true).queue(); |
107 | | - } |
108 | | - } |
109 | | -} |
| 1 | +//package me.TechsCode.TechDiscordBot.module.cmds; |
| 2 | +// |
| 3 | +//import me.TechsCode.TechDiscordBot.TechDiscordBot; |
| 4 | +//import me.TechsCode.TechDiscordBot.github.GitHubUtil; |
| 5 | +//import me.TechsCode.TechDiscordBot.github.GithubRelease; |
| 6 | +//import me.TechsCode.TechDiscordBot.module.CommandModule; |
| 7 | +//import me.TechsCode.TechDiscordBot.objects.DefinedQuery; |
| 8 | +//import me.TechsCode.TechDiscordBot.objects.Query; |
| 9 | +//import me.TechsCode.TechDiscordBot.util.TechEmbedBuilder; |
| 10 | +//import net.dv8tion.jda.api.entities.Category; |
| 11 | +//import net.dv8tion.jda.api.entities.Member; |
| 12 | +//import net.dv8tion.jda.api.entities.Role; |
| 13 | +//import net.dv8tion.jda.api.entities.TextChannel; |
| 14 | +//import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; |
| 15 | +//import net.dv8tion.jda.api.interactions.commands.Command; |
| 16 | +//import net.dv8tion.jda.api.interactions.commands.OptionType; |
| 17 | +//import net.dv8tion.jda.api.interactions.commands.build.OptionData; |
| 18 | +//import net.dv8tion.jda.api.interactions.commands.privileges.CommandPrivilege; |
| 19 | +// |
| 20 | +//import java.util.stream.Collectors; |
| 21 | +// |
| 22 | +//public class GetReleaseCommand extends CommandModule { |
| 23 | +// |
| 24 | +// private final DefinedQuery<Role> SUPPORT_ROLES = new DefinedQuery<Role>() { |
| 25 | +// @Override |
| 26 | +// protected Query<Role> newQuery() { return bot.getRoles("Supporter", "Senior Supporter", "Assistant", "Developer", "\uD83D\uDCBB Coding Wizard"); } |
| 27 | +// }; |
| 28 | +// |
| 29 | +// private final DefinedQuery<Category> SUPPORT_CATEGORIES = new DefinedQuery<Category>() { |
| 30 | +// @Override |
| 31 | +// protected Query<Category> newQuery() { return bot.getCategories("🎫 ︱Tickets", "📦︱Paid Plugin Support", "📦︱Free Plugin Support", "staff discussions"); } |
| 32 | +// }; |
| 33 | +// |
| 34 | +// public GetReleaseCommand(TechDiscordBot bot) { |
| 35 | +// super(bot); |
| 36 | +// } |
| 37 | +// |
| 38 | +// @Override |
| 39 | +// public String getName() { |
| 40 | +// return "release"; |
| 41 | +// } |
| 42 | +// |
| 43 | +// @Override |
| 44 | +// public String getDescription() { |
| 45 | +// return "Get a plugin's latest GitHub jar file."; |
| 46 | +// } |
| 47 | +// |
| 48 | +// @Override |
| 49 | +// public CommandPrivilege[] getCommandPrivileges() { |
| 50 | +// return SUPPORT_ROLES.query().stream().map(CommandPrivilege::enable).toArray(CommandPrivilege[]::new); |
| 51 | +// } |
| 52 | +// |
| 53 | +// @Override |
| 54 | +// public OptionData[] getOptions() { |
| 55 | +// if(TechDiscordBot.getSpigotStatus().isUsable()){ |
| 56 | +// return new OptionData[] { |
| 57 | +// new OptionData(OptionType.STRING, "plugin", "The plugin name.", true) |
| 58 | +// .addChoices(TechDiscordBot.getSpigotAPI().getSpigotResources().stream().map(r -> new Command.Choice(r.getName().replace(" ", ""), r.getName().replace(" ", ""))).collect(Collectors.toList())) |
| 59 | +// }; |
| 60 | +// }else{ |
| 61 | +// return new OptionData[] { |
| 62 | +// new OptionData(OptionType.STRING, "plugin", "The plugin name.", true) |
| 63 | +// .addChoice("Error getting plugins", "error") |
| 64 | +// }; |
| 65 | +// } |
| 66 | +// } |
| 67 | +// |
| 68 | +// @Override |
| 69 | +// public int getCooldown() { |
| 70 | +// return 4; |
| 71 | +// } |
| 72 | +// |
| 73 | +// @Override |
| 74 | +// public void onCommand(TextChannel channel, Member m, SlashCommandEvent e) { |
| 75 | +// String plugin = e.getOption("plugin").getAsString(); |
| 76 | +// if(plugin.equals("error")) |
| 77 | +// return; |
| 78 | +// |
| 79 | +// if (SUPPORT_CATEGORIES.query().stream().anyMatch(c -> c.getId().equals(channel.getParent().getId()))) { |
| 80 | +// e.reply("Getting release... please wait.").queue(q -> { |
| 81 | +// GithubRelease release = GitHubUtil.getLatestRelease(plugin); |
| 82 | +// |
| 83 | +// if (release == null) { |
| 84 | +// 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(); |
| 85 | +// } else if (release.getFile() != null) { |
| 86 | +// q.editOriginal(release.getFile(), plugin + ".jar") |
| 87 | +// .queue(msg2 -> release.getFile().delete()); |
| 88 | +// q.editOriginalEmbeds( |
| 89 | +// new TechEmbedBuilder(release.getRelease().getName()) |
| 90 | +// .text("```" + (release.getRelease().getBody().isEmpty() ? "No changes specified." : release.getRelease().getBody().replaceAll(" \\|\\| ", "\n")) + "```") |
| 91 | +// .build() |
| 92 | +// ).queue(); |
| 93 | +// } else { |
| 94 | +// 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(); |
| 95 | +// } |
| 96 | +// }); |
| 97 | +// } else { |
| 98 | +// StringBuilder channels = new StringBuilder(); |
| 99 | +// SUPPORT_CATEGORIES.query().forEach(c -> channels.append("\n - ").append(c.getAsMention())); |
| 100 | +// |
| 101 | +// e.replyEmbeds( |
| 102 | +// new TechEmbedBuilder("Get Release - Error") |
| 103 | +// .text("You can not use this command in this channel's category.\n\n**Available Categories:**" + channels) |
| 104 | +// .error() |
| 105 | +// .build() |
| 106 | +// ).setEphemeral(true).queue(); |
| 107 | +// } |
| 108 | +// } |
| 109 | +//} |
0 commit comments