Search in sources :

Example 11 with IChannel

use of sx.blah.discord.handle.obj.IChannel in project DiscordSailv2 by Vaerys-Dawn.

the class SetupHandler method handleCommand.

/**
 * Handle commands in the Setup Mode DMs.
 *
 * @param command The {@link CommandObject} associated with this setup.
 * @param args    The contents of the message sent.
 * @return false if command isn't run, otherwise true.
 */
private static boolean handleCommand(CommandObject command, String args) {
    List<Command> commands = Globals.getSetupCommands();
    IChannel currentChannel = command.channel.get();
    String commandArgs;
    for (Command c : commands) {
        if (c.isCall(args, command)) {
            commandArgs = c.getArgs(args, command);
            // log command
            MessageHandler.handleLogging(command, c, commandArgs);
            if (c.requiresArgs && (commandArgs == null || commandArgs.isEmpty())) {
                RequestHandler.sendMessage(Utility.getCommandInfo(c, command), currentChannel);
                return true;
            }
            RequestBuffer.request(() -> command.channel.get().setTypingStatus(true)).get();
            String response = c.execute(commandArgs, command);
            RequestHandler.sendMessage(response, currentChannel);
            RequestBuffer.request(() -> command.channel.get().setTypingStatus(false)).get();
            return true;
        }
    }
    return false;
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) Command(com.github.vaerys.templates.Command)

Example 12 with IChannel

use of sx.blah.discord.handle.obj.IChannel 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 13 with IChannel

use of sx.blah.discord.handle.obj.IChannel in project DiscordSailv2 by Vaerys-Dawn.

the class TimerHandler method reportHandling.

private static void reportHandling(GuildObject task) {
    List<UserRateObject> offenders = task.getRateLimiting();
    IRole muteRole = task.getRoleByID(task.config.getMutedRoleID());
    if (muteRole == null)
        return;
    IChannel admin = task.getChannelByType(ChannelSetting.ADMIN);
    for (UserRateObject u : offenders) {
        if (u.counter - 3 > task.config.messageLimit) {
            List<IChannel> channels = u.getChannels(task);
            if (admin == null && !channels.isEmpty()) {
                admin = channels.get(channels.size() - 1);
            }
            StringHandler output = new StringHandler();
            StringHandler modNote = new StringHandler();
            IUser offender = u.getUser(task);
            long rate = u.counter - task.config.messageLimit;
            String formattedChannels = String.join(", ", channels.stream().map(channel -> channel.mention()).collect(Collectors.toList()));
            // Admin Message output
            output.append("> ").append(offender.mention());
            output.append(" Has Been muted for breaking the guild rate limit (");
            output.append(rate);
            output.append(" Over Rate)");
            if (channels.size() == 1) {
                output.append(" in ").append(channels.get(0).mention());
            } else if (channels.size() > 1) {
                output.append(" in channels: ");
                output.append(formattedChannels);
            }
            output.append(".");
            // modNote Output
            modNote.append("> Muted by Rate Limiter, ");
            modNote.append(rate).append(" Over Rate, ");
            modNote.append("Channel");
            if (channels.size() > 1)
                modNote.append("s");
            modNote.append(": ").append(formattedChannels);
            // logging
            if (task.config.deleteLogging) {
                Utility.sendLog("> **@" + offender.getName() + "#" + offender.getDiscriminator() + "** was muted for breaking rate limit.", task, true);
            }
            ProfileObject profile = task.users.getUserByID(u.getID());
            profile.addSailModNote(modNote.toString(), u.timeStamp, false);
            RequestHandler.sendMessage(output.toString(), admin);
        }
    }
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) IRole(sx.blah.discord.handle.obj.IRole) IUser(sx.blah.discord.handle.obj.IUser)

Example 14 with IChannel

use of sx.blah.discord.handle.obj.IChannel in project DiscordSailv2 by Vaerys-Dawn.

the class LoggingSetupStage method checkForGeneralLog.

private boolean checkForGeneralLog(CommandObject command) {
    IChannel channel = null;
    StringHandler output = new StringHandler();
    for (String s : serverLogChannelNames) {
        List<IChannel> genLogChannel = command.guild.get().getChannelsByName(s);
        if (genLogChannel.size() == 1) {
            channel = genLogChannel.get(0);
            break;
        } else if (genLogChannel.size() > 1) {
            output.append("I found multiple valid channels...").append("\nPick a channel from the list below: ```");
            String format = "\n%s [%s]";
            for (IChannel c : genLogChannel) {
                output.appendFormatted(format, c.getName(), c.getLongID());
            }
            output.append("\n```").append("Respond with the ID of the channel you want to use.");
        // handle this some special way
        }
    }
    if (channel == null)
        return false;
    output.append("Do you want to use " + channel.getName() + " as the general log channel?");
    RequestHandler.sendMessage(output.toString(), command.channel);
    return true;
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) StringHandler(com.github.vaerys.handlers.StringHandler)

Example 15 with IChannel

use of sx.blah.discord.handle.obj.IChannel in project DiscordSailv2 by Vaerys-Dawn.

the class JoinHandler method autoReMute.

/**
 * Automatically re-mutes users that were muted when they left and their mute timer hasnt timed out.
 *
 * @param user    The user that joined. ({@link UserObject})
 * @param content The Guild that the user joined. ({@link GuildObject})
 * @param event   The event that calls this. ({@link UserJoinEvent})
 */
public static void autoReMute(UserJoinEvent event, GuildObject content, UserObject user) {
    for (UserCountDown u : content.users.mutedUsers) {
        if (u.getID() == event.getUser().getLongID()) {
            IChannel admin = content.getChannelByType(ChannelSetting.ADMIN);
            if (admin != null) {
                RequestHandler.sendMessage("> Looks like " + user.mention() + " has returned, I have muted them again for you.", admin);
            }
            RequestHandler.roleManagement(user, content, content.config.getMutedRoleID(), true);
        }
    }
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) UserCountDown(com.github.vaerys.objects.UserCountDown)

Aggregations

IChannel (sx.blah.discord.handle.obj.IChannel)44 IGuild (sx.blah.discord.handle.obj.IGuild)7 IRole (sx.blah.discord.handle.obj.IRole)7 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)7 SQLException (java.sql.SQLException)6 IUser (sx.blah.discord.handle.obj.IUser)6 ProfileObject (com.github.vaerys.objects.ProfileObject)5 SplitFirstObject (com.github.vaerys.objects.SplitFirstObject)5 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 ArrayList (java.util.ArrayList)4 CommandObject (com.github.vaerys.commands.CommandObject)3 ChannelSetting (com.github.vaerys.enums.ChannelSetting)3 StringHandler (com.github.vaerys.handlers.StringHandler)3 UserObject (com.github.vaerys.masterobjects.UserObject)3 CCommandObject (com.github.vaerys.objects.CCommandObject)3 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)3 IOException (java.io.IOException)3 DBGuild (me.shadorc.shadbot.data.db.DBGuild)3