use of com.dunctebot.models.settings.GuildSetting in project SkyBot by DuncteBot.
the class MessageListener method handleMessageEventChecked.
private void handleMessageEventChecked(String raw, Guild guild, GuildMessageReceivedEvent event) {
final GuildSetting settings = GuildSettingsUtils.getGuild(guild.getIdLong(), this.variables);
final String customPrefix = settings.getCustomPrefix();
final Message message = event.getMessage();
if (settings.isMessageLogging()) {
final MessageData data = MessageData.from(message);
this.redis.storeMessage(data, isGuildPatron(guild));
}
if (!commandManager.isCommand(customPrefix, raw) && doAutoModChecks(event, settings, raw)) {
return;
}
final User selfUser = event.getJDA().getSelfUser();
final long selfId = selfUser.getIdLong();
final String selfRegex = "<@!?" + selfId + '>';
if (raw.matches(selfRegex)) {
sendMsg(new MessageConfig.Builder().setChannel(event.getChannel()).setMessageFormat("Hey %s, try `%shelp` for a list of commands. If it doesn't work scream at _duncte123#1245_", event.getAuthor(), customPrefix).build());
return;
}
final String[] split = raw.replaceFirst(Pattern.quote(Settings.PREFIX), "").split("\\s+");
final List<CustomCommand> autoResponses = commandManager.getAutoResponses(guild.getIdLong());
if (!autoResponses.isEmpty() && invokeAutoResponse(autoResponses, split, event)) {
return;
}
if (doesNotStartWithPrefix(selfId, raw, customPrefix) || !canRunCommands(raw, customPrefix, event)) {
return;
}
if (raw.matches(selfRegex + "(.*)")) {
// Handle the chat command
Objects.requireNonNull(commandManager.getCommand("chat")).executeCommand(new CommandContext("chat", Arrays.asList(split).subList(1, split.length), event, variables));
} else {
// Handle the command
commandManager.runCommand(event, customPrefix);
}
}
use of com.dunctebot.models.settings.GuildSetting in project SkyBot by DuncteBot.
the class MessageListener method checkMessageForInvites.
// / <editor-fold desc="auto moderation" defaultstate="collapsed">
private void checkMessageForInvites(Guild guild, GuildMessageReceivedEvent event, GuildSetting settings, String raw) {
if (settings.isFilterInvites() && guild.getSelfMember().hasPermission(Permission.MANAGE_SERVER)) {
final Matcher matcher = Message.INVITE_PATTERN.matcher(raw);
if (matcher.find()) {
// Get the invite Id from the message
final String inviteID = matcher.group(matcher.groupCount());
// Prohibiting failure because the bot is currently banned from the other guild.
guild.retrieveInvites().queue((invites) -> {
// Check if the invite is for this guild, if it is not delete the message
if (invites.stream().noneMatch((invite) -> invite.getCode().equals(inviteID))) {
event.getMessage().delete().reason("Contained unauthorized invite.").queue((it) -> sendMsg(MessageConfig.Builder.fromEvent(event).setMessage(event.getAuthor().getAsMention() + ", please don't post invite links here.").setSuccessAction(m -> m.delete().queueAfter(4, TimeUnit.SECONDS)).build()), new ErrorHandler().ignore(UNKNOWN_MESSAGE, MISSING_PERMISSIONS));
}
});
}
}
}
use of com.dunctebot.models.settings.GuildSetting in project SkyBot by DuncteBot.
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;
}
Aggregations