Search in sources :

Example 1 with EventColor

use of com.cloudcraftgaming.discal.api.enums.event.EventColor in project DisCal-Discord-Bot by NovaFox161.

the class EventCommand method moduleColor.

private void moduleColor(String[] args, MessageReceivedEvent event, GuildSettings settings) {
    long guildId = event.getGuild().getLongID();
    if (args.length == 2) {
        String value = args[1];
        if (value.equalsIgnoreCase("list") || value.equalsIgnoreCase("colors") || value.equalsIgnoreCase("colours")) {
            // TODO: Make this list pretty!!!
            StringBuilder list = new StringBuilder("All Colors: ");
            for (EventColor ec : EventColor.values()) {
                list.append(MessageUtils.lineBreak).append("Name: ").append(ec.name()).append(", ID: ").append(ec.getId());
            }
            list.append(MessageUtils.lineBreak).append(MessageUtils.lineBreak).append(MessageManager.getMessage("Creator.Event.Color.List", settings));
            if (EventCreator.getCreator().hasCreatorMessage(guildId)) {
                Message.deleteMessage(event);
                Message.deleteMessage(EventCreator.getCreator().getCreatorMessage(guildId));
                EventCreator.getCreator().setCreatorMessage(Message.sendMessage(EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(guildId), settings), list.toString().trim(), event));
            } else {
                Message.sendMessage(list.toString().trim(), event);
            }
        } else {
            if (EventCreator.getCreator().hasPreEvent(guildId)) {
                // Attempt to get color.
                if (EventColor.exists(value)) {
                    EventColor color = EventColor.fromNameOrHexOrID(value);
                    EventCreator.getCreator().getPreEvent(guildId).setColor(color);
                    if (EventCreator.getCreator().hasCreatorMessage(guildId)) {
                        Message.deleteMessage(event);
                        Message.deleteMessage(EventCreator.getCreator().getCreatorMessage(guildId));
                        EventCreator.getCreator().setCreatorMessage(Message.sendMessage(EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(guildId), settings), MessageManager.getMessage("Creator.Event.Color.Success.New", settings), event));
                    } else {
                        Message.sendMessage(MessageManager.getMessage("Creator.Event.Color.Success", "%color%", color.name(), settings), event);
                    }
                } else {
                    if (EventCreator.getCreator().hasCreatorMessage(guildId)) {
                        Message.deleteMessage(event);
                        Message.deleteMessage(EventCreator.getCreator().getCreatorMessage(guildId));
                        EventCreator.getCreator().setCreatorMessage(Message.sendMessage(EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(guildId), settings), MessageManager.getMessage("Creator.Event.Color.Invalid", settings), event));
                    } else {
                        Message.sendMessage(MessageManager.getMessage("Creator.Event.Color.Invalid", settings), event);
                    }
                }
            } else {
                Message.sendMessage(MessageManager.getMessage("Creator.Event.NotInit", settings), event);
            }
        }
    } else {
        if (EventCreator.getCreator().hasCreatorMessage(guildId)) {
            Message.deleteMessage(event);
            Message.deleteMessage(EventCreator.getCreator().getCreatorMessage(guildId));
            EventCreator.getCreator().setCreatorMessage(Message.sendMessage(EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(guildId), settings), MessageManager.getMessage("Creator.Event.Color.Specify", settings), event));
        } else {
            Message.sendMessage(MessageManager.getMessage("Creator.Event.Color.Specify", settings), event);
        }
    }
}
Also used : EventColor(com.cloudcraftgaming.discal.api.enums.event.EventColor)

Example 2 with EventColor

use of com.cloudcraftgaming.discal.api.enums.event.EventColor 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 3 with EventColor

use of com.cloudcraftgaming.discal.api.enums.event.EventColor in project DisCal-Discord-Bot by NovaFox161.

the class AnnouncementCommand method moduleColor.

