Search in sources :

Example 1 with CommandObject

use of com.github.vaerys.commands.CommandObject 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 2 with CommandObject

use of com.github.vaerys.commands.CommandObject in project DiscordSailv2 by Vaerys-Dawn.

the class SettingsStage method stepText.

@Override
public void stepText(CommandObject command) {
    StringHandler output = new StringHandler();
    output.append("Next step is to pick which settings you want to use.\n").append("There's a lot of settings in modules, and those will be set there.\n").append("Here's a list of the settings that aren't tied to any specific module.\n");
    // Get the settings and modules.
    List<GuildToggle> globalToggles = ToggleInit.getToggles(false);
    List<GuildToggle> modules = ToggleInit.getToggles(true);
    // Sort settings
    globalToggles.sort(Comparator.comparing(GuildToggle::name));
    // Init additional vars
    List<String> enabled = new ArrayList<>();
    List<String> disabled = new ArrayList<>();
    String format = "\t> **%s** - %s\n";
    // skip debug mode after it's defaulted to off:
    if (!new DebugMode().getDefault()) {
        globalToggles.removeIf(t -> t.name() == SAILType.DEBUG_MODE);
    }
    // Filter toggles that are not part of modules.
    List<SAILType> types = new LinkedList<>();
    modules.forEach(t -> types.addAll(t.settings.stream().map(s -> s.name()).collect(Collectors.toList())));
    ListIterator iterator = globalToggles.listIterator();
    while (iterator.hasNext()) {
        GuildToggle toggle = (GuildToggle) iterator.next();
        if (types.contains(toggle.name())) {
            // Is part of a module, remove from list
            iterator.remove();
        } else {
            // is not, get extra information...
            if (toggle.enabled(command.guild.config))
                enabled.add(toggle.name().toString());
            else
                disabled.add(toggle.name().toString());
            // append to list of things.
            output.appendFormatted(format, toggle.name().toString(), toggle.shortDesc(command));
        }
    }
    // Send message
    output.append("\nYou can switch settings on and off with **" + Command.get(Toggle.class).getCommand(command) + "** and get more info on each setting with **" + Command.get(HelpSettings.class).getCommand(command) + "**.");
    // Append additional enabled/disabled state info.
    XEmbedBuilder embed = new XEmbedBuilder(command);
    embed.withTitle("Global Settings");
    embed.appendField("Enabled", "```" + Utility.listFormatter(enabled, true) + "```", false);
    embed.appendField("Disabled", "```" + Utility.listFormatter(disabled, true) + "```", false);
    RequestHandler.sendEmbedMessage(output.toString(), embed, command.channel);
}
Also used : ToggleInit(com.github.vaerys.guildtoggles.ToggleInit) XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) java.util(java.util) CommandObject(com.github.vaerys.commands.CommandObject) HelpSettings(com.github.vaerys.commands.help.HelpSettings) DebugMode(com.github.vaerys.guildtoggles.toggles.DebugMode) RequestHandler(com.github.vaerys.handlers.RequestHandler) SAILType(com.github.vaerys.enums.SAILType) Toggle(com.github.vaerys.commands.admin.Toggle) SetupHandler(com.github.vaerys.handlers.SetupHandler) Collectors(java.util.stream.Collectors) GuildToggle(com.github.vaerys.templates.GuildToggle) StringHandler(com.github.vaerys.handlers.StringHandler) Command(com.github.vaerys.templates.Command) Utility(com.github.vaerys.main.Utility) XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) GuildToggle(com.github.vaerys.templates.GuildToggle) DebugMode(com.github.vaerys.guildtoggles.toggles.DebugMode) StringHandler(com.github.vaerys.handlers.StringHandler) SAILType(com.github.vaerys.enums.SAILType)

Example 3 with CommandObject

use of com.github.vaerys.commands.CommandObject in project DiscordSailv2 by Vaerys-Dawn.

the class AnnotationListener method onMessageReceivedEvent.

