Search in sources :

Example 21 with EmbedBuilder

use of sx.blah.discord.util.EmbedBuilder in project DisCal-Discord-Bot by NovaFox161.

the class HelpCommand method getSubCommandEmbed.

private EmbedObject getSubCommandEmbed(ICommand cmd, String subCommand) {
    EmbedBuilder em = new EmbedBuilder();
    em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
    em.withAuthorName("DisCal");
    em.appendField("Command", cmd.getCommand(), true);
    em.appendField("Sub Command", subCommand, true);
    em.appendField("Usage", cmd.getCommandInfo().getSubCommands().get(subCommand), false);
    em.withFooterText("<> = required | () = optional");
    em.withUrl("https://www.cloudcraftgaming.com/discal/commands");
    em.withColor(56, 138, 237);
    return em.build();
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder)

Example 22 with EmbedBuilder

use of sx.blah.discord.util.EmbedBuilder in project DisCal-Discord-Bot by NovaFox161.

the class HelpCommand method issueCommand.

/**
 * Issues the command this Object is responsible for.
 * @param args The command arguments.
 * @param event The event received.
 * @return <code>true</code> if successful, else <code>false</code>.
 */
@Override
public Boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
    if (args.length < 1) {
        EmbedBuilder em = new EmbedBuilder();
        em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
        em.withAuthorName("DisCal");
        em.withTitle("DisCal Command Help");
        for (ICommand c : CommandExecutor.getExecutor().getCommands()) {
            if (c.getAliases().size() > 0) {
                String al = c.getAliases().toString();
                em.appendField(c.getCommand() + " " + al, c.getCommandInfo().getDescription(), true);
            } else {
                em.appendField(c.getCommand(), c.getCommandInfo().getDescription(), true);
            }
        }
        em.withFooterText("Check out the official site for more command info!");
        em.withUrl("https://www.cloudcraftgaming.com/discal/commands");
        em.withColor(56, 138, 237);
        Message.sendMessage(em.build(), event);
    } else if (args.length == 1) {
        String cmdFor = args[0];
        ICommand cmd = CommandExecutor.getExecutor().getCommand(cmdFor);
        if (cmd != null) {
            Message.sendMessage(getCommandInfoEmbed(cmd), event);
        }
    } else if (args.length == 2) {
        // Display sub command info
        String cmdFor = args[0];
        ICommand cmd = CommandExecutor.getExecutor().getCommand(cmdFor);
        if (cmd != null) {
            if (cmd.getCommandInfo().getSubCommands().containsKey(args[1].toLowerCase())) {
                Message.sendMessage(getSubCommandEmbed(cmd, args[1].toLowerCase()), event);
            } else {
                // Sub command does not exist.
                Message.sendMessage(MessageManager.getMessage("Notification.Args.InvalidSubCmd", settings), event);
            }
        }
    }
    return false;
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder)

Example 23 with EmbedBuilder

use of sx.blah.discord.util.EmbedBuilder in project DisCal-Discord-Bot by NovaFox161.

the class AnnouncementMessageFormatter method sendAnnouncementMessage.

/**
 * Sends an embed with the announcement info in a proper format.
 *
 * @param announcement The announcement to send info about.
 * @param event        the calendar event the announcement is for.
 * @param data         The BotData belonging to the guild.
 */