private void moduleColor(String[] args, MessageReceivedEvent event, GuildSettings settings) {
    long guildId = event.getGuild().getLongID();
    if (args.length == 2) {
        String value = args[1];
        if (AnnouncementCreator.getCreator().hasAnnouncement(guildId)) {
            if (AnnouncementCreator.getCreator().getAnnouncement(guildId).getAnnouncementType().equals(AnnouncementType.COLOR)) {
                if (EventColor.exists(value)) {
                    EventColor color = EventColor.fromNameOrHexOrID(value);
                    AnnouncementCreator.getCreator().getAnnouncement(guildId).setEventColor(color);
                    if (AnnouncementCreator.getCreator().hasCreatorMessage(guildId)) {
                        Message.deleteMessage(AnnouncementCreator.getCreator().getCreatorMessage(guildId));
                        Message.deleteMessage(event);
                        AnnouncementCreator.getCreator().setCreatorMessage(Message.sendMessage(AnnouncementMessageFormatter.getFormatAnnouncementEmbed(AnnouncementCreator.getCreator().getAnnouncement(guildId), settings), MessageManager.getMessage("Creator.Announcement.Color.Success.New", settings), event));
                    } else {
                        Message.sendMessage(MessageManager.getMessage("Creator.Announcement.Color.Success", "%color%", color.name(), settings), event);
                    }
                } else {
                    if (AnnouncementCreator.getCreator().hasCreatorMessage(guildId)) {
                        Message.deleteMessage(AnnouncementCreator.getCreator().getCreatorMessage(guildId));
                        Message.deleteMessage(event);
                        AnnouncementCreator.getCreator().setCreatorMessage(Message.sendMessage(AnnouncementMessageFormatter.getFormatAnnouncementEmbed(AnnouncementCreator.getCreator().getAnnouncement(guildId), settings), MessageManager.getMessage("Creator.Announcement.Color.Specify", settings), event));
                    } else {
                        Message.sendMessage(MessageManager.getMessage("Creator.Announcement.Color.Specify", settings), event);
                    }
                }
            } else {
                if (AnnouncementCreator.getCreator().hasCreatorMessage(guildId)) {
                    Message.deleteMessage(AnnouncementCreator.getCreator().getCreatorMessage(guildId));
                    Message.deleteMessage(event);
                    AnnouncementCreator.getCreator().setCreatorMessage(Message.sendMessage(AnnouncementMessageFormatter.getFormatAnnouncementEmbed(AnnouncementCreator.getCreator().getAnnouncement(guildId), settings), MessageManager.getMessage("Creator.Announcement.Color.Failure.Type", settings), event));
                } else {
                    Message.sendMessage(MessageManager.getMessage("Creator.Announcement.Color.Failure.Type", settings), event);
                }
            }
        } else {
            Message.sendMessage(MessageManager.getMessage("Creator.Announcement.NotInit", settings), event);
        }
    } else {
        Message.sendMessage(MessageManager.getMessage("Creator.Announcement.Color.Specify", settings), event);
    }
}
Also used : EventColor(com.cloudcraftgaming.discal.api.enums.event.EventColor)

Example 4 with EventColor

use of com.cloudcraftgaming.discal.api.enums.event.EventColor in project DisCal-Discord-Bot by NovaFox161.

the class EventMessageFormatter method getEventEmbed.

/**
 * Gets an EmbedObject for the specified event.
 *
 * @param event    The event involved.
 * @param settings The guild's settings
 * @return The EmbedObject of the event.
 */
public static EmbedObject getEventEmbed(Event event, GuildSettings settings) {
    EventData ed = DatabaseManager.getManager().getEventData(settings.getGuildID(), event.getId());
    EmbedBuilder em = new EmbedBuilder();
    em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
    em.withAuthorName("DisCal");
    em.withTitle(MessageManager.getMessage("Embed.Event.Info.Title", settings));
    if (ed.getImageLink() != null && ImageUtils.validate(ed.getImageLink())) {
        em.withImage(ed.getImageLink());
    }
    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.Event.Info.Summary", settings), summary, true);
    }
    if (event.getDescription() != null) {
        String description = event.getDescription();
        if (description.length() > 500) {
            description = description.substring(0, 500);
            description = description + " (continues on Google Calendar View)";
        }
        em.appendField(MessageManager.getMessage("Embed.Event.Info.Description", settings), description, true);
    }
    em.appendField(MessageManager.getMessage("Embed.Event.Info.StartDate", settings), getHumanReadableDate(event.getStart(), settings, false), true);
    em.appendField(MessageManager.getMessage("Embed.Event.Info.StartTime", settings), getHumanReadableTime(event.getStart(), settings, false), true);
    em.appendField(MessageManager.getMessage("Embed.Event.Info.EndDate", settings), getHumanReadableDate(event.getEnd(), settings, false), true);
    em.appendField(MessageManager.getMessage("Embed.Event.Info.EndTime", settings), getHumanReadableTime(event.getEnd(), settings, false), true);
    try {
        // TODO: add support for multiple calendars...
        CalendarData data = DatabaseManager.getManager().getMainCalendar(settings.getGuildID());
        Calendar service;
        service = settings.useExternalCalendar() ? CalendarAuth.getCalendarService(settings) : CalendarAuth.getCalendarService();
        String tz = service.calendars().get(data.getCalendarAddress()).execute().getTimeZone();
        em.appendField(MessageManager.getMessage("Embed.Event.Info.TimeZone", settings), tz, true);
    } catch (Exception e1) {
        em.appendField(MessageManager.getMessage("Embed.Event.Info.TimeZone", settings), "Error/Unknown", true);
    }
    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);
        }
    }
    // TODO: Add info on recurrence here.
    em.withUrl(event.getHtmlLink());
    em.withFooterText(MessageManager.getMessage("Embed.Event.Info.ID", "%id%", event.getId(), settings));
    try {
        EventColor ec = EventColor.fromId(Integer.valueOf(event.getColorId()));
        em.withColor(ec.getR(), ec.getG(), ec.getB());
    } catch (Exception e) {
        // Color is null, ignore and add our default.
        em.withColor(56, 138, 237);
    }
    return em.build();
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) CalendarData(com.cloudcraftgaming.discal.api.object.calendar.CalendarData) Calendar(com.google.api.services.calendar.Calendar) EventColor(com.cloudcraftgaming.discal.api.enums.event.EventColor) EventData(com.cloudcraftgaming.discal.api.object.event.EventData)

