Search in sources :

Example 1 with GuildConfig

use of com.github.vaerys.pogos.GuildConfig in project DiscordSailv2 by Vaerys-Dawn.

the class SpamHandler method checkMentionCount.

public static boolean checkMentionCount(CommandObject command) {
    IMessage message = command.message.get();
    GuildConfig guildconfig = command.guild.config;
    IUser author = command.user.get();
    List<IRole> oldRoles = command.user.roles;
    IGuild guild = command.guild.get();
    List<IChannel> channels = command.guild.getChannelsByType(ChannelSetting.IGNORE_SPAM);
    if (channels.contains(command.channel.get()))
        return false;
    if (GuildHandler.testForPerms(command, Permissions.MENTION_EVERYONE))
        return false;
    if (message.toString().contains("@everyone") || message.toString().contains("@here")) {
        return false;
    }
    if (guildconfig.maxMentions) {
        if (message.getMentions().size() > 8) {
            RequestHandler.deleteMessage(message);
            int i = 0;
            boolean offenderFound = false;
            for (OffenderObject o : guildconfig.getOffenders()) {
                if (author.getLongID() == o.getID()) {
                    guildconfig.addOffence(o.getID());
                    command.guild.sendDebugLog(command, "STOP_MASS_MENTIONS", "OFFENCE_ADDED", message.getMentions().size() + " Mentions");
                    offenderFound = true;
                    i++;
                    if (o.getCount() >= Globals.maxWarnings) {
                        String report = "> %s has been muted for repeat offences of spamming mentions.";
                        RequestHandler.roleManagement(author, guild, guildconfig.getMutedRoleID(), true);
                        command.guild.sendDebugLog(command, "STOP_MASS_MENTIONS", "MUTE", o.getCount() + " Offences");
                        command.client.get().getDispatcher().dispatch(new UserRoleUpdateEvent(guild, author, oldRoles, command.user.get().getRolesForGuild(guild)));
                        // add strike in modnote
                        command.user.getProfile(command.guild).addSailModNote(String.format(report, author.mention()), command, false);
                        // send admin notification
                        RequestHandler.sendMessage(String.format(report, author.mention()), command.channel.get());
                    }
                }
            }
            if (!offenderFound) {
                guildconfig.addOffender(new OffenderObject(author.getLongID()));
            }
            String response = "> <mentionAdmin>, " + author.mention() + "  has attempted to post more than " + guildconfig.getMaxMentionLimit() + " Mentions in a single message in " + command.channel.mention + ".";
            IRole roleToMention = command.guild.getRoleByID(guildconfig.getRoleToMentionID());
            if (roleToMention != null) {
                response = response.replaceAll("<mentionAdmin>", roleToMention.mention());
            } else {
                response = response.replaceAll("<mentionAdmin>", "Admin");
            }
            RequestHandler.sendMessage(response, command.channel.get());
            return true;
        }
    }
    return false;
}
Also used : UserRoleUpdateEvent(sx.blah.discord.handle.impl.events.guild.member.UserRoleUpdateEvent) OffenderObject(com.github.vaerys.objects.OffenderObject) GuildConfig(com.github.vaerys.pogos.GuildConfig)

Example 2 with GuildConfig

use of com.github.vaerys.pogos.GuildConfig in project DiscordSailv2 by Vaerys-Dawn.

the class TimerHandler method dailyMessageHandler.

private static void dailyMessageHandler(TimedEvent event) {
    ZonedDateTime timeNow = ZonedDateTime.now(ZoneOffset.UTC);
    DayOfWeek day = timeNow.getDayOfWeek();
    logger.info("Running Daily tasks for " + day);
    Random random = new Random();
    for (GuildObject task : Globals.getGuilds()) {
        GuildConfig guildconfig = task.config;
        // do decay
        GuildHandler.dailyTask(task);
        // reset offenders
        task.resetOffenders();
        // getToggles general channel
        IChannel generalChannel = task.getChannelByType(ChannelSetting.GENERAL);
        // do daily messages
        if (generalChannel != null && guildconfig.dailyMessage) {
            DailyMessage finalMessage;
            List<DailyMessage> messages;
            if (event != null && event.doSpecialMessages() && event.getMessagesDay(day).size() != 0) {
                messages = event.getMessagesDay(day);
            } else {
                messages = new ArrayList<>(Globals.getDailyMessages().getDailyMessages(day));
                messages.add(Globals.getDailyMessage(day));
            }
            int randomMessage = random.nextInt(messages.size());
            finalMessage = messages.get(randomMessage);
            task.config.setLastDailyMessage(finalMessage);
            CommandObject command = new CommandObject(task, generalChannel);
            RequestHandler.sendMessage(finalMessage.getContents(command), generalChannel);
        }
    }
}
Also used : CommandObject(com.github.vaerys.commands.CommandObject) DayOfWeek(java.time.DayOfWeek) GuildObject(com.github.vaerys.masterobjects.GuildObject) IChannel(sx.blah.discord.handle.obj.IChannel) ZonedDateTime(java.time.ZonedDateTime) GuildConfig(com.github.vaerys.pogos.GuildConfig)

Example 3 with GuildConfig

