All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.neoforged.camelot.db.callback.TrickCallbacks Maven / Gradle / Ivy

There is a newer version: 1.0.177
Show newest version
package net.neoforged.camelot.db.callback;

import net.neoforged.camelot.BotMain;
import net.neoforged.camelot.Database;
import net.neoforged.camelot.db.api.ExecutionCallback;
import net.neoforged.camelot.db.transactionals.SlashTricksDAO;
import net.neoforged.camelot.db.transactionals.TricksDAO;
import net.neoforged.camelot.module.TricksModule;
import net.neoforged.camelot.script.ScriptUtils;

/**
 * Callbacks for {@link TricksDAO}.
 */
public class TrickCallbacks {
    /**
     * A callback that runs when a trick's script is updated, and marks the trick as needing an update
     * in guilds where it was promoted to a slash trick.
     */
    @ExecutionCallback(methodName = "updateScript", phase = ExecutionCallback.Phase.POST)
    public static void onScriptUpdated(TricksDAO dao, int trickId, String script) {
        Database.main().withExtension(SlashTricksDAO.class, db -> db.getPromotionsOfTrick(trickId))
                .forEach(trick -> BotMain.getModule(TricksModule.class).slashTrickManagers.get(trick.guildId()).markNeedsUpdate(trick));
    }

    /**
     * A callback that runs on trick deletion to trigger guild command updates in guilds where it was promoted to a slash trick.
     */
    @ExecutionCallback(methodName = "delete", phase = ExecutionCallback.Phase.POST)
    public static void onTrickDeleted(TricksDAO dao, int trickId) {
        Database.main().withExtension(SlashTricksDAO.class, db -> db.getPromotionsOfTrick(trickId))
                .forEach(trick -> ScriptUtils.SERVICE.submit(() -> BotMain.getModule(TricksModule.class).slashTrickManagers
                        .get(trick.guildId()).updateCommands(BotMain.get().getGuildById(trick.guildId()))));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy