use of com.cloudcraftgaming.discal.api.enums.event.EventColor in project DisCal-Discord-Bot by NovaFox161.
the class AnnouncementMessageFormatter method getFormatAnnouncementEmbed.
/**
* Gets the EmbedObject for an Announcement.
* @param a The Announcement to embed.
* @return The EmbedObject for the Announcement.
*/
public static EmbedObject getFormatAnnouncementEmbed(Announcement a, GuildSettings settings) {
EmbedBuilder em = new EmbedBuilder();
em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
em.withAuthorName("DisCal");
em.withTitle(MessageManager.getMessage("Embed.Announcement.Info.Title", settings));
try {
em.appendField(MessageManager.getMessage("Embed.Announcement.Info.ID", settings), a.getAnnouncementId().toString(), true);
} catch (NullPointerException e) {
em.appendField(MessageManager.getMessage("Embed.Announcement.Info.ID", settings), "ID IS NULL???", true);
}
em.appendField(MessageManager.getMessage("Embed.Announcement.Info.Type", settings), a.getAnnouncementType().name(), true);
if (a.getAnnouncementType().equals(AnnouncementType.SPECIFIC)) {
em.appendField(MessageManager.getMessage("Embed.Announcement.Info.EventID", settings), a.getEventId(), true);
EventData ed = DatabaseManager.getManager().getEventData(a.getGuildId(), a.getEventId());
if (ed.getImageLink() != null && ImageUtils.validate(ed.getImageLink())) {
em.withImage(ed.getImageLink());
}
} else if (a.getAnnouncementType().equals(AnnouncementType.COLOR)) {
em.appendField(MessageManager.getMessage("Embed.Announcement.Info.Color", settings), a.getEventColor().name(), true);
} else if (a.getAnnouncementType().equals(AnnouncementType.RECUR)) {
em.appendField(MessageManager.getMessage("Embed.Announcement.Info.RecurID", settings), a.getEventId(), true);
EventData ed = DatabaseManager.getManager().getEventData(a.getGuildId(), a.getEventId());
if (ed.getImageLink() != null && ImageUtils.validate(ed.getImageLink())) {
em.withImage(ed.getImageLink());
}
}
em.appendField(MessageManager.getMessage("Embed.Announcement.Info.Hours", settings), String.valueOf(a.getHoursBefore()), true);
em.appendField(MessageManager.getMessage("Embed.Announcement.Info.Minutes", settings), String.valueOf(a.getMinutesBefore()), true);
em.appendField(MessageManager.getMessage("Embed.Announcement.Info.Channel", settings), ChannelUtils.getChannelNameFromNameOrId(a.getAnnouncementChannelId(), a.getGuildId()), true);
em.appendField(MessageManager.getMessage("Embed.Announcement.Info.Info", settings), a.getInfo(), false);
if (a.getAnnouncementType().equals(AnnouncementType.COLOR)) {
EventColor c = a.getEventColor();
em.withColor(c.getR(), c.getG(), c.getB());
} else {
em.withColor(56, 138, 237);
}
em.appendField(MessageManager.getMessage("Embed.Announcement.Info.Enabled", settings), a.isEnabled() + "", true);
return em.build();
}
use of com.cloudcraftgaming.discal.api.enums.event.EventColor in project DisCal-Discord-Bot by NovaFox161.
the class AnnouncementMessageFormatter method getCondensedAnnouncementEmbed.
/**
* Gets the EmbedObject for a Condensed Announcement.
* @param a The Announcement to embed.
* @return The EmbedObject for a Condensed Announcement.
*/
public static EmbedObject getCondensedAnnouncementEmbed(Announcement a, GuildSettings settings) {
EmbedBuilder em = new EmbedBuilder();
em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
em.withAuthorName("DisCal");
em.withTitle(MessageManager.getMessage("Embed.Announcement.Condensed.Title", settings));
em.appendField(MessageManager.getMessage("Embed.Announcement.Condensed.ID", settings), a.getAnnouncementId().toString(), false);
em.appendField(MessageManager.getMessage("Embed.Announcement.Condensed.Time", settings), condensedTime(a), false);
if (a.getAnnouncementType().equals(AnnouncementType.SPECIFIC)) {
em.appendField(MessageManager.getMessage("Embed.Announcement.Condensed.EventID", settings), a.getEventId(), false);
try {
Calendar service;
if (settings.useExternalCalendar()) {
service = CalendarAuth.getCalendarService(settings);
} else {
service = CalendarAuth.getCalendarService();
}
// TODO: Handle multiple calendars...
CalendarData data = DatabaseManager.getManager().getMainCalendar(a.getGuildId());
Event event = service.events().get(data.getCalendarAddress(), a.getEventId()).execute();
EventData ed = DatabaseManager.getManager().getEventData(settings.getGuildID(), event.getId());
if (ed.getImageLink() != null && ImageUtils.validate(ed.getImageLink())) {
em.withThumbnail(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.Announcement.Condensed.Summary", settings), summary, true);
}
} catch (Exception e) {
// Failed to get from google cal.
Logger.getLogger().exception(null, "Failed to get event for announcement.", e, AnnouncementMessageFormatter.class, true);
}
} else if (a.getAnnouncementType().equals(AnnouncementType.COLOR)) {
em.appendField(MessageManager.getMessage("Embed.Announcement.Condensed.Color", settings), a.getEventColor().name(), true);
} else if (a.getAnnouncementType().equals(AnnouncementType.RECUR)) {
em.appendField(MessageManager.getMessage("Embed.Announcement.Condensed.RecurID", settings), a.getEventId(), true);
}
em.withFooterText(MessageManager.getMessage("Embed.Announcement.Condensed.Type", "%type%", a.getAnnouncementType().name(), settings));
if (a.getAnnouncementType().equals(AnnouncementType.COLOR)) {
EventColor c = a.getEventColor();
em.withColor(c.getR(), c.getG(), c.getB());
} else {
em.withColor(56, 138, 237);
}
em.appendField(MessageManager.getMessage("Embed.Announcement.Info.Enabled", settings), a.isEnabled() + "", true);
return em.build();
}
use of com.cloudcraftgaming.discal.api.enums.event.EventColor in project DisCal-Discord-Bot by NovaFox161.
the class AnnouncementMessageFormatter method sendAnnouncementDM.
static void sendAnnouncementDM(Announcement announcement, Event event, IUser user, CalendarData data, GuildSettings settings) {
EmbedBuilder em = new EmbedBuilder();
em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
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());
}
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);
}
em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.Info", settings), announcement.getInfo(), false);
em.withUrl(event.getHtmlLink());
if (!settings.usingSimpleAnnouncements()) {
em.withFooterText(MessageManager.getMessage("Embed.Announcement.Announce.ID", "%id%", announcement.getAnnouncementId().toString(), settings));
}
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);
}
IGuild guild = Main.client.getGuildByID(announcement.getGuildId());
String msg = MessageManager.getMessage("Embed.Announcement.Announce.Dm.Message", "%guild%", guild.getName(), settings);
Message.sendDirectMessage(msg, em.build(), user);
}
use of com.cloudcraftgaming.discal.api.enums.event.EventColor in project DisCal-Discord-Bot by NovaFox161.
the class EventMessageFormatter method getCondensedEventEmbed.
/**
* Gets an EmbedObject for the specified event.
*
* @param event The event involved.
* @return The EmbedObject of the event.
*/
public static EmbedObject getCondensedEventEmbed(Event event, GuildSettings settings) {
EmbedBuilder em = new EmbedBuilder();
em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
em.withAuthorName("DisCal");
em.withTitle(MessageManager.getMessage("Embed.Event.Condensed.Title", settings));
EventData ed = DatabaseManager.getManager().getEventData(settings.getGuildID(), event.getId());
if (ed.getImageLink() != null && ImageUtils.validate(ed.getImageLink())) {
em.withThumbnail(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.Condensed.Summary", settings), summary, true);
}
em.appendField(MessageManager.getMessage("Embed.Event.Condensed.Date", settings), getHumanReadableDate(event.getStart(), settings, false), 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);
}
}
em.appendField(MessageManager.getMessage("Embed.Event.Condensed.ID", settings), event.getId(), false);
em.withUrl(event.getHtmlLink());
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();
}
use of com.cloudcraftgaming.discal.api.enums.event.EventColor in project DisCal-Discord-Bot by NovaFox161.
the class EventMessageFormatter method getEventConfirmationEmbed.
/**
* Gets an EmbedObject for the specified CreatorResponse.
*
* @param ecr The CreatorResponse involved.
* @return The EmbedObject for the CreatorResponse.
*/
public static EmbedObject getEventConfirmationEmbed(EventCreatorResponse ecr, GuildSettings settings) {
EventData ed = DatabaseManager.getManager().getEventData(settings.getGuildID(), ecr.getEvent().getId());
EmbedBuilder em = new EmbedBuilder();
em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
em.withAuthorName("DisCal");
em.withTitle(MessageManager.getMessage("Embed.Event.Confirm.Title", settings));
if (ed.getImageLink() != null && ImageUtils.validate(ed.getImageLink())) {
em.withImage(ed.getImageLink());
}
em.appendField(MessageManager.getMessage("Embed.Event.Confirm.ID", settings), ecr.getEvent().getId(), false);
em.appendField(MessageManager.getMessage("Embed.Event.Confirm.Date", settings), getHumanReadableDate(ecr.getEvent().getStart(), settings, false), false);
if (ecr.getEvent().getLocation() != null && !ecr.getEvent().getLocation().equalsIgnoreCase("")) {
if (ecr.getEvent().getLocation().length() > 300) {
String location = ecr.getEvent().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), ecr.getEvent().getLocation(), true);
}
}
em.withFooterText(MessageManager.getMessage("Embed.Event.Confirm.Footer", settings));
em.withUrl(ecr.getEvent().getHtmlLink());
try {
EventColor ec = EventColor.fromId(Integer.valueOf(ecr.getEvent().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();
}
Aggregations