Search in sources :

Example 6 with EventSubscriber

use of sx.blah.discord.api.events.EventSubscriber 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 7 with EventSubscriber

use of sx.blah.discord.api.events.EventSubscriber 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 8 with EventSubscriber

use of sx.blah.discord.api.events.EventSubscriber in project DiscordSailv2 by Vaerys-Dawn.

the class CreatorHandler method creatorCommands.

@EventSubscriber
public void creatorCommands(MessageReceivedEvent event) {
    if (event.getAuthor().getLongID() != Globals.creatorID)
        return;
    List<Command> commands;
    CommandObject command = new CommandObject(event.getMessage());
    if (event.getChannel().isPrivate()) {
        commands = new ArrayList<>(Globals.getCreatorCommands(true));
    } else {
        commands = new ArrayList<>(Globals.getCreatorCommands(false));
    }
    String message = event.getMessage().getContent();
    for (Command c : commands) {
        if (c.isCall(message, command)) {
            String args = c.getArgs(message, command);
            RequestHandler.sendMessage(c.execute(args, command), command.channel.get());
            MessageHandler.handleLogging(command, c, args);
            return;
        }
    }
}
Also used : CommandObject(com.github.vaerys.commands.CommandObject) Command(com.github.vaerys.templates.Command) EventSubscriber(sx.blah.discord.api.events.EventSubscriber)

Example 9 with EventSubscriber

use of sx.blah.discord.api.events.EventSubscriber in project DiscordSailv2 by Vaerys-Dawn.

the class CreatorHandler method restart.

@EventSubscriber
public void restart(MessageReceivedEvent event) {
    CommandObject command = new CommandObject(event.getMessage());
    Restart restart = new Restart();
    if (restart.isCall(event.getMessage().getContent(), command)) {
        List<Long> auth = new LinkedList<>();
        try {
            List<String> toParse = FileHandler.readFromFile(Constants.FILE_AUTH_TO_RESTART);
            auth.addAll(toParse.stream().map(Long::parseUnsignedLong).collect(Collectors.toList()));
        } catch (NumberFormatException e) {
        // do nothing
        }
        auth.add(Globals.creatorID);
        if (auth.contains(event.getAuthor().getLongID())) {
            restart.execute("", command);
            return;
        }
    }
}
Also used : CommandObject(com.github.vaerys.commands.CommandObject) Restart(com.github.vaerys.commands.creator.Restart) LinkedList(java.util.LinkedList) EventSubscriber(sx.blah.discord.api.events.EventSubscriber)

Example 10 with EventSubscriber

use of sx.blah.discord.api.events.EventSubscriber in project DiscordSailv2 by Vaerys-Dawn.

the class GuildCreateListener method onGuildCreateEvent.

@EventSubscriber
public void onGuildCreateEvent(GuildCreateEvent event) {
    IGuild guild = event.getGuild();
    long guildID = guild.getLongID();
    logger.debug("Starting Loading process for Guild with ID: " + guildID);
    if (new File(Utility.getDirectory(guildID)).exists()) {
        PatchHandler.guildPatches(guild);
    }
    FileHandler.createDirectory(Utility.getDirectory(guildID));
    FileHandler.createDirectory(Utility.getDirectory(guildID, true));
    FileHandler.createDirectory(Utility.getGuildImageDir(guildID));
    FileHandler.initFile(Utility.getFilePath(guildID, Constants.FILE_INFO));
    GuildObject guildObject = new GuildObject(guild);
    Globals.initGuild(guildObject);
    logger.info("Finished Loading Guild With ID: " + guildID);
}
Also used : GuildObject(com.github.vaerys.masterobjects.GuildObject) IGuild(sx.blah.discord.handle.obj.IGuild) File(java.io.File) EventSubscriber(sx.blah.discord.api.events.EventSubscriber)

Aggregations

EventSubscriber (sx.blah.discord.api.events.EventSubscriber)18 IMessage (sx.blah.discord.handle.obj.IMessage)6 CommandObject (com.github.vaerys.commands.CommandObject)5 IGuild (sx.blah.discord.handle.obj.IGuild)3 GuildObject (com.github.vaerys.masterobjects.GuildObject)2 UserObject (com.github.vaerys.masterobjects.UserObject)2 ArrayList (java.util.ArrayList)2 GuildSettings (com.cloudcraftgaming.discal.api.object.GuildSettings)1 Restart (com.github.vaerys.commands.creator.Restart)1 LogObject (com.github.vaerys.objects.LogObject)1 Command (com.github.vaerys.templates.Command)1 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)1 AlmanaxCommand (commands.classic.AlmanaxCommand)1 LanguageCommand (commands.config.LanguageCommand)1 RSSCommand (commands.config.RSSCommand)1 ServerCommand (commands.config.ServerCommand)1 TwitterCommand (commands.config.TwitterCommand)1 Guild (data.Guild)1 Language (enums.Language)1 AlmanaxCalendar (finders.AlmanaxCalendar)1