@EventSubscriber
public void onMessageReceivedEvent(MessageReceivedEvent event) {
    if (!Globals.isReady)
        return;
    try {
        if (event.getAuthor().isBot())
            return;
        CommandObject command = new CommandObject(event.getMessage());
        // Set Console Response Channel.
        if (command.user.get().equals(command.client.creator)) {
            Globals.consoleMessageCID = command.channel.longID;
        }
        command.guild.handleWelcome(command);
        // message and command handling
        new MessageHandler(command.message.get().getContent(), command, event.getChannel().isPrivate());
    } catch (Exception e) {
        String errorPos = "";
        for (StackTraceElement s : e.getStackTrace()) {
            if (s.toString().contains("com.github.vaerys")) {
                errorPos = s.toString();
                break;
            }
        }
        StringBuilder builder = new StringBuilder();
        builder.append("> I caught an Error, Please send this Error message and the message that caused this error " + "to my **Direct Messages** so my developer can look at it and try to solve the issue.\n```\n");
        builder.append(e.getClass().getName());
        builder.append(": " + e.getMessage());
        if (!errorPos.isEmpty()) {
            builder.append("\n" + Constants.PREFIX_INDENT + "at " + errorPos);
        }
        builder.append("```");
        RequestHandler.sendMessage(builder.toString(), event.getChannel());
        Globals.addToLog(new LogObject("ERROR", "MESSAGE_HANDLER", event.getMessage().getContent(), event.getChannel().getLongID(), event.getAuthor().getLongID(), event.getMessageID(), event.getGuild().getLongID()));
        Utility.sendStack(e);
    }
}
Also used : CommandObject(com.github.vaerys.commands.CommandObject) LogObject(com.github.vaerys.objects.LogObject) EventSubscriber(sx.blah.discord.api.events.EventSubscriber)

Example 4 with CommandObject

use of com.github.vaerys.commands.CommandObject in project DiscordSailv2 by Vaerys-Dawn.

the class AnnotationListener method onReactionAddEvent.

@EventSubscriber
public void onReactionAddEvent(ReactionAddEvent event) {
    if (event.getUser().isBot()) {
        return;
    }
    ReactionEmoji x = Utility.getReaction("x");
    ReactionEmoji pin = Utility.getReaction(Constants.EMOJI_ADD_PIN);
    ReactionEmoji thumbsUp = Utility.getReaction(Constants.EMOJI_APPROVE);
    ReactionEmoji thumbsDown = Utility.getReaction(Constants.EMOJI_DISAPPROVE);
    ReactionEmoji heart = Utility.getReaction(Constants.EMOJI_LIKE_PIN);
    ReactionEmoji remove = Utility.getReaction(Constants.EMOJI_REMOVE_PIN);
    ReactionEmoji emoji = event.getReaction().getEmoji();
    if (emoji == null)
        return;
    IMessage message = event.getMessage();
    if (message == null)
        message = event.getChannel().getMessageByID(event.getMessageID());
    CommandObject object = new CommandObject(message);
    UserObject pinner = new UserObject(event.getUser(), object.guild);
    UserObject owner = new UserObject(event.getAuthor(), object.guild);
    // do only on server channels
    if (!event.getChannel().isPrivate() && emoji.isUnicode()) {
        // if is x and can bypass
        if (emoji.equals(remove))
            ArtHandler.unPin(object);
        if (emoji.equals(x) && GuildHandler.testForPerms(object, Permissions.MANAGE_MESSAGES) && object.client.bot.longID == object.user.longID)
            RequestHandler.deleteMessage(object.message);
        // if is pushpin
        if (emoji.equals(pin))
            ArtHandler.pinMessage(object, pinner, owner);
        // if is thumbsup or thumbs down and is creator.
        if (emoji.equals(thumbsUp) || emoji.equals(thumbsDown))
            QueueHandler.reactionAdded(object, event.getReaction());
        // if is hear and is pinned then give xp
        if (emoji.equals(heart))
            ArtHandler.pinLiked(object, pinner, owner);
    // do only within Direct messages
    } else if (event.getChannel().isPrivate() && emoji.isUnicode()) {
        // if anyone uses x
        if (emoji.equals(x) && object.client.bot.longID == object.user.longID) {
            RequestHandler.deleteMessage(message);
        }
    }
}
Also used : CommandObject(com.github.vaerys.commands.CommandObject) IMessage(sx.blah.discord.handle.obj.IMessage) UserObject(com.github.vaerys.masterobjects.UserObject) ReactionEmoji(sx.blah.discord.handle.impl.obj.ReactionEmoji) EventSubscriber(sx.blah.discord.api.events.EventSubscriber)

Example 5 with CommandObject

use of com.github.vaerys.commands.CommandObject in project DiscordSailv2 by Vaerys-Dawn.

the class Utility method getUser.

