Search in sources :

Example 11 with GuildSetting

use of com.dunctebot.models.settings.GuildSetting in project SkyBot by duncte123.

the class GuildSettingsUtils method registerNewGuild.

private static GuildSetting registerNewGuild(long guildId, Variables variables, GuildSetting newGuildSettings) {
    final Map<Long, GuildSetting> cache = variables.getGuildSettingsCache();
    final GuildSetting settingForGuild = cache.get(guildId);
    if (settingForGuild != null) {
        return settingForGuild;
    }
    variables.getDatabaseAdapter().registerNewGuild(newGuildSettings, (bool) -> null);
    variables.getGuildSettingsCache().put(guildId, newGuildSettings);
    return newGuildSettings;
}
Also used : GuildSetting(com.dunctebot.models.settings.GuildSetting)

Example 12 with GuildSetting

use of com.dunctebot.models.settings.GuildSetting in project SkyBot by duncte123.

the class GuildInfoCommand method sendGuildInfoEmbed.

@SuppressWarnings("PMD.ConfusingTernary")
private void sendGuildInfoEmbed(CommandContext ctx, String inviteString) {
    final Guild guild = ctx.getJDAGuild();
    final double[] ratio = GuildUtils.getBotRatio(guild);
    final EmbedBuilder builder = EmbedUtils.getDefaultEmbed();
    final GuildSetting settings = ctx.getGuildSettings();
    final Pair<String, String> times = Time4JKt.parseTimeCreated(guild);
    if (settings.getServerDesc() != null && !"".equals(settings.getServerDesc())) {
        builder.addField("Server Description", settings.getServerDesc() + "\n\u200B", false);
    } else if (guild.getDescription() != null && !"".equals(guild.getDescription())) {
        builder.addField("Server Description", guild.getDescription() + "\n\u200B", false);
    }
    String owner = "Unknown";
    if (guild.getOwner() != null) {
        owner = guild.getOwner().getEffectiveName();
    }
    String emoteList = "";
    final Set<String> features = guild.getFeatures();
    // can only have one of them
    if (features.contains("VERIFIED")) {
        emoteList = Emotes.DISCORD_VERIFIED_SERVER;
    } else if (features.contains("PARTNERED")) {
        emoteList = Emotes.DISCORD_PARTNER_SERVER;
    }
    builder.setThumbnail(guild.getIconUrl()).addField("Basic Info", "**Owner:** " + owner + "\n" + "**Name:** " + guild.getName() + ' ' + emoteList + "\n" + "**Prefix:** " + settings.getCustomPrefix() + "\n" + // TODO: remove this once it's removed
    "**Region:** " + guild.getRegion().getEmoji() + ' ' + guild.getRegion().getName() + "\n" + "**Created at:** " + String.format("%s (%s)", times.getFirst(), times.getSecond()) + "\n" + "**Verification level:** " + GuildUtils.verificationLvlToName(guild.getVerificationLevel()) + "\n" + inviteString + "\n\u200B", false).addField("Member Stats", "**Total members:** " + guild.getMemberCount() + "\n" + "**(Possible) Nitro users:** " + GuildUtils.getNitroUserCountCache(guild) + "\n" + "**Bot to user ratio:** " + ratio[1] + "% is a bot and " + ratio[0] + "% is a user", false);
    sendEmbed(ctx, builder);
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GuildSetting(com.dunctebot.models.settings.GuildSetting) Guild(net.dv8tion.jda.api.entities.Guild)

Example 13 with GuildSetting

use of com.dunctebot.models.settings.GuildSetting in project SkyBot by duncte123.

the class MuteCommand method execute.

@Override
public void execute(@Nonnull CommandContext ctx) {
    final List<String> args = ctx.getArgs();
    final List<Member> mentioned = ctx.getMentionedArg(0);
    if (mentioned.isEmpty()) {
        sendMsg(ctx, "I could not find any members with name " + args.get(0));
        return;
    }
    final GuildSetting settings = ctx.getGuildSettings();
    if (settings.getMuteRoleId() <= 0) {
        sendMsg(ctx, "No mute/spamrole is set, use `" + ctx.getPrefix() + "muterole <Role>` to set it");
        return;
    }
    final Member mod = ctx.getMember();
    final Member self = ctx.getSelfMember();
    final Member toMute = mentioned.get(0);
    final Role role = ctx.getGuild().getRoleById(settings.getMuteRoleId());
    if (canNotProceed(ctx, mod, toMute, role, self)) {
        return;
    }
    String reason = "No reason given";
    final var flags = ctx.getParsedFlags(this);
    if (flags.containsKey("r")) {
        reason = String.join(" ", flags.get("r"));
    } else if (args.size() > 1) {
        final var example = "\nExample: `%smute %s -r %s`".formatted(ctx.getPrefix(), args.get(0), String.join(" ", args.subList(1, args.size())));
        sendMsg(ctx, "Hint: if you want to set a reason, use the `-r` flag" + example);
    }
    ctx.getGuild().addRoleToMember(toMute, role).reason("Muted by " + String.format("%#s: %s", ctx.getAuthor(), reason)).queue(success -> {
        ModerationUtils.modLog(ctx.getAuthor(), toMute.getUser(), "muted", null, null, ctx.getGuild());
        sendSuccess(ctx.getMessage());
    });
}
Also used : Role(net.dv8tion.jda.api.entities.Role) GuildSetting(com.dunctebot.models.settings.GuildSetting) Member(net.dv8tion.jda.api.entities.Member)

Example 14 with GuildSetting

use of com.dunctebot.models.settings.GuildSetting in project SkyBot by duncte123.

the class TempMuteCommand method execute.

@Override
public void execute(@Nonnull CommandContext ctx) {
    final List<Member> mentioned = ctx.getMentionedArg(0);
    final List<String> args = ctx.getArgs();
    if (mentioned.isEmpty()) {
        sendMsg(ctx, "I could not find any members with name " + args.get(0));
        return;
    }
    final GuildSetting settings = ctx.getGuildSettings();
    if (settings.getMuteRoleId() <= 0) {
        sendMsg(ctx, "No mute/spamrole is set, use `" + ctx.getPrefix() + "spamrole <Role>` to set it");
        return;
    }
    final Member mod = ctx.getMember();
    final Member toMute = mentioned.get(0);
    final Guild guild = ctx.getGuild();
    final Role role = guild.getRoleById(settings.getMuteRoleId());
    final Member self = ctx.getSelfMember();
    if (canNotProceed(ctx, mod, toMute, role, self)) {
        return;
    }
    String reason = "No reason given";
    final var flags = ctx.getParsedFlags(this);
    if (flags.containsKey("r")) {
        reason = String.join(" ", flags.get("r"));
    } else if (args.size() > 2) {
        final var example = "\nExample: `%stempmute %s %s -r %s`".formatted(ctx.getPrefix(), args.get(0), args.get(1), String.join(" ", args.subList(2, args.size())));
        sendMsg(ctx, "Hint: if you want to set a reason, use the `-r` flag" + example);
    }
    final ParsedDuration duration = getDuration(args.get(1), getName(), ctx, ctx.getPrefix());
    if (duration == null) {
        return;
    }
    final String fReason = reason;
    final String finalDate = AirUtils.getDatabaseDateFormat(duration);
    final User mutee = toMute.getUser();
    final User author = ctx.getAuthor();
    ctx.getDatabaseAdapter().createMute(author.getIdLong(), mutee.getIdLong(), mutee.getAsTag(), finalDate, guild.getIdLong(), (mute) -> {
        if (mute != null) {
            final String modId = mute.getModId();
            final User oldMuteMod = guild.getJDA().getUserById(modId);
            String modName = "Unknown";
            if (oldMuteMod != null) {
                modName = oldMuteMod.getAsTag();
            }
            sendMsg(ctx, String.format("Previously created muted for %#s removed, mute was created by %s", mutee, modName));
        }
        return null;
    });
    guild.addRoleToMember(toMute, role).reason("Muted by " + String.format("%#s: %s", ctx.getAuthor(), fReason)).queue(success -> {
        ModerationUtils.modLog(author, mutee, "muted", fReason, duration.toString(), ctx.getGuild());
        sendSuccess(ctx.getMessage());
    });
}
Also used : Role(net.dv8tion.jda.api.entities.Role) User(net.dv8tion.jda.api.entities.User) ParsedDuration(me.duncte123.durationparser.ParsedDuration) GuildSetting(com.dunctebot.models.settings.GuildSetting) Guild(net.dv8tion.jda.api.entities.Guild) Member(net.dv8tion.jda.api.entities.Member)

Example 15 with GuildSetting

use of com.dunctebot.models.settings.GuildSetting in project SkyBot by DuncteBot.

the class MessageListener method onGuildMessageUpdate.

protected void onGuildMessageUpdate(GuildMessageUpdateEvent event) {
    // ignore bots
    final Message message = event.getMessage();
    final User author = message.getAuthor();
    if (author.isBot() || author.isSystem() || message.isWebhookMessage() || event.getMember() == null) {
        return;
    }
    if (topicContains(event.getChannel(), PROFANITY_DISABLE)) {
        return;
    }
    this.handlerThread.submit(() -> {
        try {
            final DunctebotGuild guild = new DunctebotGuild(event.getGuild(), variables);
            final GuildSetting settings = guild.getSettings();
            if (settings.isMessageLogging()) {
                final MessageData edited = MessageData.from(message);
                final MessageData original = this.redis.getAndUpdateMessage(message.getId(), edited, isGuildPatron(guild));
                // data will be null if the message expired
                if (original != null) {
                    this.logEditedMessage(original, edited, guild);
                }
            }
            if (guild.getSelfMember().hasPermission(Permission.MESSAGE_MANAGE) && !event.getMember().hasPermission(Permission.MESSAGE_MANAGE)) {
                if (blacklistedWordCheck(guild, message, event.getMember(), settings.getBlacklistedWords())) {
                    return;
                }
                checkSwearFilter(message, event, guild);
            }
        } catch (Exception e) {
            LOGGER.error("Exception on message update", e);
        }
    });
}
Also used : DunctebotGuild(ml.duncte123.skybot.entities.jda.DunctebotGuild) UnknownUser(ml.duncte123.skybot.objects.user.UnknownUser) MessageData(ml.duncte123.skybot.objects.discord.MessageData) GuildSetting(com.dunctebot.models.settings.GuildSetting)

Aggregations

GuildSetting (com.dunctebot.models.settings.GuildSetting)18 MessageData (ml.duncte123.skybot.objects.discord.MessageData)6 UnknownUser (ml.duncte123.skybot.objects.user.UnknownUser)6 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)6 Member (net.dv8tion.jda.api.entities.Member)6 Role (net.dv8tion.jda.api.entities.Role)6 MessageConfig (me.duncte123.botcommons.messaging.MessageConfig)4 DunctebotGuild (ml.duncte123.skybot.entities.jda.DunctebotGuild)4 CommandContext (ml.duncte123.skybot.objects.command.CommandContext)4 CustomCommand (ml.duncte123.skybot.objects.command.custom.CustomCommand)4 Guild (net.dv8tion.jda.api.entities.Guild)4 ErrorHandler (net.dv8tion.jda.api.exceptions.ErrorHandler)3 Sentry (io.sentry.Sentry)2 Instant (java.time.Instant)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 java.util (java.util)2 Executors (java.util.concurrent.Executors)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 TimeUnit (java.util.concurrent.TimeUnit)2 Consumer (java.util.function.Consumer)2