static void sendAnnouncementMessage(Announcement announcement, Event event, CalendarData data, GuildSettings settings) {
    EmbedBuilder em = new EmbedBuilder();
    em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
    IGuild guild = Main.client.getGuildByID(announcement.getGuildId());
    assert guild != null;
    // Set all of the stuff for embeds regardless of announcement settings
    if (settings.isBranded()) {
        em.withAuthorName(guild.getName());
    } else {
        em.withAuthorName("DisCal");
    }
    em.withTitle(MessageManager.getMessage("Embed.Announcement.Announce.Title", settings));
    EventData ed = DatabaseManager.getManager().getEventData(announcement.getGuildId(), event.getId());
    if (ed.getImageLink() != null && ImageUtils.validate(ed.getImageLink())) {
        em.withImage(ed.getImageLink());
    }
    em.withUrl(event.getHtmlLink());
    try {
        EventColor ec = EventColor.fromNameOrHexOrID(event.getColorId());
        em.withColor(ec.getR(), ec.getG(), ec.getB());
    } catch (Exception e) {
        // I dunno, color probably null.
        em.withColor(56, 138, 237);
    }
    if (!settings.usingSimpleAnnouncements()) {
        em.withFooterText(MessageManager.getMessage("Embed.Announcement.Announce.ID", "%id%", announcement.getAnnouncementId().toString(), settings));
    }
    if (announcement.isInfoOnly()) {
        // Only send info...
        em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.Info", settings), announcement.getInfo(), false);
    } else {
        // Requires all announcement data
        if (event.getSummary() != null) {
            String summary = event.getSummary();
            if (summary.length() > 250) {
                summary = summary.substring(0, 250);
                summary = summary + " (continues on Google Calendar View)";
            }
            em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.Summary", settings), summary, true);
        }
        if (event.getDescription() != null) {
            String description = event.getDescription();
            if (description.length() > 250) {
                description = description.substring(0, 250);
                description = description + " (continues on Google Calendar View)";
            }
            em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.Description", settings), description, true);
        }
        if (!settings.usingSimpleAnnouncements()) {
            em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.Date", settings), EventMessageFormatter.getHumanReadableDate(event.getStart(), settings, false), true);
            em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.Time", settings), EventMessageFormatter.getHumanReadableTime(event.getStart(), settings, false), true);
            try {
                Calendar service = CalendarAuth.getCalendarService();
                String tz = service.calendars().get(data.getCalendarAddress()).execute().getTimeZone();
                em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.TimeZone", settings), tz, true);
            } catch (Exception e1) {
                em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.TimeZone", settings), "Unknown *Error Occurred", true);
            }
        } else {
            String start = EventMessageFormatter.getHumanReadableDate(event.getStart(), settings, false) + " at " + EventMessageFormatter.getHumanReadableTime(event.getStart(), settings, false);
            try {
                Calendar service = CalendarAuth.getCalendarService();
                String tz = service.calendars().get(data.getCalendarAddress()).execute().getTimeZone();
                start = start + " " + tz;
            } catch (Exception e1) {
                start = start + " (TZ UNKNOWN/ERROR)";
            }
            em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.Start", settings), start, false);
        }
        if (event.getLocation() != null && !event.getLocation().equalsIgnoreCase("")) {
            if (event.getLocation().length() > 300) {
                String location = event.getLocation().substring(0, 300).trim() + "... (cont. on Google Cal)";
                em.appendField(MessageManager.getMessage("Embed.Event.Confirm.Location", settings), location, true);
            } else {
                em.appendField(MessageManager.getMessage("Embed.Event.Confirm.Location", settings), event.getLocation(), true);
            }
        }
        if (!settings.usingSimpleAnnouncements()) {
            em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.EventID", settings), event.getId(), false);
        }
        if (!announcement.getInfo().equalsIgnoreCase("None")) {
            em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.Info", settings), announcement.getInfo(), false);
        }
    }
    IChannel channel = null;
    try {
        channel = guild.getChannelByID(Long.valueOf(announcement.getAnnouncementChannelId()));
    } catch (Exception e) {
        Logger.getLogger().exception(null, "Failed to find announcement channel! Will auto delete announcement to prevent issue! | Announcement: " + announcement.getAnnouncementId() + " | Guild: " + announcement.getGuildId(), e, AnnouncementMessageFormatter.class, true);
    }
    if (channel == null) {
        // Channel does not exist or could not be found, automatically delete announcement to prevent issues.
        DatabaseManager.getManager().deleteAnnouncement(announcement.getAnnouncementId().toString());
        return;
    }
    Message.sendMessageAsync(em.build(), getSubscriberMentions(announcement, guild), channel);
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IChannel(sx.blah.discord.handle.obj.IChannel) Calendar(com.google.api.services.calendar.Calendar) EventColor(com.cloudcraftgaming.discal.api.enums.event.EventColor) IGuild(sx.blah.discord.handle.obj.IGuild) EventData(com.cloudcraftgaming.discal.api.object.event.EventData)

Example 24 with EmbedBuilder

use of sx.blah.discord.util.EmbedBuilder in project DisCal-Discord-Bot by NovaFox161.

the class AnnouncementCommand method moduleSubscribeRewriteArgsThree.

private void moduleSubscribeRewriteArgsThree(String[] args, MessageReceivedEvent event, GuildSettings settings) {
    IMessage message = event.getMessage();
    IGuild guild = message.getGuild();
    List<String> subscribedUsers = new ArrayList<>();
    List<String> subscribedRoles = new ArrayList<>();
    String announcementID;
    boolean updateDb;
    if (args[1].length() > 32) {
        AnnouncementCreator.getCreator().getAnnouncement(guild.getLongID());
        updateDb = true;
        announcementID = args[1];
    } else {
        updateDb = false;
        if (AnnouncementCreator.getCreator().hasAnnouncement(guild.getLongID())) {
            announcementID = AnnouncementCreator.getCreator().getAnnouncement(guild.getLongID()).getAnnouncementId().toString();
        } else {
            Message.sendMessage(MessageManager.getMessage("Creator.Announcement.Subscribe.Other.Specify", settings), event);
            return;
        }
    }
    if (AnnouncementUtils.announcementExists(announcementID, event) || !updateDb) {
        Announcement a = updateDb ? DatabaseManager.getManager().getAnnouncement(UUID.fromString(announcementID), guild.getLongID()) : AnnouncementCreator.getCreator().getAnnouncement(guild.getLongID());
        for (int i = 1; i < args.length; i++) {
            IUser u = guild.getUserByID(UserUtils.getUser(args[i].matches("<@?!?#?&?[0-9]+>") ? args[i].replaceAll("<@?!?#?&?[0-9]+>", "") : args[i], event.getGuild()));
            IRole r = guild.getRoleByID(RoleUtils.getRole(args[i].matches("<@?!?#?&?[0-9]+>") ? args[i].replaceAll("<@?!?#?&?[0-9]+>", "") : args[i], event.getGuild()));
            if (args[i].equalsIgnoreCase("everyone") || args[i].equalsIgnoreCase("here")) {
                // Here or everyone is to be subscribed...
                String men = args[i].toLowerCase();
                if (!a.getSubscriberRoleIds().contains(men)) {
                    a.getSubscriberRoleIds().add(men);
                    Message.sendMessage(MessageManager.getMessage("Creator.Announcement.Subscribe.Other.Success", "%value%", men, settings), event);
                    subscribedUsers.add(men);
                } else {
                    Message.sendMessage(MessageManager.getMessage("Creator.Announcement.Subscribe.Other.Already", "%value%", men, settings), event);
                }
            }
            if (u != null) {
                if (!a.getSubscriberUserIds().contains(u.getStringID())) {
                    subscribedUsers.add(u.getName());
                    a.getSubscriberUserIds().add(u.getStringID());
                }
            } else if (r != null) {
                if (!a.getSubscriberRoleIds().contains(r.getStringID())) {
                    subscribedRoles.add(r.getName());
                    a.getSubscriberRoleIds().add(r.getStringID());
                }
            }
        }
        EmbedBuilder em = new EmbedBuilder();
        em.withColor(EventColor.TURQUOISE.getR(), EventColor.TURQUOISE.getG(), EventColor.TURQUOISE.getB());
        em.withAuthorIcon(event.getClient().getApplicationIconURL());
        em.withAuthorName(MessageManager.getMessage("Embed.Announcement.Subscribe.Title", settings));
        em.withDesc(MessageManager.getMessage("Embed.Announcement.Subscribe.Users", "%users%", subscribedUsers.toString(), settings) + MessageUtils.lineBreak + MessageManager.getMessage("Embed.Announcement.Subscribe.Roles", "%roles%", subscribedRoles.toString(), settings));
        em.withFooterText(MessageManager.getMessage("Embed.Announcement.Subscribe.Footer", "%id%", a.getAnnouncementId().toString(), settings));
        Message.sendMessage(em.build(), event);
        if (updateDb) {
            DatabaseManager.getManager().updateAnnouncement(a);
        }
    } else {
        Message.sendMessage(MessageManager.getMessage("Creator.Announcement.CannotFind.Announcement", settings), event);
    }
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) Announcement(com.cloudcraftgaming.discal.api.object.announcement.Announcement) ArrayList(java.util.ArrayList)

Example 25 with EmbedBuilder

use of sx.blah.discord.util.EmbedBuilder in project DisCal-Discord-Bot by NovaFox161.

the class AnnouncementCommand method moduleUnsubscribeRewriteArgsThree.

private void moduleUnsubscribeRewriteArgsThree(String[] args, MessageReceivedEvent event, GuildSettings settings) {
    IMessage message = event.getMessage();
    IGuild guild = message.getGuild();
    List<String> subscribedUsers = new ArrayList<>();
    List<String> subscribedRoles = new ArrayList<>();
    String announcementID;
    boolean updateDb;
    if (args[1].length() > 32) {
        AnnouncementCreator.getCreator().getAnnouncement(guild.getLongID());
        updateDb = true;
        announcementID = args[1];
    } else {
        updateDb = false;
        if (AnnouncementCreator.getCreator().hasAnnouncement(guild.getLongID())) {
            announcementID = AnnouncementCreator.getCreator().getAnnouncement(guild.getLongID()).getAnnouncementId().toString();
        } else {
            Message.sendMessage(MessageManager.getMessage("Creator.Announcement.Unsubscribe.Other.Specify", settings), event);
            return;
        }
    }
    if (AnnouncementUtils.announcementExists(announcementID, event) || !updateDb) {
        Announcement a = updateDb ? DatabaseManager.getManager().getAnnouncement(UUID.fromString(announcementID), guild.getLongID()) : AnnouncementCreator.getCreator().getAnnouncement(guild.getLongID());
        for (int i = 1; i < args.length; i++) {
            IUser u = guild.getUserByID(UserUtils.getUser(args[i].matches("<@?!?#?&?[0-9]+>") ? args[i].replaceAll("<@?!?#?&?[0-9]+>", "") : args[i], event.getGuild()));
            IRole r = guild.getRoleByID(RoleUtils.getRole(args[i].matches("<@?!?#?&?[0-9]+>") ? args[i].replaceAll("<@?!?#?&?[0-9]+>", "") : args[i], event.getGuild()));
            if (args[i].toLowerCase().contains("everyone") || args[i].toLowerCase().contains("here")) {
                // Here or everyone is to be subscribed...
                String men = args[i].toLowerCase();
                if (a.getSubscriberRoleIds().contains(men)) {
                    a.getSubscriberRoleIds().remove(men);
                    Message.sendMessage(MessageManager.getMessage("Creator.Announcement.Unsubscribe.Other.Success", "%value%", men, settings), event);
                    subscribedUsers.add(men);
                } else {
                    Message.sendMessage(MessageManager.getMessage("Creator.Announcement.Unsubscribe.Other.Not", "%value%", men, settings), event);
                }
            }
            if (u != null) {
                if (a.getSubscriberUserIds().contains(u.getStringID())) {
                    subscribedUsers.add(u.getName());
                    a.getSubscriberUserIds().remove(u.getStringID());
                }
            } else if (r != null) {
                if (a.getSubscriberRoleIds().contains(r.getStringID())) {
                    subscribedRoles.add(r.getName());
                    a.getSubscriberRoleIds().remove(r.getStringID());
                }
            }
        }
        EmbedBuilder em = new EmbedBuilder();
        em.withColor(EventColor.TURQUOISE.getR(), EventColor.TURQUOISE.getG(), EventColor.TURQUOISE.getB());
        em.withAuthorIcon(event.getClient().getApplicationIconURL());
        em.withAuthorName(MessageManager.getMessage("Embed.Announcement.Unsubscribe.Title", settings));
        em.withDesc(MessageManager.getMessage("Embed.Announcement.Unsubscribe.Users", "%users%", subscribedUsers.toString(), settings) + MessageUtils.lineBreak + MessageManager.getMessage("Embed.Announcement.Unsubscribe.Roles", "%roles%", subscribedRoles.toString(), settings));
        em.withFooterText(MessageManager.getMessage("Embed.Announcement.Unsubscribe.Footer", "%id%", a.getAnnouncementId().toString(), settings));
        Message.sendMessage(em.build(), event);
        if (updateDb) {
            DatabaseManager.getManager().updateAnnouncement(a);
        }
    } else {
        Message.sendMessage(MessageManager.getMessage("Creator.Announcement.CannotFind.Announcement", settings), event);
    }
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) Announcement(com.cloudcraftgaming.discal.api.object.announcement.Announcement) ArrayList(java.util.ArrayList)

Aggregations

EmbedBuilder (sx.blah.discord.util.EmbedBuilder)103 IOException (java.io.IOException)19 Random (java.util.Random)17 IUser (sx.blah.discord.handle.obj.IUser)14 MissingArgumentException (me.shadorc.shadbot.exception.MissingArgumentException)13 LoadingMessage (me.shadorc.shadbot.utils.object.LoadingMessage)13 EmbedObject (sx.blah.discord.api.internal.json.objects.EmbedObject)12 JSONObject (org.json.JSONObject)11 IMessage (sx.blah.discord.handle.obj.IMessage)10 List (java.util.List)9 AbstractCommand (me.shadorc.shadbot.core.command.AbstractCommand)9 EmbedUtils (me.shadorc.shadbot.utils.embed.EmbedUtils)9 JSONException (org.json.JSONException)9 EventColor (com.cloudcraftgaming.discal.api.enums.event.EventColor)8 Utils (me.shadorc.shadbot.utils.Utils)8 IChannel (sx.blah.discord.handle.obj.IChannel)8 EventData (com.cloudcraftgaming.discal.api.object.event.EventData)7 FormatUtils (me.shadorc.shadbot.utils.FormatUtils)7 File (java.io.File)6 CommandCategory (me.shadorc.shadbot.core.command.CommandCategory)6