Example 5 with EventColor

use of com.cloudcraftgaming.discal.api.enums.event.EventColor in project DisCal-Discord-Bot by NovaFox161.

the class EventMessageFormatter method getPreEventEmbed.

/**
 * Gets an EmbedObject for the specified PreEvent.
 *
 * @param event The PreEvent to get an embed for.
 * @return The EmbedObject of the PreEvent.
 */
public static EmbedObject getPreEventEmbed(PreEvent event, GuildSettings settings) {
    EmbedBuilder em = new EmbedBuilder();
    em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
    em.withAuthorName("DisCal");
    em.withTitle(MessageManager.getMessage("Embed.Event.Pre.Title", settings));
    if (event.getEventData() != null && event.getEventData().getImageLink() != null && ImageUtils.validate(event.getEventData().getImageLink())) {
        em.withImage(event.getEventData().getImageLink());
    }
    if (event.isEditing()) {
        em.appendField(MessageManager.getMessage("Embed.Event.Pre.Id", settings), event.getEventId(), false);
    }
    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.Event.Pre.Summary", settings), summary, true);
    } else {
        em.appendField(MessageManager.getMessage("Embed.Event.Pre.Summary", settings), "NOT SET", true);
    }
    if (event.getDescription() != null) {
        String description = event.getDescription();
        if (description.length() > 500) {
            description = description.substring(0, 500);
            description = description + " (continues on Google Calendar View)";
        }
        em.appendField(MessageManager.getMessage("Embed.Event.Pre.Description", settings), description, true);
    } else {
        em.appendField(MessageManager.getMessage("Embed.Event.Pre.Description", settings), "NOT SET", true);
    }
    if (event.shouldRecur()) {
        em.appendField(MessageManager.getMessage("Embed.Event.Pre.Recurrence", settings), event.getRecurrence().toHumanReadable(), true);
    } else {
        em.appendField(MessageManager.getMessage("Embed.Event.Pre.Recurrence", settings), "N/a", true);
    }
    em.appendField(MessageManager.getMessage("Embed.Event.Pre.StartDate", settings), getHumanReadableDate(event.getViewableStartDate(), settings, true), true);
    em.appendField(MessageManager.getMessage("Embed.Event.Pre.StartTime", settings), EventMessageFormatter.getHumanReadableTime(event.getViewableStartDate(), settings, true), true);
    em.appendField(MessageManager.getMessage("Embed.Event.Pre.EndDate", settings), getHumanReadableDate(event.getViewableEndDate(), settings, true), true);
    em.appendField(MessageManager.getMessage("Embed.Event.Pre.EndTime", settings), EventMessageFormatter.getHumanReadableTime(event.getViewableEndDate(), settings, true), true);
    em.appendField(MessageManager.getMessage("Embed.Event.Pre.TimeZone", settings), event.getTimeZone(), true);
    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);
        }
    } else {
        em.appendField(MessageManager.getMessage("Embed.Event.Confirm.Location", settings), "N/a", true);
    }
    em.withFooterText(MessageManager.getMessage("Embed.Event.Pre.Key", settings));
    EventColor ec = event.getColor();
    em.withColor(ec.getR(), ec.getG(), ec.getB());
    return em.build();
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) EventColor(com.cloudcraftgaming.discal.api.enums.event.EventColor)

Aggregations

EventColor (com.cloudcraftgaming.discal.api.enums.event.EventColor)10 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)8 EventData (com.cloudcraftgaming.discal.api.object.event.EventData)7 Calendar (com.google.api.services.calendar.Calendar)4 CalendarData (com.cloudcraftgaming.discal.api.object.calendar.CalendarData)2 IGuild (sx.blah.discord.handle.obj.IGuild)2 Event (com.google.api.services.calendar.model.Event)1 IChannel (sx.blah.discord.handle.obj.IChannel)1