Search in sources :

Example 16 with GuildObject

use of com.github.vaerys.masterobjects.GuildObject in project DiscordSailv2 by Vaerys-Dawn.

the class SetupWizard method execute.

@Override
public String execute(String args, CommandObject command) {
    if (SetupHandler.isRunningSetup(command.guild)) {
        return "> Setup is already running for this guild. I can't run it twice!";
    }
    // user can only run setup for one guild at a time
    UserObject user = command.user;
    for (GuildObject guildObject : Globals.getGuilds()) {
        if (guildObject.config.setupUser == user.longID) {
            return "> You're running setup for a different guild. I can't do more than one at a time.";
        }
    }
    // Handle Setup beginning
    String message = "Hi! I'm " + command.client.bot.displayName + " and I'm here to help you get your server set up.\n" + "This guide will walk you through a bunch of commands and things you can do to make your server exactly the way you want it.\n\n" + "You can navigate forwards and backwards in this setup with **" + new SetupBack().getUsage(command) + "** and **" + new SetupNext().getUsage(command) + "**";
    if (command.user.sendDm(message) == null) {
        return "> **ERROR**: I wasn't able to send you a DM! Check your server privacy settings!";
    }
    // send first setup stage response
    SetupHandler.setSetupStage(command, SetupStage.SETUP_MODULES);
    return "> Check your DMs for more instructions.";
}
Also used : GuildObject(com.github.vaerys.masterobjects.GuildObject) UserObject(com.github.vaerys.masterobjects.UserObject) SetupBack(com.github.vaerys.commands.setup.SetupBack) SetupNext(com.github.vaerys.commands.setup.SetupNext)

Example 17 with GuildObject

use of com.github.vaerys.masterobjects.GuildObject in project DiscordSailv2 by Vaerys-Dawn.

the class LoggingHandler method doRoleUpdateLog.

public static void doRoleUpdateLog(UserRoleUpdateEvent event) {
    IGuild guild = event.getGuild();
    GuildObject content = Globals.getGuildContent(guild.getLongID());
    if (!content.config.moduleLogging)
        return;
    if (content.config.userRoleLogging) {
        ArrayList<String> oldRoles = new ArrayList<>();
        ArrayList<String> newRoles = new ArrayList<>();
        oldRoles.addAll(event.getOldRoles().stream().filter(r -> !r.isEveryoneRole()).map(IRole::getName).collect(Collectors.toList()));
        newRoles.addAll(event.getNewRoles().stream().filter(r -> !r.isEveryoneRole()).map(IRole::getName).collect(Collectors.toList()));
        StringBuilder oldRoleList = new StringBuilder();
        StringBuilder newRoleList = new StringBuilder();
        for (String r : oldRoles) {
            oldRoleList.append(r + ", ");
        }
        for (String r : newRoles) {
            newRoleList.append(r + ", ");
        }
        String prefix = "> **@" + event.getUser().getName() + "#" + event.getUser().getDiscriminator() + "'s** Role have been Updated.";
        Utility.sendLog(prefix + "\nOld Roles: " + Utility.listFormatter(oldRoles, true) + "\nNew Roles: " + Utility.listFormatter(newRoles, true), content, false);
    }
}
Also used : GuildObject(com.github.vaerys.masterobjects.GuildObject) GuildMemberEvent(sx.blah.discord.handle.impl.events.guild.member.GuildMemberEvent) ChannelUpdateEvent(sx.blah.discord.handle.impl.events.guild.channel.ChannelUpdateEvent) UserBanEvent(sx.blah.discord.handle.impl.events.guild.member.UserBanEvent) ZonedDateTime(java.time.ZonedDateTime) ChannelSetting(com.github.vaerys.enums.ChannelSetting) LoggerFactory(org.slf4j.LoggerFactory) Client(com.github.vaerys.main.Client) MessageUpdateEvent(sx.blah.discord.handle.impl.events.guild.channel.message.MessageUpdateEvent) ArrayList(java.util.ArrayList) DiscordUtils(sx.blah.discord.api.internal.DiscordUtils) AuditLogEntry(sx.blah.discord.handle.audit.entry.AuditLogEntry) TargetedEntry(sx.blah.discord.handle.audit.entry.TargetedEntry) ActionType(sx.blah.discord.handle.audit.ActionType) ZoneOffset(java.time.ZoneOffset) CommandObject(com.github.vaerys.commands.CommandObject) Globals(com.github.vaerys.main.Globals) Logger(org.slf4j.Logger) ChannelCreateEvent(sx.blah.discord.handle.impl.events.guild.channel.ChannelCreateEvent) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) List(java.util.List) sx.blah.discord.handle.obj(sx.blah.discord.handle.obj) ChannelDeleteEvent(sx.blah.discord.handle.impl.events.guild.channel.ChannelDeleteEvent) Comparator(java.util.Comparator) Utility(com.github.vaerys.main.Utility) UserRoleUpdateEvent(sx.blah.discord.handle.impl.events.guild.member.UserRoleUpdateEvent) GuildObject(com.github.vaerys.masterobjects.GuildObject) ArrayList(java.util.ArrayList)

