Search in sources :

Example 56 with Member

use of net.dv8tion.jda.core.entities.Member in project FredBoat by Frederikam.

the class ConfigCommand method setConfig.

private void setConfig(CommandContext context) {
    Member invoker = context.invoker;
    if (!PermsUtil.checkPermsWithFeedback(PermissionLevel.ADMIN, context)) {
        return;
    }
    if (context.args.length != 2) {
        HelpCommand.sendFormattedCommandHelp(context);
        return;
    }
    String key = context.args[0];
    String val = context.args[1];
    switch(key) {
        case "track_announce":
            if (val.equalsIgnoreCase("true") | val.equalsIgnoreCase("false")) {
                Launcher.getBotController().getGuildConfigService().transformGuildConfig(context.guild, gc -> gc.setTrackAnnounce(Boolean.valueOf(val)));
                context.replyWithName("`track_announce` " + context.i18nFormat("configSetTo", val));
            } else {
                context.reply(context.i18nFormat("configMustBeBoolean", TextUtils.escapeAndDefuse(invoker.getEffectiveName())));
            }
            break;
        case "auto_resume":
            if (val.equalsIgnoreCase("true") | val.equalsIgnoreCase("false")) {
                Launcher.getBotController().getGuildConfigService().transformGuildConfig(context.guild, gc -> gc.setAutoResume(Boolean.valueOf(val)));
                context.replyWithName("`auto_resume` " + context.i18nFormat("configSetTo", val));
            } else {
                context.reply(context.i18nFormat("configMustBeBoolean", TextUtils.escapeAndDefuse(invoker.getEffectiveName())));
            }
            break;
        default:
            context.reply(context.i18nFormat("configUnknownKey", TextUtils.escapeAndDefuse(invoker.getEffectiveName())));
            break;
    }
}
Also used : Member(net.dv8tion.jda.core.entities.Member)

Example 57 with Member

use of net.dv8tion.jda.core.entities.Member in project FredBoat by Frederikam.

the class ClearCommand method onInvoke.

// TODO: Redo this
// TODO: i18n this class
@Override
public void onInvoke(@Nonnull CommandContext context) {
    JDA jda = context.guild.getJDA();
    TextChannel channel = context.channel;
    Member invoker = context.invoker;
    if (!invoker.hasPermission(channel, Permission.MESSAGE_MANAGE) && !PermsUtil.checkPerms(PermissionLevel.BOT_ADMIN, invoker)) {
        context.replyWithName("You must have Manage Messages to do that!");
        return;
    }
    if (!context.guild.getSelfMember().hasPermission(channel, Permission.MESSAGE_HISTORY)) {
        context.reply(context.i18n("permissionMissingBot") + " **" + Permission.MESSAGE_HISTORY.getName() + "**");
        return;
    }
    MessageHistory history = new MessageHistory(channel);
    history.retrievePast(50).queue(msgs -> {
        Metrics.successfulRestActions.labels("retrieveMessageHistory").inc();
        ArrayList<Message> toDelete = new ArrayList<>();
        for (Message msg : msgs) {
            if (msg.getAuthor().equals(jda.getSelfUser()) && youngerThanTwoWeeks(msg)) {
                toDelete.add(msg);
            }
        }
        if (toDelete.isEmpty()) {
            context.reply("No messages found.");
        } else if (toDelete.size() == 1) {
            context.reply("Found one message, deleting.");
            CentralMessaging.deleteMessage(toDelete.get(0));
        } else {
            if (!context.hasPermissions(Permission.MESSAGE_MANAGE)) {
                context.reply("I must have the `Manage Messages` permission to delete my own messages in bulk.");
                return;
            }
            context.reply("Deleting **" + toDelete.size() + "** messages.");
            CentralMessaging.deleteMessages(channel, toDelete);
        }
    }, CentralMessaging.getJdaRestActionFailureHandler(String.format("Failed to retrieve message history in channel %s in guild %s", channel.getId(), context.guild.getId())));
}
Also used : MessageHistory(net.dv8tion.jda.core.entities.MessageHistory) TextChannel(net.dv8tion.jda.core.entities.TextChannel) Message(net.dv8tion.jda.core.entities.Message) JDA(net.dv8tion.jda.core.JDA) ArrayList(java.util.ArrayList) Member(net.dv8tion.jda.core.entities.Member)

Example 58 with Member

use of net.dv8tion.jda.core.entities.Member in project FredBoat by Frederikam.

the class SoftbanCommand method onInvoke.

