use of com.cloudcraftgaming.discal.api.object.event.EventData 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.object.event.EventData 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.object.event.EventData 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.object.event.EventData 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();
}
use of com.cloudcraftgaming.discal.api.object.event.EventData in project DisCal-Discord-Bot by NovaFox161.
the class EventEndpoint method updateEvent.
public static String updateEvent(Request request, Response response) {
JSONObject body = new JSONObject(request.body());
String eventId = body.getString("id");
GuildSettings settings;
if (DiscordAccountHandler.getHandler().hasAccount(request.session().id())) {
Map m = DiscordAccountHandler.getHandler().getAccount(request.session().id());
WebGuild g = (WebGuild) m.get("selected");
g.setSettings(DatabaseManager.getManager().getSettings(Long.valueOf(g.getId())));
settings = g.getSettings();
} else {
long guildId = body.getLong("guild_id");
settings = DatabaseManager.getManager().getSettings(guildId);
}
// Okay, time to update the event
try {
Calendar service;
if (settings.useExternalCalendar()) {
service = CalendarAuth.getCalendarService(settings);
} else {
service = CalendarAuth.getCalendarService();
}
CalendarData calendarData = DatabaseManager.getManager().getMainCalendar(settings.getGuildID());
com.google.api.services.calendar.model.Calendar cal = service.calendars().get(calendarData.getCalendarId()).execute();
Event event = new Event();
event.setId(eventId);
event.setVisibility("public");
event.setSummary(body.getString("summary"));
event.setDescription(body.getString("description"));
EventDateTime start = new EventDateTime();
start.setDateTime(new DateTime(body.getLong("epochStart")));
event.setStart(start.setTimeZone(cal.getTimeZone()));
EventDateTime end = new EventDateTime();
end.setDateTime(new DateTime(body.getLong("epochEnd")));
event.setEnd(end.setTimeZone(cal.getTimeZone()));
if (!body.getString("color").equalsIgnoreCase("NONE")) {
event.setColorId(EventColor.fromNameOrHexOrID(body.getString("color")).getId().toString());
}
if (!body.getString("location").equalsIgnoreCase("") || !body.getString("location").equalsIgnoreCase("N/a")) {
event.setLocation(body.getString("location"));
}
JSONObject recur = body.getJSONObject("recurrence");
if (recur.getBoolean("recur")) {
// Handle recur
Recurrence recurrence = new Recurrence();
recurrence.setFrequency(EventFrequency.fromValue(recur.getString("frequency")));
recurrence.setCount(recur.getInt("count"));
recurrence.setInterval(recur.getInt("interval"));
String[] rr = new String[] { recurrence.toRRule() };
event.setRecurrence(Arrays.asList(rr));
}
EventData ed = new EventData(settings.getGuildID());
if (!body.getString("image").equalsIgnoreCase("") && ImageUtils.validate(body.getString("image"))) {
ed.setImageLink(body.getString("image"));
ed.setEventId(eventId);
ed.setEventEnd(event.getEnd().getDateTime().getValue());
}
if (ed.shouldBeSaved()) {
DatabaseManager.getManager().updateEventData(ed);
}
service.events().update(calendarData.getCalendarId(), eventId, event).execute();
response.status(200);
response.body(ResponseUtils.getJsonResponseMessage("Successfully updated event!"));
} catch (Exception e) {
Logger.getLogger().exception(null, "[WEB] Failed to update event!", e, EventEndpoint.class, true);
e.printStackTrace();
response.status(500);
response.body(ResponseUtils.getJsonResponseMessage("Failed to update event!"));
}
return response.body();
}
Aggregations