Search in sources :

Example 1 with Command

use of de.tectoast.emolga.commands.Command in project Emolga by TecToast.

the class EmolgaMain method start.

public static void start() throws Exception {
    emolgajda = JDABuilder.createDefault(Command.tokens.getString("discord")).enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_PRESENCES).addEventListeners(new EmolgaListener(), messageWaiter).setMemberCachePolicy(MemberCachePolicy.ALL).build();
    emolgajda.addEventListener(new SlashListener(emolgajda));
    flegmonjda = JDABuilder.createDefault(Command.tokens.getString("discordflegmon")).enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_PRESENCES).addEventListeners(new EmolgaListener(), messageWaiter).setMemberCachePolicy(MemberCachePolicy.ALL).build();
    flegmonjda.addEventListener(new SlashListener(emolgajda));
    emolgajda.awaitReady();
    flegmonjda.awaitReady();
    setupJetty();
    Guild g = emolgajda.getGuildById(MYSERVER);
    g.updateCommands().addCommands(commands.values().stream().filter(Command::isSlash).map(c -> {
        CommandData dt = new CommandData(c.getName(), c.getHelp());
        List<ArgumentManagerTemplate.Argument> args = c.getArgumentTemplate().arguments;
        for (ArgumentManagerTemplate.Argument arg : args) {
            dt.addOption(arg.getType().asOptionType(), arg.getName().toLowerCase(), arg.getHelp(), !arg.isOptional());
        }
        return dt;
    }).toArray(CommandData[]::new)).queue();
    awaitNextDay();
    flegmonjda.getPresence().setActivity(Activity.playing("mit seiner Rute"));
    updatePresence();
    ReactionManager manager = new ReactionManager(emolgajda);
    manager.registerReaction("715249205186265178", "813025531779743774", "813025179114405898", "719928482544484352").registerReaction("715249205186265178", "813025531779743774", "813025403098628097", "813005659619590184").registerReaction("715249205186265178", "813025531779743774", "813025709232488480", "813027599743713320").registerReaction("540899923789611018", "820784528888561715", "820781668586618901", "820783085976420372").registerReaction("830146866812420116", "830391184459300915", "540969934457667613", "830392346348355594").registerReaction("827608009571958806", "884567614918111233", "884564674744561684", "884565654227812364").registerReaction("827608009571958806", "884567614918111233", "884564533295869962", "884565697479458826").registerReaction("827608009571958806", "884567614918111233", "884565288564195348", "884565609663320086").registerReaction("827608009571958806", "884567614918111233", "886748333484441650", "886746672120606771").registerReaction("827608009571958806", "884567614918111233", "886748333484441650", "886746672120606771").registerReaction("827608009571958806", "884567614918111233", "921389285188440115", "921387730200584222");
    ScheduledExecutorService giveawayscheduler = new ScheduledThreadPoolExecutor(5);
    HashMap<Long, ScheduledFuture<?>> giveawayFutures = new HashMap<>();
    DBManagers.GIVEAWAY.forAll(r -> new Giveaway(r.getLong("channelid"), r.getLong("hostid"), r.getTimestamp("end").toInstant(), r.getInt("winners"), r.getString("prize"), r.getLong("messageid")));
}
Also used : X509Certificate(java.security.cert.X509Certificate) JSONObject(org.jsolf.JSONObject) SSLContext(javax.net.ssl.SSLContext) JDA(net.dv8tion.jda.api.JDA) ScheduledFuture(java.util.concurrent.ScheduledFuture) CertificateFactory(java.security.cert.CertificateFactory) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HttpVersion(org.eclipse.jetty.http.HttpVersion) HashMap(java.util.HashMap) DatatypeConverter(jakarta.xml.bind.DatatypeConverter) GatewayIntent(net.dv8tion.jda.api.requests.GatewayIntent) ArrayList(java.util.ArrayList) Guild(net.dv8tion.jda.api.entities.Guild) ByteArrayInputStream(java.io.ByteArrayInputStream) JDABuilder(net.dv8tion.jda.api.JDABuilder) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Giveaway(de.tectoast.emolga.utils.Giveaway) DBManagers(de.tectoast.emolga.utils.sql.DBManagers) HttpHandler(de.tectoast.emolga.jetty.HttpHandler) MemberCachePolicy(net.dv8tion.jda.api.utils.MemberCachePolicy) PKCS8EncodedKeySpec(java.security.spec.PKCS8EncodedKeySpec) Files(java.nio.file.Files) Activity(net.dv8tion.jda.api.entities.Activity) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) IOException(java.io.IOException) KeyStore(java.security.KeyStore) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) CommandData(net.dv8tion.jda.api.interactions.commands.build.CommandData) CertificateException(java.security.cert.CertificateException) KeyManager(javax.net.ssl.KeyManager) File(java.io.File) KeyFactory(java.security.KeyFactory) Consumer(java.util.function.Consumer) Command(de.tectoast.emolga.commands.Command) List(java.util.List) Certificate(java.security.cert.Certificate) org.eclipse.jetty.server(org.eclipse.jetty.server) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MYSERVER(de.tectoast.emolga.utils.Constants.MYSERVER) ReactionManager(de.tectoast.toastilities.managers.ReactionManager) MessageWaiter(de.tectoast.emolga.utils.MessageWaiter) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) HashMap(java.util.HashMap) Giveaway(de.tectoast.emolga.utils.Giveaway) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Guild(net.dv8tion.jda.api.entities.Guild) ScheduledFuture(java.util.concurrent.ScheduledFuture) ReactionManager(de.tectoast.toastilities.managers.ReactionManager) Command(de.tectoast.emolga.commands.Command) ArrayList(java.util.ArrayList) List(java.util.List) CommandData(net.dv8tion.jda.api.interactions.commands.build.CommandData)

