Search in sources :

Example 26 with IMessage

use of sx.blah.discord.handle.obj.IMessage in project BoltBot by DiscordBolt.

the class VoiceManager method reactionEvent.

/* Listeners */
@EventSubscriber
public void reactionEvent(ReactionAddEvent e) {
    if (e.getUser().equals(MusicModule.getClient().getOurUser()))
        return;
    DJ dj = getDJ(e.getGuild());
    IMessage message = e.getMessage();
    AudioTrack track = null;
    if (message.equals(dj.getNowPlayingMessage()))
        track = dj.getPlaying();
    else if (dj.getTrackMessages().containsKey(message))
        track = dj.getTrackMessages().get(message);
    if (track == null)
        return;
    switch(e.getReaction().getUnicodeEmoji().getAliases().get(0)) {
        case "black_right_pointing_double_triangle_with_vertical_bar":
            if (track.getIdentifier().equals(dj.getPlaying().getIdentifier())) {
                try {
                    skip(e.getGuild(), e.getUser(), false, 1);
                    ChannelUtil.sendMessage(e.getChannel(), e.getUser().getDisplayName(e.getGuild()) + " has voted to skip this track.");
                } catch (CommandException ex) {
                    ChannelUtil.sendMessage(e.getChannel(), ex.getMessage());
                }
            } else {
                ChannelUtil.sendMessage(e.getChannel(), e.getUser().getName() + ", You can only skip currently playing songs");
                return;
            }
            break;
        case "star":
            try {
                getDJ(e.getGuild()).starSong(track, e.getUser());
                ChannelUtil.sendMessage(e.getChannel(), e.getUser().getDisplayName(e.getGuild()) + ", successfully added the song to your selected playlist.");
            } catch (CommandException ex) {
                ChannelUtil.sendMessage(e.getChannel(), ex.getMessage());
            }
            break;
    }
}
Also used : IMessage(sx.blah.discord.handle.obj.IMessage) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) EventSubscriber(sx.blah.discord.api.events.EventSubscriber)

Example 27 with IMessage

use of sx.blah.discord.handle.obj.IMessage in project S-argo by Expugn.

the class WeaponScout method displayAndSave.

/**
 * Displays the scout results to the channel where the command was
 * requested and save the results to the user file afterwards. If
 * the results fail to display for any reason then the user file
 * is not saved.
 */
