Search in sources :

Example 1 with IMusicCommand

use of fredboat.commandmeta.abs.IMusicCommand in project FredBoat by Frederikam.

the class CommandManager method prefixCalled.

public void prefixCalled(CommandContext context) {
    Guild guild = context.guild;
    Command invoked = context.command;
    TextChannel channel = context.channel;
    Member invoker = context.invoker;
    totalCommandsExecuted.incrementAndGet();
    Metrics.commandsExecuted.labels(invoked.getClass().getSimpleName()).inc();
    if (FeatureFlags.PATRON_VALIDATION.isActive()) {
        PatronageChecker.Status status = patronageChecker.getStatus(guild);
        if (!status.isValid()) {
            String msg = "Access denied. This bot can only be used if invited from <https://patron.fredboat.com/> " + "by someone who currently has a valid pledge on Patreon.\n**Denial reason:** " + status.getReason() + "\n\n";
            msg += "Do you believe this to be a mistake? If so reach out to Fre_d on Patreon <" + BotConstants.PATREON_CAMPAIGN_URL + ">";
            context.reply(msg);
            return;
        }
    }
    // Hardcode music commands in FredBoatHangout. Blacklist any channel that isn't #spam_and_music or #staff, but whitelist Admins
    if (guild.getIdLong() == BotConstants.FREDBOAT_HANGOUT_ID && DiscordUtil.isOfficialBot(credentials)) {
        if (// #spam_and_music
        !channel.getId().equals("174821093633294338") && // #staff
        !channel.getId().equals("217526705298866177") && !PermsUtil.checkPerms(PermissionLevel.ADMIN, invoker)) {
            context.deleteMessage();
            context.replyWithName("Please read <#219483023257763842> for server rules and only use commands in <#174821093633294338>!", msg -> CentralMessaging.restService.schedule(() -> CentralMessaging.deleteMessage(msg), 5, TimeUnit.SECONDS));
            return;
        }
    }
    if (disabledCommands.contains(invoked)) {
        context.replyWithName("Sorry the `" + context.command.name + "` command is currently disabled. Please try again later");
        return;
    }
    if (invoked instanceof ICommandRestricted) {
        if (!PermsUtil.checkPermsWithFeedback(((ICommandRestricted) invoked).getMinimumPerms(), context)) {
            return;
        }
    }
    if (invoked instanceof IMusicCommand) {
        musicTextChannelProvider.setMusicChannel(channel);
    }
    try {
        invoked.onInvoke(context);
    } catch (Exception e) {
        TextUtils.handleException(e, context);
    }
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) PatronageChecker(fredboat.feature.PatronageChecker) Command(fredboat.commandmeta.abs.Command) IMusicCommand(fredboat.commandmeta.abs.IMusicCommand) ICommandRestricted(fredboat.commandmeta.abs.ICommandRestricted) Guild(net.dv8tion.jda.core.entities.Guild) IMusicCommand(fredboat.commandmeta.abs.IMusicCommand) Member(net.dv8tion.jda.core.entities.Member)

Aggregations

Command (fredboat.commandmeta.abs.Command)1 ICommandRestricted (fredboat.commandmeta.abs.ICommandRestricted)1 IMusicCommand (fredboat.commandmeta.abs.IMusicCommand)1 PatronageChecker (fredboat.feature.PatronageChecker)1 Guild (net.dv8tion.jda.core.entities.Guild)1 Member (net.dv8tion.jda.core.entities.Member)1 TextChannel (net.dv8tion.jda.core.entities.TextChannel)1