Search in sources :

Example 1 with IMessage

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

the class CharacterScout 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() {
    ScoutMasterParser smp = new ScoutMasterParser();
    if (!SIMPLE_MESSAGE) {
        scoutMenu.withAuthorName(SELECTED_BANNER.getBannerName());
        setupScoutMenu();
        if (!generateImage || IMAGE_DISABLED)
            scoutMenu.appendField("- Scout Result -", characterString, false);
        scoutMenu.withDesc(smp.getQuote());
        scoutMenu.withAuthorIcon(new GitHubImage("images/System/Scout_Icon.png").getURL());
        scoutMenu.withColor(244, 233, 167);
        scoutMenu.withThumbnail(smp.getImage(highestRarity));
        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();
        simpleMessage += smp.getQuote() + "\n";
        if (!generateImage || IMAGE_DISABLED) {
            simpleMessage += "**- Scout Result -**" + "\n";
            simpleMessage += characterString;
        }
        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 : ScoutMasterParser(io.github.spugn.Sargo.XMLParsers.ScoutMasterParser) 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 2 with IMessage

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

the class TicketScout 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) {
        setupScoutMenu();
        if (!generateImage || IMAGE_DISABLED)
            scoutMenu.appendField("- Weapon Result -", itemString, false);
        scoutMenu.withAuthorIcon(new GitHubImage("images/System/Scout_Icon.png").getURL());
        scoutMenu.withColor(255, 255, 255);
        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()) + " | " + userTotalScouts + " Total Ticket Scouts");
        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 {
        setupScoutMenu();
        if (!generateImage || IMAGE_DISABLED) {
            simpleMessage += "**- Weapon Result -**" + "\n";
            simpleMessage += itemString;
        }
        simpleMessage += (CHANNEL.getGuild().getUserByID(Long.parseLong(DISCORD_ID)).getName() + "#" + CHANNEL.getGuild().getUserByID(Long.parseLong(DISCORD_ID)).getDiscriminator()) + " | " + userTotalScouts + " Total Ticket Scouts";
        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;
        }
    }
    USER.upgradeExchangeSwords();
    USER.saveData();
    deleteTempDirectory();
}
Also used : WarningMessage(io.github.spugn.Sargo.Objects.WarningMessage) 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 3 with IMessage

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

the class DevCommand method moduleReload.

private void moduleReload(MessageReceivedEvent event) {
    IMessage msg = Message.sendMessage("Reloading DisCal! This may take a moment!", event);
    for (IShard s : msg.getClient().getShards()) {
        s.logout();
        s.login();
    }
    Message.sendMessage("DisCal successfully reloaded!", event);
}
Also used : IShard(sx.blah.discord.api.IShard) IMessage(sx.blah.discord.handle.obj.IMessage)

Example 4 with IMessage

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

the class DevCommand method moduleEval.

@SuppressWarnings("all")
private void moduleEval(MessageReceivedEvent event) {
    IGuild guild = event.getGuild();
    IUser user = event.getAuthor();
    IMessage message = event.getMessage();
    IDiscordClient client = event.getClient();
    IChannel channel = event.getChannel();
    String input = message.getContent().substring(message.getContent().indexOf("eval") + 5).replaceAll("`", "");
    Object o = null;
    factory.put("guild", guild);
    factory.put("channel", channel);
    factory.put("user", user);
    factory.put("message", message);
    factory.put("command", this);
    factory.put("client", client);
    factory.put("builder", new EmbedBuilder());
    factory.put("cUser", client.getOurUser());
    try {
        o = factory.eval(input);
    } catch (Exception ex) {
        EmbedBuilder em = new EmbedBuilder();
        em.withAuthorIcon(guild.getIconURL());
        em.withAuthorName("Error");
        em.withDesc(ex.getMessage());
        em.withFooterText("Eval failed");
        em.withColor(56, 138, 237);
        Message.sendMessage(em.build(), channel);
        return;
    }
    EmbedBuilder em = new EmbedBuilder();
    em.withAuthorIcon(guild.getIconURL());
    em.withAuthorName("Success!");
    em.withColor(56, 138, 237);
    em.withTitle("Evaluation output.");
    em.withDesc(o == null ? "No output, object is null" : o.toString());
    em.appendField("Input", "```java\n" + input + "\n```", false);
    em.withFooterText("Eval successful!");
    Message.sendMessage(em.build(), channel);
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IChannel(sx.blah.discord.handle.obj.IChannel) IMessage(sx.blah.discord.handle.obj.IMessage) IUser(sx.blah.discord.handle.obj.IUser) IGuild(sx.blah.discord.handle.obj.IGuild) IDiscordClient(sx.blah.discord.api.IDiscordClient) DiscordException(sx.blah.discord.util.DiscordException)

Example 5 with IMessage

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

the class AnnouncementCreator method init.

// Functionals
/**
 * Initiates the creator for the guild involved.
 * @param e The event received upon init.
 * @return A new Announcement.
 */
public Announcement init(MessageReceivedEvent e, GuildSettings settings) {
    if (!hasAnnouncement(e.getGuild().getLongID())) {
        Announcement a = new Announcement(e.getGuild().getLongID());
        a.setAnnouncementChannelId(e.getChannel().getStringID());
        if (PermissionChecker.botHasMessageManagePerms(e)) {
            IMessage msg = Message.sendMessage(AnnouncementMessageFormatter.getFormatAnnouncementEmbed(a, settings), MessageManager.getMessage("Creator.Announcement.Create.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)

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