Example 18 with GuildObject

use of com.github.vaerys.masterobjects.GuildObject in project DiscordSailv2 by Vaerys-Dawn.

the class LoggingHandler method doChannelUpdateLog.

public static void doChannelUpdateLog(ChannelUpdateEvent event) {
    GuildObject content = Globals.getGuildContent(event.getGuild().getLongID());
    if (event.getNewChannel() instanceof IVoiceChannel) {
        // TODO: 26/03/2018 Add support for voice Channels.
        return;
    }
    if (!content.config.moduleLogging)
        return;
    if (content.config.channelLogging) {
        if (!event.getOldChannel().getName().equalsIgnoreCase(event.getNewChannel().getName())) {
            String log = "> Channel " + event.getNewChannel().mention() + "'s name was changed.\nOld name : #" + event.getOldChannel().getName() + ".";
            Utility.sendLog(log, content, false);
        } else if ((event.getOldChannel().getTopic() == null || event.getOldChannel().getTopic().isEmpty()) && (event.getNewChannel().getTopic() == null || event.getNewChannel().getTopic().isEmpty())) {
        // do nothing
        } else if ((event.getOldChannel().getTopic() == null || event.getOldChannel().getTopic().isEmpty()) && (event.getNewChannel().getTopic() != null || !event.getNewChannel().getTopic().isEmpty())) {
            StringBuilder log = new StringBuilder("> Channel " + event.getNewChannel().mention() + "'s Channel topic was added.\n");
            log.append("**New Topic**: " + event.getNewChannel().getTopic());
            Utility.sendLog(log.toString(), content, false);
        } else if ((event.getOldChannel().getTopic() != null || !event.getOldChannel().getTopic().isEmpty()) && (event.getNewChannel().getTopic() == null || event.getNewChannel().getTopic().isEmpty())) {
            StringBuilder log = new StringBuilder("> Channel " + event.getNewChannel().mention() + "'s Channel topic was removed.\n");
            log.append("**Old Topic**: " + event.getOldChannel().getTopic());
            Utility.sendLog(log.toString(), content, false);
        } else if (!event.getOldChannel().getTopic().equalsIgnoreCase(event.getNewChannel().getTopic())) {
            StringBuilder log = new StringBuilder("> Channel " + event.getNewChannel().mention() + "'s Channel topic was changed.");
            log.append("\n**Old Topic**: " + event.getOldChannel().getTopic());
            log.append("\n**New Topic**: " + event.getNewChannel().getTopic());
            Utility.sendLog(log.toString(), content, false);
        }
    }
}
Also used : GuildObject(com.github.vaerys.masterobjects.GuildObject)

Example 19 with GuildObject

use of com.github.vaerys.masterobjects.GuildObject in project DiscordSailv2 by Vaerys-Dawn.

the class LoggingHandler method doBanLog.

