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;
}
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);
}
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());
});
}
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());
});
}
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);
}
});
}
Aggregations