use of com.github.vaerys.pogos.GuildConfig in project DiscordSailv2 by Vaerys-Dawn.

the class EnterComp method execute.

@Override
public String execute(String args, CommandObject command) {
    GuildConfig guildconfig = command.guild.config;
    IMessage message = command.message.get();
    IUser author = command.user.get();
    if (guildconfig.compEntries) {
        String fileName;
        String fileUrl;
        if (message.getAttachments().size() > 0) {
            List<IMessage.Attachment> attatchments = message.getAttachments();
            IMessage.Attachment a = attatchments.get(0);
            fileName = a.getFilename();
            fileUrl = a.getUrl();
        } else if (!args.isEmpty()) {
            fileName = author.getName() + "'s Entry";
            fileUrl = args;
        } else {
            return "> Missing a File or Image link to enter into the competition.";
        }
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yy - HH:mm:ss");
        Calendar cal = Calendar.getInstance();
        command.guild.competition.newEntry(new CompObject(author.getDisplayName(command.guild.get()), author.getLongID(), fileName, fileUrl, dateFormat.format(cal.getTime())));
        return "> Thank you " + author.getDisplayName(command.guild.get()) + " For entering the Competition.";
    } else {
        return "> Competition Entries are closed.";
    }
}
Also used : GuildConfig(com.github.vaerys.pogos.GuildConfig) IMessage(sx.blah.discord.handle.obj.IMessage) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Calendar(java.util.Calendar) IUser(sx.blah.discord.handle.obj.IUser) CompObject(com.github.vaerys.objects.CompObject) SimpleDateFormat(java.text.SimpleDateFormat)

Example 4 with GuildConfig

use of com.github.vaerys.pogos.GuildConfig in project DiscordSailv2 by Vaerys-Dawn.

the class SetupBack method execute.

@Override
public String execute(String args, CommandObject command) {
    GuildConfig config = command.guild.config;
    if (!SetupHandler.isRunningSetup(command.guild))
        return "> You aren't running setup you nincompoop.";
    // check if out of bounds.
    try {
        SetupStage prevStage = SetupStage.getPrevStage(command.guild.config.setupStage);
        if (prevStage == SetupStage.SETUP_MODULES && command.guild.config.setupStage == SetupStage.SETUP_MODULES) {
            return "> You are already *on* the first step you pillock";
        }
        SetupHandler.setSetupStage(command, prevStage);
        return "> Going back a step.";
    } catch (ArrayIndexOutOfBoundsException e) {
        // stop them from actually breaking shit...
        config.setupStage = SetupStage.SETUP_UNSET;
        return "> `ERROR: ArrayIndexOutOfBoundsException`... *cough*\n" + "You broke it. Now I have to cancel the setup because of you. This shouldn't have even been possible. *angry bot noises*";
    }
}
Also used : SetupStage(com.github.vaerys.handlers.SetupHandler.SetupStage) GuildConfig(com.github.vaerys.pogos.GuildConfig)

Example 5 with GuildConfig

use of com.github.vaerys.pogos.GuildConfig in project DiscordSailv2 by Vaerys-Dawn.

the class SetupNext method execute.

@Override
public String execute(String args, CommandObject command) {
    GuildConfig config = command.guild.config;
    if (!SetupHandler.isRunningSetup(command.guild))
        return "> You aren't running setup you nincompoop.";
    // check if out of bounds.
    try {
        // get next ordinal value
        SetupStage next = SetupStage.values()[config.setupStage.ordinal() + 1];
        if (next == SetupStage.SETUP_COMPLETE) {
            config.setupStage = SetupStage.SETUP_COMPLETE;
            return "> Congratulations! You're all done. Everything should be perfectly set up just the way you want it.";
        }
        // move to next stage
        SetupHandler.setSetupStage(command, next);
    } catch (ArrayIndexOutOfBoundsException e) {
        // stop them from actually breaking shit...
        config.setupStage = SetupStage.SETUP_COMPLETE;
        return "> Congratulations! You're all done. Everything should be perfectly set up just the way you want it.";
    }
    // "log" step change.
    SetupHandler.setSetupStage(command, config.setupStage);
    return null;
}
Also used : SetupStage(com.github.vaerys.handlers.SetupHandler.SetupStage) GuildConfig(com.github.vaerys.pogos.GuildConfig)

Aggregations

GuildConfig (com.github.vaerys.pogos.GuildConfig)7 SetupStage (com.github.vaerys.handlers.SetupHandler.SetupStage)2 CommandObject (com.github.vaerys.commands.CommandObject)1 GuildObject (com.github.vaerys.masterobjects.GuildObject)1 CompObject (com.github.vaerys.objects.CompObject)1 OffenderObject (com.github.vaerys.objects.OffenderObject)1 ProfileObject (com.github.vaerys.objects.ProfileObject)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 DayOfWeek (java.time.DayOfWeek)1 ZonedDateTime (java.time.ZonedDateTime)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 UserRoleUpdateEvent (sx.blah.discord.handle.impl.events.guild.member.UserRoleUpdateEvent)1 IChannel (sx.blah.discord.handle.obj.IChannel)1 IMessage (sx.blah.discord.handle.obj.IMessage)1 IUser (sx.blah.discord.handle.obj.IUser)1