void displayAndSave() {
    if (!SIMPLE_MESSAGE) {
        scoutMenu.withAuthorName(SELECTED_BANNER.getBannerName());
        setupScoutMenu();
        if (!generateImage || IMAGE_DISABLED)
            scoutMenu.appendField("- Weapon Result -", weaponString, false);
        scoutMenu.withAuthorIcon(new GitHubImage("images/System/Scout_Icon.png").getURL());
        scoutMenu.withColor(139, 69, 19);
        if (weapons.get(0).getRarity() == 2)
            scoutMenu.withThumbnail(new GitHubImage("images/System/Brown_Chest.png").getURL());
        else if (weapons.get(0).getRarity() == 3)
            scoutMenu.withThumbnail(new GitHubImage("images/System/Blue_Chest.png").getURL());
        else if (weapons.get(0).getRarity() == 4)
            scoutMenu.withThumbnail(new GitHubImage("images/System/Red_Chest.png").getURL());
        scoutMenu.withFooterIcon(new GitHubImage("images/System/Memory_Diamond_Icon.png").getURL());
        scoutMenu.withFooterText((CHANNEL.getGuild().getUserByID(Long.parseLong(DISCORD_ID)).getName() + "#" + CHANNEL.getGuild().getUserByID(Long.parseLong(DISCORD_ID)).getDiscriminator()) + " | " + USER.getMemoryDiamonds() + " Memory Diamonds Left");
        LOGGER.debug("Displaying Scout Result...");
        IMessage display = null;
        try {
            if (generateImage && !IMAGE_DISABLED)
                display = CHANNEL.sendFile(scoutMenu.build(), new File(tempUserDirectory + "/results.png"));
            else
                display = CHANNEL.sendMessage(scoutMenu.build());
        } catch (FileNotFoundException e) {
            CHANNEL.sendMessage(new WarningMessage("FAILED TO GENERATE IMAGE", "Unable to display scout result.").get().build());
            display.delete();
            deleteTempDirectory();
            return;
        } catch (RateLimitException e) {
            EmbedBuilder rateLimited = new WarningMessage("RATE LIMIT EXCEPTION", "Slow down on the requests!").get();
            try {
                display.edit(rateLimited.build());
            } catch (NullPointerException a) {
            // DO SOMETHING
            }
            deleteTempDirectory();
            return;
        }
    } else {
        simpleMessage += "**" + SELECTED_BANNER.getBannerName() + "**" + "\n";
        setupScoutMenu();
        if (!generateImage || IMAGE_DISABLED) {
            simpleMessage += "**- Weapon Result -**" + "\n";
            simpleMessage += weaponString;
        }
        simpleMessage += (CHANNEL.getGuild().getUserByID(Long.parseLong(DISCORD_ID)).getName() + "#" + CHANNEL.getGuild().getUserByID(Long.parseLong(DISCORD_ID)).getDiscriminator()) + " | " + USER.getMemoryDiamonds() + " Memory Diamonds Left";
        LOGGER.debug("Displaying Scout Result...");
        IMessage display = null;
        try {
            if (generateImage && !IMAGE_DISABLED) {
                display = CHANNEL.sendFile(simpleMessage, new File(tempUserDirectory + "/results.png"));
            } else {
                display = CHANNEL.sendMessage(simpleMessage);
            }
        } catch (FileNotFoundException e) {
            CHANNEL.sendMessage(new WarningMessage("FAILED TO GENERATE IMAGE", "Unable to display scout result.").get().build());
            display.delete();
            deleteTempDirectory();
            return;
        } catch (RateLimitException e) {
            EmbedBuilder rateLimited = new WarningMessage("RATE LIMIT EXCEPTION", "Slow down on the requests!").get();
            try {
                display.edit(rateLimited.build());
            } catch (NullPointerException a) {
            // DO SOMETHING
            }
            deleteTempDirectory();
            return;
        }
    }
    LOGGER.debug("Saving User Data...");
    USER.saveData();
    deleteTempDirectory();
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) RateLimitException(sx.blah.discord.util.RateLimitException) GitHubImage(io.github.spugn.Sargo.Utilities.GitHubImage) IMessage(sx.blah.discord.handle.obj.IMessage) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File)

Example 28 with IMessage

use of sx.blah.discord.handle.obj.IMessage in project DisCal-Discord-Bot by NovaFox161.

the class AnnouncementCreator method edit.

public Announcement edit(MessageReceivedEvent e, String announcementId, GuildSettings settings) {
    if (!hasAnnouncement(e.getGuild().getLongID()) && AnnouncementUtils.announcementExists(announcementId, e)) {
        Announcement edit = DatabaseManager.getManager().getAnnouncement(UUID.fromString(announcementId), e.getGuild().getLongID());
        // Copy
        Announcement a = new Announcement(edit, true);
        a.setEditing(true);
        if (PermissionChecker.botHasMessageManagePerms(e)) {
            IMessage msg = Message.sendMessage(AnnouncementMessageFormatter.getFormatAnnouncementEmbed(a, settings), MessageManager.getMessage("Creator.Announcement.Edit.Init", settings), e);
            a.setCreatorMessage(msg);
        } else {
            Message.sendMessage(MessageManager.getMessage("Creator.Notif.MANAGE_MESSAGES", settings), e);
        }
        announcements.add(a);
        return a;
    }
    return getAnnouncement(e.getGuild().getLongID());
}
Also used : Announcement(com.cloudcraftgaming.discal.api.object.announcement.Announcement) IMessage(sx.blah.discord.handle.obj.IMessage)

Example 29 with IMessage

use of sx.blah.discord.handle.obj.IMessage in project DisCal-Discord-Bot by NovaFox161.

the class CalendarCommand method moduleCancel.