@Override
public void onInvoke(@Nonnull CommandContext context) {
    Guild guild = context.guild;
    // Ensure we have a search term
    if (!context.hasArguments()) {
        HelpCommand.sendFormattedCommandHelp(context);
        return;
    }
    // was there a target provided?
    Member target = ArgumentUtil.checkSingleFuzzyMemberSearchResult(context, context.args[0]);
    if (target == null)
        return;
    // are we allowed to do that?
    if (!checkAuthorization(context, target))
        return;
    // putting together a reason
    String plainReason = DiscordUtil.getReasonForModAction(context);
    String auditLogReason = DiscordUtil.formatReasonForAuditLog(plainReason, context.invoker);
    // putting together the action
    RestAction<Void> modAction = guild.getController().ban(target, 7, auditLogReason);
    // on success
    String successOutput = context.i18nFormat("softbanSuccess", TextUtils.escapeAndDefuse(target.getUser().getName()), target.getUser().getDiscriminator(), target.getUser().getId()) + "\n" + plainReason;
    Consumer<Void> onSuccess = aVoid -> {
        Metrics.successfulRestActions.labels("ban").inc();
        guild.getController().unban(target.getUser()).queue(__ -> Metrics.successfulRestActions.labels("unban").inc(), CentralMessaging.getJdaRestActionFailureHandler(String.format("Failed to unban user %s in guild %s", target.getUser().getId(), guild.getId())));
        context.replyWithName(successOutput);
    };
    // on fail
    String failOutput = context.i18nFormat("modBanFail", target.getUser());
    Consumer<Throwable> onFail = t -> {
        CentralMessaging.getJdaRestActionFailureHandler(String.format("Failed to ban user %s in guild %s", target.getUser().getId(), guild.getId())).accept(t);
        context.replyWithName(failOutput);
    };
    // issue the mod action
    modAction.queue(onSuccess, onFail);
}
Also used : ArgumentUtil(fredboat.util.ArgumentUtil) CentralMessaging(fredboat.messaging.CentralMessaging) Logger(org.slf4j.Logger) Member(net.dv8tion.jda.core.entities.Member) Command(fredboat.commandmeta.abs.Command) LoggerFactory(org.slf4j.LoggerFactory) CommandContext(fredboat.commandmeta.abs.CommandContext) TextUtils(fredboat.util.TextUtils) IModerationCommand(fredboat.commandmeta.abs.IModerationCommand) RestAction(net.dv8tion.jda.core.requests.RestAction) Consumer(java.util.function.Consumer) Guild(net.dv8tion.jda.core.entities.Guild) Permission(net.dv8tion.jda.core.Permission) Context(fredboat.messaging.internal.Context) DiscordUtil(fredboat.util.DiscordUtil) HelpCommand(fredboat.command.info.HelpCommand) Metrics(fredboat.feature.metrics.Metrics) Nonnull(javax.annotation.Nonnull) Guild(net.dv8tion.jda.core.entities.Guild) Member(net.dv8tion.jda.core.entities.Member)

Example 59 with Member

use of net.dv8tion.jda.core.entities.Member 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)

Example 60 with Member

use of net.dv8tion.jda.core.entities.Member in project SkyBot by duncte123.

the class GuildUtils method getBotAndUserCount.

/**
 * Returns an array with the member counts of the guild
 * 0 = the total users
 * 1 = the total bots
 * 3 = the total members
 *
 * @param g The {@link Guild Guild} to count the users in
 * @return an array with the member counts of the guild
 */
public static long[] getBotAndUserCount(Guild g) {
    MemberCacheView memberCache = g.getMemberCache();
    long totalCount = memberCache.size();
    long botCount = memberCache.stream().filter(it -> it.getUser().isBot()).count();
    long userCount = totalCount - botCount;
    return new long[] { userCount, botCount, totalCount };
}
Also used : MemberCacheView(net.dv8tion.jda.core.utils.cache.MemberCacheView) Logger(org.slf4j.Logger) Member(net.dv8tion.jda.core.entities.Member) ComparatingUtils(ml.duncte123.skybot.unstable.utils.ComparatingUtils) TextChannel(net.dv8tion.jda.core.entities.TextChannel) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Settings(ml.duncte123.skybot.Settings) MemberCacheView(net.dv8tion.jda.core.utils.cache.MemberCacheView) Objects(java.util.Objects) Guild(net.dv8tion.jda.core.entities.Guild) AtomicLong(java.util.concurrent.atomic.AtomicLong) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) Permission(net.dv8tion.jda.core.Permission) Map(java.util.Map) JDA(net.dv8tion.jda.core.JDA)

Aggregations

Member (net.dv8tion.jda.core.entities.Member)69 Guild (net.dv8tion.jda.core.entities.Guild)22 Message (net.dv8tion.jda.core.entities.Message)22 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)17 User (net.dv8tion.jda.core.entities.User)17 TextChannel (net.dv8tion.jda.core.entities.TextChannel)16 MessageBuilder (net.dv8tion.jda.core.MessageBuilder)11 ArrayList (java.util.ArrayList)10 List (java.util.List)10 Permission (net.dv8tion.jda.core.Permission)8 GuildWrapper (stream.flarebot.flarebot.objects.GuildWrapper)8 Role (net.dv8tion.jda.core.entities.Role)7 CommandType (stream.flarebot.flarebot.commands.CommandType)7 MessageUtils (stream.flarebot.flarebot.util.MessageUtils)7 Collectors (java.util.stream.Collectors)6 Permission (stream.flarebot.flarebot.permissions.Permission)6 GuildPlayer (fredboat.audio.player.GuildPlayer)5 AudioTrackContext (fredboat.audio.queue.AudioTrackContext)5 JDA (net.dv8tion.jda.core.JDA)5 Command (stream.flarebot.flarebot.commands.Command)5