public static UserObject getUser(CommandObject command, String args, boolean doContains, boolean hasProfile) {
    if (args != null && !args.isEmpty()) {
        IUser user = null;
        IUser conUser = null;
        String toTest;
        if (args.split(" ").length != 1) {
            toTest = escapeRegex(args);
        } else {
            toTest = escapeRegex(args).replace("_", "[_| ]");
        }
        List<IUser> guildUsers = command.guild.getUsers();
        guildUsers.sort(Comparator.comparing(o -> o.getRolesForGuild(command.guild.get()).size()));
        Collections.reverse(guildUsers);
        for (IUser u : guildUsers) {
            if (user != null) {
                break;
            }
            try {
                UserObject object = new UserObject(u, command.guild, true);
                if (hasProfile) {
                    ProfileObject profile = object.getProfile(command.guild);
                    if (profile == null || profile.isEmpty())
                        continue;
                }
                if ((u.getName() + "#" + u.getDiscriminator()).matches("(?i)" + toTest)) {
                    user = u;
                }
                if (u.getName().matches("(?i)" + toTest) && user == null) {
                    user = u;
                }
                String displayName = u.getDisplayName(command.guild.get());
                if (displayName.matches("(?i)" + toTest) && user == null) {
                    user = u;
                }
                if (doContains && conUser == null) {
                    if (u.getName().matches("(?i).*" + toTest + ".*")) {
                        conUser = u;
                    }
                    if (displayName.matches("(?i).*" + toTest + ".*") && conUser == null) {
                        conUser = u;
                    }
                }
            } catch (PatternSyntaxException e) {
            // continue.
            }
        }
        UserObject userObject = null;
        try {
            long uID = Long.parseLong(args);
            return new UserObject(uID, command.guild);
        } catch (NumberFormatException e) {
            if (command.message.get().getMentions().size() > 0) {
                user = command.message.get().getMentions().get(0);
            }
        }
        if (user == null && doContains) {
            user = conUser;
        }
        if (user != null) {
            userObject = new UserObject(user, command.guild);
        }
        return userObject;
    }
    return null;
}
Also used : com.github.vaerys.objects(com.github.vaerys.objects) java.util(java.util) RequestHandler(com.github.vaerys.handlers.RequestHandler) GuildObject(com.github.vaerys.masterobjects.GuildObject) ReactionEmoji(sx.blah.discord.handle.impl.obj.ReactionEmoji) URL(java.net.URL) ZonedDateTime(java.time.ZonedDateTime) ChannelSetting(com.github.vaerys.enums.ChannelSetting) LoggerFactory(org.slf4j.LoggerFactory) SAILType(com.github.vaerys.enums.SAILType) GuildHandler(com.github.vaerys.handlers.GuildHandler) StringUtils(org.apache.commons.lang3.StringUtils) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) CommandObject(com.github.vaerys.commands.CommandObject) Logger(org.slf4j.Logger) PatternSyntaxException(java.util.regex.PatternSyntaxException) MalformedURLException(java.net.MalformedURLException) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) EmojiManager(com.vdurmont.emoji.EmojiManager) sx.blah.discord.handle.obj(sx.blah.discord.handle.obj) Stream(java.util.stream.Stream) StringHandler(com.github.vaerys.handlers.StringHandler) UserObject(com.github.vaerys.masterobjects.UserObject) Command(com.github.vaerys.templates.Command) Emoji(com.vdurmont.emoji.Emoji) Pattern(java.util.regex.Pattern) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) UserObject(com.github.vaerys.masterobjects.UserObject) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Aggregations

CommandObject (com.github.vaerys.commands.CommandObject)26 Collectors (java.util.stream.Collectors)13 SAILType (com.github.vaerys.enums.SAILType)12 ChannelSetting (com.github.vaerys.enums.ChannelSetting)11 Utility (com.github.vaerys.main.Utility)11 Command (com.github.vaerys.templates.Command)10 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)9 List (java.util.List)9 Permissions (sx.blah.discord.handle.obj.Permissions)9 RequestHandler (com.github.vaerys.handlers.RequestHandler)7 GuildHandler (com.github.vaerys.handlers.GuildHandler)6 ArrayList (java.util.ArrayList)6 UserObject (com.github.vaerys.masterobjects.UserObject)5 SubCommandObject (com.github.vaerys.objects.SubCommandObject)5 EventSubscriber (sx.blah.discord.api.events.EventSubscriber)5 GuildObject (com.github.vaerys.masterobjects.GuildObject)4 ZonedDateTime (java.time.ZonedDateTime)4 java.util (java.util)4 IChannel (sx.blah.discord.handle.obj.IChannel)4 IRole (sx.blah.discord.handle.obj.IRole)4