Search in sources :

Example 1 with GithubRelease

use of me.TechsCode.TechDiscordBot.github.GithubRelease in project TechDiscordBot by TechsCode-Team.

the class PluginLabModule method detectRelease.

public void detectRelease() {
    plugins.forEach((name, channel) -> {
        String plugin = name.replace(" ", "");
        GithubRelease release = GitHubUtil.getLatestRelease(plugin);
        if (release != null) {
            try {
                Date date = release.getRelease().getCreatedAt();
                if (lastUpload.containsKey(plugin)) {
                    long lastTime = lastUpload.get(plugin);
                    if (lastTime != date.getTime()) {
                        lastUpload.put(plugin, date.getTime());
                        uploadFile(channel, release, plugin);
                    }
                } else {
                    lastUpload.put(plugin, date.getTime());
                }
            } catch (IOException ex) {
                TechDiscordBot.log("Could not get the last release date from the " + plugin + " repo!");
            }
        } else {
            TechDiscordBot.log("Could not get info from the " + plugin + " repo!");
        }
    });
}
Also used : GithubRelease(me.TechsCode.TechDiscordBot.github.GithubRelease) IOException(java.io.IOException)

Example 2 with GithubRelease

use of me.TechsCode.TechDiscordBot.github.GithubRelease 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();
    }
}
Also used : OptionType(net.dv8tion.jda.api.interactions.commands.OptionType) TechEmbedBuilder(me.TechsCode.TechDiscordBot.util.TechEmbedBuilder) TechDiscordBot(me.TechsCode.TechDiscordBot.TechDiscordBot) Category(net.dv8tion.jda.api.entities.Category) OptionData(net.dv8tion.jda.api.interactions.commands.build.OptionData) Member(net.dv8tion.jda.api.entities.Member) TextChannel(net.dv8tion.jda.api.entities.TextChannel) Command(net.dv8tion.jda.api.interactions.commands.Command) Collectors(java.util.stream.Collectors) SlashCommandEvent(net.dv8tion.jda.api.events.interaction.SlashCommandEvent) CommandModule(me.TechsCode.TechDiscordBot.module.CommandModule) GitHubUtil(me.TechsCode.TechDiscordBot.github.GitHubUtil) Role(net.dv8tion.jda.api.entities.Role) GithubRelease(me.TechsCode.TechDiscordBot.github.GithubRelease) CommandPrivilege(net.dv8tion.jda.api.interactions.commands.privileges.CommandPrivilege) DefinedQuery(me.TechsCode.TechDiscordBot.objects.DefinedQuery) Query(me.TechsCode.TechDiscordBot.objects.Query) TechEmbedBuilder(me.TechsCode.TechDiscordBot.util.TechEmbedBuilder) GithubRelease(me.TechsCode.TechDiscordBot.github.GithubRelease)

Aggregations

GithubRelease (me.TechsCode.TechDiscordBot.github.GithubRelease)2 IOException (java.io.IOException)1 Collectors (java.util.stream.Collectors)1 TechDiscordBot (me.TechsCode.TechDiscordBot.TechDiscordBot)1 GitHubUtil (me.TechsCode.TechDiscordBot.github.GitHubUtil)1 CommandModule (me.TechsCode.TechDiscordBot.module.CommandModule)1 DefinedQuery (me.TechsCode.TechDiscordBot.objects.DefinedQuery)1 Query (me.TechsCode.TechDiscordBot.objects.Query)1 TechEmbedBuilder (me.TechsCode.TechDiscordBot.util.TechEmbedBuilder)1 Category (net.dv8tion.jda.api.entities.Category)1 Member (net.dv8tion.jda.api.entities.Member)1 Role (net.dv8tion.jda.api.entities.Role)1 TextChannel (net.dv8tion.jda.api.entities.TextChannel)1 SlashCommandEvent (net.dv8tion.jda.api.events.interaction.SlashCommandEvent)1 Command (net.dv8tion.jda.api.interactions.commands.Command)1 OptionType (net.dv8tion.jda.api.interactions.commands.OptionType)1 OptionData (net.dv8tion.jda.api.interactions.commands.build.OptionData)1 CommandPrivilege (net.dv8tion.jda.api.interactions.commands.privileges.CommandPrivilege)1