private void moduleCancel(MessageReceivedEvent event, CalendarData calendarData, GuildSettings settings) {
    long guildId = event.getGuild().getLongID();
    if (CalendarCreator.getCreator().hasPreCalendar(guildId)) {
        IMessage message = CalendarCreator.getCreator().getPreCalendar(guildId).getCreatorMessage();
        Boolean editing = CalendarCreator.getCreator().getPreCalendar(guildId).isEditing();
        if (CalendarCreator.getCreator().terminate(event)) {
            if (message != null) {
                if (!editing) {
                    Message.deleteMessage(event);
                    Message.deleteMessage(CalendarCreator.getCreator().getCreatorMessage(guildId));
                } else {
                    Message.deleteMessage(event);
                    Message.deleteMessage(CalendarCreator.getCreator().getCreatorMessage(guildId));
                    CalendarCreator.getCreator().setCreatorMessage(Message.sendMessage(MessageManager.getMessage("Creator.Calendar.Cancel.Edit.Success", settings), event));
                }
            } else {
                if (!editing) {
                    Message.sendMessage(MessageManager.getMessage("Creator.Calendar.Cancel.Success", settings), event);
                } else {
                    Message.sendMessage(MessageManager.getMessage("Creator.Calendar.Cancel.Edit.Success", settings), event);
                }
            }
        } else {
            Message.sendMessage(MessageManager.getMessage("Creator.Calendar.Cancel.Failure", settings), event);
            Message.deleteMessage(event);
        }
    } else {
        if (calendarData.getCalendarId().equalsIgnoreCase("primary")) {
            Message.sendMessage(MessageManager.getMessage("Creator.Calendar.NotInit", settings), event);
        } else {
            Message.sendMessage(MessageManager.getMessage("Creator.Calendar.HasCalendar", settings), event);
        }
    }
}
Also used : IMessage(sx.blah.discord.handle.obj.IMessage)

Example 30 with IMessage

use of sx.blah.discord.handle.obj.IMessage in project DisCal-Discord-Bot by NovaFox161.

the class EventCommand method moduleRestart.

private void moduleRestart(String[] args, MessageReceivedEvent event, CalendarData calendarData, GuildSettings settings) {
    long guildId = event.getGuild().getLongID();
    IMessage msg = null;
    boolean editing = false;
    if (EventCreator.getCreator().hasPreEvent(guildId)) {
        editing = EventCreator.getCreator().getPreEvent(guildId).isEditing();
    }
    if (EventCreator.getCreator().hasCreatorMessage(guildId))
        msg = EventCreator.getCreator().getCreatorMessage(guildId);
    if (EventCreator.getCreator().terminate(event)) {
        if (msg != null) {
            Message.deleteMessage(msg);
            Message.deleteMessage(event);
        }
        if (!editing) {
            moduleCreate(args, event, calendarData, settings);
        } else {
            moduleEdit(args, event, calendarData, settings);
        }
    } else {
        Message.sendMessage(MessageManager.getMessage("Creator.Event.NotInit", settings), event);
    }
}
Also used : IMessage(sx.blah.discord.handle.obj.IMessage)

Aggregations

IMessage (sx.blah.discord.handle.obj.IMessage)46 IUser (sx.blah.discord.handle.obj.IUser)10 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)9 EventSubscriber (sx.blah.discord.api.events.EventSubscriber)6 IChannel (sx.blah.discord.handle.obj.IChannel)6 ProfileObject (com.github.vaerys.objects.ProfileObject)5 UserObject (com.github.vaerys.masterobjects.UserObject)4 ArrayList (java.util.ArrayList)4 DiscordException (sx.blah.discord.util.DiscordException)4 Announcement (com.cloudcraftgaming.discal.api.object.announcement.Announcement)3 PreEvent (com.cloudcraftgaming.discal.api.object.event.PreEvent)3 CommandObject (com.github.vaerys.commands.CommandObject)3 SplitFirstObject (com.github.vaerys.objects.SplitFirstObject)3 GitHubImage (io.github.spugn.Sargo.Utilities.GitHubImage)3 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 RateLimitException (sx.blah.discord.util.RateLimitException)3 PreCalendar (com.cloudcraftgaming.discal.api.object.calendar.PreCalendar)2 TrackLikes (com.github.vaerys.objects.TrackLikes)2