public static void doBanLog(UserBanEvent event) {
    IGuild guild = event.getGuild();
    GuildObject guildObject = Globals.getGuildContent(guild.getLongID());
    if (!guildObject.config.banLogging || !GuildHandler.testForPerms(Client.getClient().getOurUser(), guild, Permissions.VIEW_AUDIT_LOG))
        return;
    StringHandler output = new StringHandler("> **@%s#%s** was banned");
    output.setContent(String.format(output.toString(), event.getUser().getName(), event.getUser().getDiscriminator()));
    // get recent bans
    List<TargetedEntry> recentBans = event.getGuild().getAuditLog(ActionType.MEMBER_BAN_ADD).getEntriesByTarget(event.getUser().getLongID());
    if (recentBans.size() == 0)
        return;
    // and sort them. last entry is most recent.
    recentBans.sort(Comparator.comparingLong(o -> DiscordUtils.getSnowflakeTimeFromID(o.getLongID()).toEpochMilli()));
    AuditLogEntry lastBan = recentBans.get(recentBans.size() - 1);
    output.appendFormatted(" by **@%s#%s**", lastBan.getResponsibleUser().getName(), lastBan.getResponsibleUser().getDiscriminator());
    String reason = lastBan.getReason().isPresent() ? lastBan.getReason().get() : "No reason provided";
    output.appendFormatted(" with reason `%s`", reason);
    Utility.sendLog(output.toString(), guildObject, true);
}
Also used : GuildObject(com.github.vaerys.masterobjects.GuildObject) GuildMemberEvent(sx.blah.discord.handle.impl.events.guild.member.GuildMemberEvent) ChannelUpdateEvent(sx.blah.discord.handle.impl.events.guild.channel.ChannelUpdateEvent) UserBanEvent(sx.blah.discord.handle.impl.events.guild.member.UserBanEvent) ZonedDateTime(java.time.ZonedDateTime) ChannelSetting(com.github.vaerys.enums.ChannelSetting) LoggerFactory(org.slf4j.LoggerFactory) Client(com.github.vaerys.main.Client) MessageUpdateEvent(sx.blah.discord.handle.impl.events.guild.channel.message.MessageUpdateEvent) ArrayList(java.util.ArrayList) DiscordUtils(sx.blah.discord.api.internal.DiscordUtils) AuditLogEntry(sx.blah.discord.handle.audit.entry.AuditLogEntry) TargetedEntry(sx.blah.discord.handle.audit.entry.TargetedEntry) ActionType(sx.blah.discord.handle.audit.ActionType) ZoneOffset(java.time.ZoneOffset) CommandObject(com.github.vaerys.commands.CommandObject) Globals(com.github.vaerys.main.Globals) Logger(org.slf4j.Logger) ChannelCreateEvent(sx.blah.discord.handle.impl.events.guild.channel.ChannelCreateEvent) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) List(java.util.List) sx.blah.discord.handle.obj(sx.blah.discord.handle.obj) ChannelDeleteEvent(sx.blah.discord.handle.impl.events.guild.channel.ChannelDeleteEvent) Comparator(java.util.Comparator) Utility(com.github.vaerys.main.Utility) UserRoleUpdateEvent(sx.blah.discord.handle.impl.events.guild.member.UserRoleUpdateEvent) GuildObject(com.github.vaerys.masterobjects.GuildObject) AuditLogEntry(sx.blah.discord.handle.audit.entry.AuditLogEntry) TargetedEntry(sx.blah.discord.handle.audit.entry.TargetedEntry)

Example 20 with GuildObject

use of com.github.vaerys.masterobjects.GuildObject in project DiscordSailv2 by Vaerys-Dawn.

the class LoggingHandler method doKickLog.

/**
 * Handler for logging Kicks.
 *
 * @param guild the Guild the user left.
 * @param user  the User that left the server.
 */