Example 2 with Command

use of de.tectoast.emolga.commands.Command in project Emolga by TecToast.

the class HelpButton method process.

@Override
public void process(ButtonClickEvent e, String name) {
    Guild g = e.getGuild();
    Member mem = e.getMember();
    if (name.equals("BACK")) {
        EmbedBuilder builder = new EmbedBuilder();
        builder.setTitle("Commands").setColor(java.awt.Color.CYAN);
        builder.setDescription(getHelpDescripion(g, mem));
        builder.setColor(java.awt.Color.CYAN);
        e.editMessageEmbeds(builder.build()).queue();
    } else {
        CommandCategory c = CommandCategory.byName(name);
        if (c.allowsGuild(g) && c.allowsMember(mem)) {
            List<Command> l = getWithCategory(c, g, mem);
            List<MessageEmbed> embeds = new LinkedList<>();
            StringBuilder b = new StringBuilder();
            boolean first = true;
            for (Command cmd : l) {
                b.append(cmd.getHelp(g)).append("\n");
                if (b.length() > 1900) {
                    EmbedBuilder emb = new EmbedBuilder();
                    if (first)
                        emb.setTitle(c.getName());
                    embeds.add(emb.setColor(Color.CYAN).setDescription(b.toString()).build());
                    first = false;
                    b.setLength(0);
                }
            }
            if (b.length() > 0) {
                EmbedBuilder emb = new EmbedBuilder();
                if (first)
                    emb.setTitle(c.getName());
                embeds.add(emb.setColor(Color.CYAN).setDescription(b.toString()).build());
            }
            e.editMessageEmbeds(embeds).queue(i -> i.editOriginalComponents(getHelpButtons(g, mem)).queue());
        } else {
            e.reply("Auf die Kategorie " + c.getName() + " hast du keinen Zugriff!").queue();
        }
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) MessageEmbed(net.dv8tion.jda.api.entities.MessageEmbed) Command(de.tectoast.emolga.commands.Command) CommandCategory(de.tectoast.emolga.commands.CommandCategory) Guild(net.dv8tion.jda.api.entities.Guild) Member(net.dv8tion.jda.api.entities.Member) LinkedList(java.util.LinkedList)

Example 3 with Command

use of de.tectoast.emolga.commands.Command in project Emolga by TecToast.

the class RandomPickCommand method process.

@Override
public void process(GuildCommandEvent e) {
    Member memberr = e.getMember();
    long member = memberr.getIdLong();
    TextChannel tco = e.getChannel();
    Draft d = Draft.getDraftByMember(member, tco);
    if (d == null) {
        e.getChannel().sendMessage("Du Kek der Command funktioniert nur in einem Draft xD").queue();
        return;
    }
    String msg = e.getMessage().getContentDisplay();
    Tierlist tierlist = d.getTierlist();
    ArgumentManager args = e.getArguments();
    String tier = tierlist.order.stream().filter(s -> args.getText("tier").equalsIgnoreCase(s)).findFirst().orElse("");
    if (tier.equals("")) {
        tco.sendMessage("Das ist kein Tier!").queue();
        return;
    }
    if (!d.tc.getId().equals(tco.getId()))
        return;
    if (d.isNotCurrent(member)) {
        tco.sendMessage(d.getMention(member) + " Du bist nicht dran!").queue();
        return;
    }
    long mem = d.current;
    JSONObject json = getEmolgaJSON();
    // JSONObject league = json.getJSONObject("drafts").getJSONObject(d.name);
    JSONObject league = getEmolgaJSON().getJSONObject("drafts").getJSONObject(d.name);
    /*if (asl.has("allowed")) {
                JSONObject allowed = asl.getJSONObject("allowed");
                if (allowed.has(member.getId())) {
                    mem = d.tc.getGuild().retrieveMemberById(allowed.getString(member.getId())).complete();
                } else mem = member;
            } else mem = member;*/
    ArrayList<String> list = new ArrayList<>(tierlist.tierlist.get(tier));
    Collections.shuffle(list);
    Predicate<String> typecheck;
    if (args.has("type")) {
        Translation type = args.getTranslation("type");
        typecheck = str -> getDataJSON().getJSONObject(getSDName(str)).getJSONArray("types").toList().contains(type.getTranslation());
    } else {
        typecheck = str -> true;
    }
    PickCommand.exec(tco, "!pick " + list.stream().filter(str -> !d.isPicked(str) && !d.hasInAnotherForm(mem, str) && (!d.hasMega(mem) || !str.startsWith("M-")) && typecheck.test(str)).map(String::trim).findFirst().orElse(""), memberr, true);
}
Also used : Command(de.tectoast.emolga.commands.Command) JSONObject(org.jsolf.JSONObject) Predicate(java.util.function.Predicate) GuildCommandEvent(de.tectoast.emolga.commands.GuildCommandEvent) CommandCategory(de.tectoast.emolga.commands.CommandCategory) Draft(de.tectoast.emolga.utils.draft.Draft) Member(net.dv8tion.jda.api.entities.Member) TextChannel(net.dv8tion.jda.api.entities.TextChannel) Tierlist(de.tectoast.emolga.utils.draft.Tierlist) Collections(java.util.Collections) ArrayList(java.util.ArrayList) Tierlist(de.tectoast.emolga.utils.draft.Tierlist) ArrayList(java.util.ArrayList) TextChannel(net.dv8tion.jda.api.entities.TextChannel) Draft(de.tectoast.emolga.utils.draft.Draft) JSONObject(org.jsolf.JSONObject) Member(net.dv8tion.jda.api.entities.Member)

Example 4 with Command

use of de.tectoast.emolga.commands.Command in project Emolga by TecToast.

the class SlashListener method onSlashCommand.

@Override
public void onSlashCommand(@NotNull SlashCommandEvent e) {
    Command command = Command.byName(e.getName());
    User u = e.getUser();
    TextChannel tco = e.getTextChannel();
    try {
        new GuildCommandEvent(command, e);
    } catch (Command.MissingArgumentException ex) {
        Command.ArgumentManagerTemplate.Argument arg = ex.getArgument();
        if (arg.hasCustomErrorMessage())
            e.reply(arg.getCustomErrorMessage()).queue();
        else {
            e.reply("Das benötigte Argument `" + arg.getName() + "`, was eigentlich " + buildEnumeration(arg.getType().getName()) + " sein müsste, ist nicht vorhanden!\n" + "Nähere Informationen über die richtige Syntax für den Command erhältst du unter `e!help " + command.getName() + "`.").queue();
        }
        if (u.getIdLong() != FLOID) {
            sendToMe("MissingArgument " + tco.getAsMention() + " Server: " + tco.getGuild().getName());
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        e.getHook().sendMessage("Es ist ein Fehler beim Ausführen des Commands aufgetreten!\nWenn du denkst, dass dies ein interner Fehler beim Bot ist, melde dich bitte bei Flo/TecToast.\n" + command.getHelp(e.getGuild()) + (u.getIdLong() == FLOID ? "\nJa Flo, du sollst dich auch bei ihm melden du Kek! :^)" : "")).queue();
    }
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) User(net.dv8tion.jda.api.entities.User) Command(de.tectoast.emolga.commands.Command) GuildCommandEvent(de.tectoast.emolga.commands.GuildCommandEvent)

Example 5 with Command

use of de.tectoast.emolga.commands.Command in project Emolga by TecToast.

the class HelpCommand method process.

@Override
public void process(GuildCommandEvent e) {
    String cmdname = e.getArguments().getText("cmd");
    Command c = Command.byName(cmdname);
    EmbedBuilder builder = new EmbedBuilder();
    builder.setTitle(c.getPrefix() + c.getName());
    builder.setColor(Color.CYAN);
    ArgumentManagerTemplate template = c.getArgumentTemplate();
    builder.setDescription(c.getHelpWithoutCmd(e.getGuild()));
    builder.addField("Syntax", "```" + (template.hasSyntax() ? template.getSyntax() : c.getPrefix() + c.getName() + " " + template.arguments.stream().map(a -> (a.isOptional() ? "[" : "<") + a.getName() + (a.isOptional() ? "]" : ">")).collect(Collectors.joining(" "))) + "```", false);
    for (ArgumentManagerTemplate.Argument a : template.arguments) {
        builder.addField(a.getName(), (a.isOptional() ? "(Optional)\n" : "") + a.getHelp(), true);
    }
    builder.setFooter("Aufgerufen von " + e.getAuthor().getAsTag());
    if (template.hasExample()) {
        builder.addField("Beispiel", "```" + template.getExample() + "```", false);
    }
    if (!c.getAliases().isEmpty()) {
        builder.addField("Aliases", "`" + String.join("`, `", c.getAliases()) + "`", false);
    }
    e.reply(builder.build());
}
Also used : java.awt(java.awt) Command(de.tectoast.emolga.commands.Command) GuildCommandEvent(de.tectoast.emolga.commands.GuildCommandEvent) CommandCategory(de.tectoast.emolga.commands.CommandCategory) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Collectors(java.util.stream.Collectors) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Command(de.tectoast.emolga.commands.Command)

Aggregations

Command (de.tectoast.emolga.commands.Command)6 CommandCategory (de.tectoast.emolga.commands.CommandCategory)3 GuildCommandEvent (de.tectoast.emolga.commands.GuildCommandEvent)3 ArrayList (java.util.ArrayList)3 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)3 Guild (net.dv8tion.jda.api.entities.Guild)2 Member (net.dv8tion.jda.api.entities.Member)2 TextChannel (net.dv8tion.jda.api.entities.TextChannel)2 HttpHandler (de.tectoast.emolga.jetty.HttpHandler)1 MYSERVER (de.tectoast.emolga.utils.Constants.MYSERVER)1 Giveaway (de.tectoast.emolga.utils.Giveaway)1 MessageWaiter (de.tectoast.emolga.utils.MessageWaiter)1 Draft (de.tectoast.emolga.utils.draft.Draft)1 Tierlist (de.tectoast.emolga.utils.draft.Tierlist)1 DBManagers (de.tectoast.emolga.utils.sql.DBManagers)1 ReactionManager (de.tectoast.toastilities.managers.ReactionManager)1 DatatypeConverter (jakarta.xml.bind.DatatypeConverter)1 java.awt (java.awt)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1