private static void doKickLog(IGuild guild, IUser user) {
    IUser botUser = Client.getClient().getOurUser();
    // test if the bot has auditLog perms
    if (!GuildHandler.testForPerms(botUser, guild, Permissions.VIEW_AUDIT_LOG))
        return;
    // getTimestamp
    long timeStamp = Instant.now().atZone(ZoneOffset.UTC).toEpochSecond() * 1000;
    // build Message
    StringHandler kickLog = new StringHandler("**@%s#%d** has been **Kicked** by **@%s#%d**");
    // do some checks to make sure the user was in fact kicked
    List<TargetedEntry> kicksLog = guild.getAuditLog(ActionType.MEMBER_KICK).getEntriesByTarget(user.getLongID());
    if (kicksLog.size() == 0)
        return;
    // sort kickLog and get latest entry
    kicksLog.sort(Comparator.comparingLong(o -> DiscordUtils.getSnowflakeTimeFromID(o.getLongID()).toEpochMilli()));
    AuditLogEntry lastKick = kicksLog.get(kicksLog.size() - 1);
    // get the latest entry's timestamp
    long lastKickTime = DiscordUtils.getSnowflakeTimeFromID(lastKick.getLongID()).toEpochMilli();
    // get user responsible
    IUser responsible = lastKick.getResponsibleUser();
    // Check if timestamp is within fifteen seconds either way, lastKick is valid.
    long timeDiff = Math.abs(timeStamp - lastKickTime);
    if (timeDiff > 15000)
        return;
    // format and send message
    kickLog.format(user.getName(), user.getDiscriminator(), responsible.getName(), responsible.getName());
    if (lastKick.getReason().isPresent()) {
        kickLog.appendFormatted(" with reason `%s`", lastKick.getReason().get());
    }
    // send log
    GuildObject content = Globals.getGuildContent(guild.getLongID());
    Utility.sendLog(kickLog.toString(), content, true);
}
Also used : GuildObject(com.github.vaerys.masterobjects.GuildObject) GuildMemberEvent(sx.blah.discord.handle.impl.events.guild.member.GuildMemberEvent) ChannelUpdateEvent(sx.blah.discord.handle.impl.events.guild.channel.ChannelUpdateEvent) UserBanEvent(sx.blah.discord.handle.impl.events.guild.member.UserBanEvent) ZonedDateTime(java.time.ZonedDateTime) ChannelSetting(com.github.vaerys.enums.ChannelSetting) LoggerFactory(org.slf4j.LoggerFactory) Client(com.github.vaerys.main.Client) MessageUpdateEvent(sx.blah.discord.handle.impl.events.guild.channel.message.MessageUpdateEvent) ArrayList(java.util.ArrayList) DiscordUtils(sx.blah.discord.api.internal.DiscordUtils) AuditLogEntry(sx.blah.discord.handle.audit.entry.AuditLogEntry) TargetedEntry(sx.blah.discord.handle.audit.entry.TargetedEntry) ActionType(sx.blah.discord.handle.audit.ActionType) ZoneOffset(java.time.ZoneOffset) CommandObject(com.github.vaerys.commands.CommandObject) Globals(com.github.vaerys.main.Globals) Logger(org.slf4j.Logger) ChannelCreateEvent(sx.blah.discord.handle.impl.events.guild.channel.ChannelCreateEvent) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) List(java.util.List) sx.blah.discord.handle.obj(sx.blah.discord.handle.obj) ChannelDeleteEvent(sx.blah.discord.handle.impl.events.guild.channel.ChannelDeleteEvent) Comparator(java.util.Comparator) Utility(com.github.vaerys.main.Utility) UserRoleUpdateEvent(sx.blah.discord.handle.impl.events.guild.member.UserRoleUpdateEvent) GuildObject(com.github.vaerys.masterobjects.GuildObject) AuditLogEntry(sx.blah.discord.handle.audit.entry.AuditLogEntry) TargetedEntry(sx.blah.discord.handle.audit.entry.TargetedEntry)

Aggregations

GuildObject (com.github.vaerys.masterobjects.GuildObject)21 CommandObject (com.github.vaerys.commands.CommandObject)5 ZonedDateTime (java.time.ZonedDateTime)5 ArrayList (java.util.ArrayList)4 UserRoleUpdateEvent (sx.blah.discord.handle.impl.events.guild.member.UserRoleUpdateEvent)4 ChannelSetting (com.github.vaerys.enums.ChannelSetting)3 Client (com.github.vaerys.main.Client)3 Globals (com.github.vaerys.main.Globals)3 Utility (com.github.vaerys.main.Utility)3 Instant (java.time.Instant)3 ZoneOffset (java.time.ZoneOffset)3 Comparator (java.util.Comparator)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 DiscordUtils (sx.blah.discord.api.internal.DiscordUtils)3 EmbedObject (sx.blah.discord.api.internal.json.objects.EmbedObject)3 ActionType (sx.blah.discord.handle.audit.ActionType)3 AuditLogEntry (sx.blah.discord.handle.audit.entry.AuditLogEntry)3