Java Code Examples for com.google.api.services.calendar.model.Event#getSummary()

The following examples show how to use com.google.api.services.calendar.model.Event#getSummary() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GoogleCalendarExporter.java    From data-transfer-project with Apache License 2.0 6 votes vote down vote up
private static CalendarEventModel convertToCalendarEventModel(String id, Event eventData) {
  List<EventAttendee> attendees = eventData.getAttendees();
  List<String> recurrenceRulesStrings = eventData.getRecurrence();
  return new CalendarEventModel(
      id,
      eventData.getDescription(),
      eventData.getSummary(),
      attendees == null
          ? null
          : attendees
              .stream()
              .map(GoogleCalendarExporter::transformToModelAttendee)
              .collect(Collectors.toList()),
      eventData.getLocation(),
      getEventTime(eventData.getStart()),
      getEventTime(eventData.getEnd()),
      recurrenceRulesStrings == null ? null : getRecurrenceRule(recurrenceRulesStrings));
}
 
Example 2
Source File: HolidayEventsLoader.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
private Map<HolidayEvent, Set<String>> aggregateCountryCodesGroupByHolidays(List<Event> newHolidays) {
  // A map from new holiday to a set of country codes that has the holiday
  Map<HolidayEvent, Set<String>> newHolidayEventToCountryCodes = new HashMap<>();

  // Convert Google Event Type to holiday events and aggregates the country code list
  for (Event holiday : newHolidays) {
    String countryCode = getCountryCode(holiday);
    String timeZone = getTimeZoneForCountry(countryCode);
    HolidayEvent holidayEvent =
        new HolidayEvent(holiday.getSummary(), EventType.HOLIDAY.toString(),
            getUtcTimeStamp(holiday.getStart().getDate().getValue(), timeZone),
            getUtcTimeStamp(holiday.getEnd().getDate().getValue(), timeZone));
    if (!newHolidayEventToCountryCodes.containsKey(holidayEvent)) {
      newHolidayEventToCountryCodes.put(holidayEvent, new HashSet<String>());
    }
    if (!countryCode.equals(NO_COUNTRY_CODE)) {
      newHolidayEventToCountryCodes.get(holidayEvent).add(countryCode);
    }
    LOG.info("Get holiday event {} in country {} between {} and {} in timezone {} ", holidayEvent.getName(),
        countryCode, holidayEvent.getStartTime(), holidayEvent.getEndTime(), timeZone);
  }
  return newHolidayEventToCountryCodes;
}
 
Example 3
Source File: EventMessageFormatter.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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 Consumer<EmbedCreateSpec> getEventEmbed(Event event, GuildSettings settings) {
	return spec -> {
		EventData ed = DatabaseManager.getManager().getEventData(settings.getGuildID(), event.getId());
		Guild guild = DisCalClient.getClient().getGuildById(settings.getGuildID()).block();

		if (settings.isBranded() && guild != null)
			spec.setAuthor(guild.getName(), GlobalConst.discalSite, guild.getIconUrl(Image.Format.PNG).orElse(GlobalConst.iconUrl));
		else
			spec.setAuthor("DisCal", GlobalConst.discalSite, GlobalConst.iconUrl);

		spec.setTitle(MessageManager.getMessage("Embed.Event.Info.Title", settings));
		if (ed.getImageLink() != null && ImageUtils.validate(ed.getImageLink(), settings.isPatronGuild())) {
			spec.setImage(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)";
			}

			spec.addField(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)";
			}
			spec.addField(MessageManager.getMessage("Embed.Event.Info.Description", settings), description, true);
		}
		spec.addField(MessageManager.getMessage("Embed.Event.Info.StartDate", settings), getHumanReadableDate(event.getStart(), settings, false), true);
		spec.addField(MessageManager.getMessage("Embed.Event.Info.StartTime", settings), getHumanReadableTime(event.getStart(), settings, false), true);
		spec.addField(MessageManager.getMessage("Embed.Event.Info.EndDate", settings), getHumanReadableDate(event.getEnd(), settings, false), true);
		spec.addField(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 = CalendarAuth.getCalendarService(settings);
			String tz = service.calendars().get(data.getCalendarAddress()).execute().getTimeZone();
			spec.addField(MessageManager.getMessage("Embed.Event.Info.TimeZone", settings), tz, true);
		} catch (Exception e1) {
			spec.addField(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)";
				spec.addField(MessageManager.getMessage("Embed.Event.Confirm.Location", settings), location, true);
			} else {
				spec.addField(MessageManager.getMessage("Embed.Event.Confirm.Location", settings), event.getLocation(), true);
			}
		}
		//TODO: Add info on recurrence here.
		spec.setUrl(event.getHtmlLink());
		spec.setFooter(MessageManager.getMessage("Embed.Event.Info.ID", "%id%", event.getId(), settings), null);
		try {
			EventColor ec = EventColor.fromId(Integer.valueOf(event.getColorId()));
			spec.setColor(ec.asColor());
		} catch (Exception e) {
			//Color is null, ignore and add our default.
			spec.setColor(GlobalConst.discalColor);
		}

	};
}
 
Example 4
Source File: EventMessageFormatter.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Gets an EmbedObject for the specified event.
 *
 * @param event The event involved.
 * @return The EmbedObject of the event.
 */
public static Consumer<EmbedCreateSpec> getCondensedEventEmbed(Event event, GuildSettings settings) {
	return spec -> {
		Guild guild = DisCalClient.getClient().getGuildById(settings.getGuildID()).block();

		if (settings.isBranded() && guild != null)
			spec.setAuthor(guild.getName(), GlobalConst.discalSite, guild.getIconUrl(Image.Format.PNG).orElse(GlobalConst.iconUrl));
		else
			spec.setAuthor("DisCal", GlobalConst.discalSite, GlobalConst.iconUrl);

		spec.setTitle(MessageManager.getMessage("Embed.Event.Condensed.Title", settings));
		EventData ed = DatabaseManager.getManager().getEventData(settings.getGuildID(), event.getId());
		if (ed.getImageLink() != null && ImageUtils.validate(ed.getImageLink(), settings.isPatronGuild()))
			spec.setThumbnail(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)";
			}
			spec.addField(MessageManager.getMessage("Embed.Event.Condensed.Summary", settings), summary, true);
		}
		spec.addField(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)";
				spec.addField(MessageManager.getMessage("Embed.Event.Confirm.Location", settings), location, true);
			} else {
				spec.addField(MessageManager.getMessage("Embed.Event.Confirm.Location", settings), event.getLocation(), true);
			}
		}
		spec.addField(MessageManager.getMessage("Embed.Event.Condensed.ID", settings), event.getId(), false);
		spec.setUrl(event.getHtmlLink());
		try {
			EventColor ec = EventColor.fromId(Integer.valueOf(event.getColorId()));
			spec.setColor(ec.asColor());
		} catch (Exception e) {
			//Color is null, ignore and add our default.
			spec.setColor(GlobalConst.discalColor);
		}
	};
}
 
Example 5
Source File: AnnouncementMessageFormatter.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Gets the EmbedObject for a Condensed Announcement.
 *
 * @param a The Announcement to embed.
 * @return The EmbedObject for a Condensed Announcement.
 */
public static Consumer<EmbedCreateSpec> getCondensedAnnouncementEmbed(Announcement a, GuildSettings settings) {
	return spec -> {
		Guild guild = DisCalClient.getClient().getGuildById(settings.getGuildID()).block();

		if (settings.isBranded())
			spec.setAuthor(guild.getName(), GlobalConst.discalSite, guild.getIconUrl(Image.Format.PNG).orElse(GlobalConst.iconUrl));
		else
			spec.setAuthor("DisCal", GlobalConst.discalSite, GlobalConst.iconUrl);

		spec.setTitle(MessageManager.getMessage("Embed.Announcement.Condensed.Title", settings));
		spec.addField(MessageManager.getMessage("Embed.Announcement.Condensed.ID", settings), a.getAnnouncementId().toString(), false);
		spec.addField(MessageManager.getMessage("Embed.Announcement.Condensed.Time", settings), condensedTime(a), false);

		if (a.getAnnouncementType().equals(AnnouncementType.SPECIFIC)) {
			spec.addField(MessageManager.getMessage("Embed.Announcement.Condensed.EventID", settings), a.getEventId(), false);
			try {
				Calendar service = CalendarAuth.getCalendarService(settings);

				//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(), settings.isPatronGuild()))
					spec.setThumbnail(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)";
					}
					spec.addField(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, true, AnnouncementMessageFormatter.class);
			}
		} else if (a.getAnnouncementType().equals(AnnouncementType.COLOR)) {
			spec.addField(MessageManager.getMessage("Embed.Announcement.Condensed.Color", settings), a.getEventColor().name(), true);
		} else if (a.getAnnouncementType().equals(AnnouncementType.RECUR)) {
			spec.addField(MessageManager.getMessage("Embed.Announcement.Condensed.RecurID", settings), a.getEventId(), true);
		}
		spec.setFooter(MessageManager.getMessage("Embed.Announcement.Condensed.Type", "%type%", a.getAnnouncementType().name(), settings), null);

		if (a.getAnnouncementType().equals(AnnouncementType.COLOR)) {
			spec.setColor(a.getEventColor().asColor());
		} else {
			spec.setColor(GlobalConst.discalColor);
		}

		spec.addField(MessageManager.getMessage("Embed.Announcement.Info.Enabled", settings), a.isEnabled() + "", true);

	};
}
 
Example 6
Source File: PreEvent.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 4 votes vote down vote up
public PreEvent(Snowflake _guildId, Event e) {
	guildId = _guildId;
	eventId = e.getId();

	color = EventColor.fromNameOrHexOrID(e.getColorId());

	recurrence = new Recurrence();

	if (e.getRecurrence() != null && e.getRecurrence().size() > 0) {
		recur = true;
		recurrence.fromRRule(e.getRecurrence().get(0));
	}

	if (e.getSummary() != null)
		summary = e.getSummary();

	if (e.getDescription() != null)
		description = e.getDescription();

	if (e.getLocation() != null)
		location = e.getLocation();


	startDateTime = e.getStart();
	endDateTime = e.getEnd();

	//Here is where I need to fix the display times
	GuildSettings settings = DatabaseManager.getManager().getSettings(guildId);
	//TODO: Support multiple calendars
	CalendarData data = DatabaseManager.getManager().getMainCalendar(guildId);

	Calendar cal = null;
	try {
		cal = CalendarAuth.getCalendarService(settings).calendars().get(data.getCalendarAddress()).execute();
	} catch (Exception ex) {
		Logger.getLogger().exception(null, "Failed to get proper date time for event!", ex, true, this.getClass());
	}

	if (cal != null) {

		//Check if either DateTime or just Date...
		if (e.getStart().getDateTime() != null) {
			//DateTime
			viewableStartDate = new EventDateTime().setDateTime(new DateTime(TimeUtils.applyTimeZoneOffset(e.getStart().getDateTime().getValue(), cal.getTimeZone())));
			viewableEndDate = new EventDateTime().setDateTime(new DateTime(TimeUtils.applyTimeZoneOffset(e.getEnd().getDateTime().getValue(), cal.getTimeZone())));
		} else {
			//Just Date
			viewableStartDate = new EventDateTime().setDate(new DateTime(TimeUtils.applyTimeZoneOffset(e.getStart().getDate().getValue(), cal.getTimeZone())));
			viewableEndDate = new EventDateTime().setDate(new DateTime(TimeUtils.applyTimeZoneOffset(e.getEnd().getDate().getValue(), cal.getTimeZone())));
		}
	} else {
		//Almost definitely not correct, but we need something displayed here.
		viewableStartDate = e.getStart();
		viewableEndDate = e.getEnd();
	}

	eventData = DatabaseManager.getManager().getEventData(guildId, e.getId());

	editing = false;
	lastEdit = System.currentTimeMillis();
}
 
Example 7
Source File: EventMessageFormatter.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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 Consumer<EmbedCreateSpec> getEventEmbed(Event event, GuildSettings settings) {
	return spec -> {
		EventData ed = DatabaseManager.getManager().getEventData(settings.getGuildID(), event.getId());
		Guild guild = DisCalClient.getClient().getGuildById(settings.getGuildID()).block();

		if (settings.isBranded() && guild != null)
			spec.setAuthor(guild.getName(), GlobalConst.discalSite, guild.getIconUrl(Image.Format.PNG).orElse(GlobalConst.iconUrl));
		else
			spec.setAuthor("DisCal", GlobalConst.discalSite, GlobalConst.iconUrl);

		spec.setTitle(MessageManager.getMessage("Embed.Event.Info.Title", settings));
		if (ed.getImageLink() != null && ImageUtils.validate(ed.getImageLink(), settings.isPatronGuild())) {
			spec.setImage(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)";
			}

			spec.addField(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)";
			}
			spec.addField(MessageManager.getMessage("Embed.Event.Info.Description", settings), description, true);
		}
		spec.addField(MessageManager.getMessage("Embed.Event.Info.StartDate", settings), getHumanReadableDate(event.getStart(), settings, false), true);
		spec.addField(MessageManager.getMessage("Embed.Event.Info.StartTime", settings), getHumanReadableTime(event.getStart(), settings, false), true);
		spec.addField(MessageManager.getMessage("Embed.Event.Info.EndDate", settings), getHumanReadableDate(event.getEnd(), settings, false), true);
		spec.addField(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 = CalendarAuth.getCalendarService(settings);
			String tz = service.calendars().get(data.getCalendarAddress()).execute().getTimeZone();
			spec.addField(MessageManager.getMessage("Embed.Event.Info.TimeZone", settings), tz, true);
		} catch (Exception e1) {
			spec.addField(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)";
				spec.addField(MessageManager.getMessage("Embed.Event.Confirm.Location", settings), location, true);
			} else {
				spec.addField(MessageManager.getMessage("Embed.Event.Confirm.Location", settings), event.getLocation(), true);
			}
		}
		//TODO: Add info on recurrence here.
		spec.setUrl(event.getHtmlLink());
		spec.setFooter(MessageManager.getMessage("Embed.Event.Info.ID", "%id%", event.getId(), settings), null);
		try {
			EventColor ec = EventColor.fromId(Integer.valueOf(event.getColorId()));
			spec.setColor(ec.asColor());
		} catch (Exception e) {
			//Color is null, ignore and add our default.
			spec.setColor(GlobalConst.discalColor);
		}

	};
}
 
Example 8
Source File: EventMessageFormatter.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Gets an EmbedObject for the specified event.
 *
 * @param event The event involved.
 * @return The EmbedObject of the event.
 */
public static Consumer<EmbedCreateSpec> getCondensedEventEmbed(Event event, GuildSettings settings) {
	return spec -> {
		Guild guild = DisCalClient.getClient().getGuildById(settings.getGuildID()).block();

		if (settings.isBranded() && guild != null)
			spec.setAuthor(guild.getName(), GlobalConst.discalSite, guild.getIconUrl(Image.Format.PNG).orElse(GlobalConst.iconUrl));
		else
			spec.setAuthor("DisCal", GlobalConst.discalSite, GlobalConst.iconUrl);

		spec.setTitle(MessageManager.getMessage("Embed.Event.Condensed.Title", settings));
		EventData ed = DatabaseManager.getManager().getEventData(settings.getGuildID(), event.getId());
		if (ed.getImageLink() != null && ImageUtils.validate(ed.getImageLink(), settings.isPatronGuild()))
			spec.setThumbnail(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)";
			}
			spec.addField(MessageManager.getMessage("Embed.Event.Condensed.Summary", settings), summary, true);
		}
		spec.addField(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)";
				spec.addField(MessageManager.getMessage("Embed.Event.Confirm.Location", settings), location, true);
			} else {
				spec.addField(MessageManager.getMessage("Embed.Event.Confirm.Location", settings), event.getLocation(), true);
			}
		}
		spec.addField(MessageManager.getMessage("Embed.Event.Condensed.ID", settings), event.getId(), false);
		spec.setUrl(event.getHtmlLink());
		try {
			EventColor ec = EventColor.fromId(Integer.valueOf(event.getColorId()));
			spec.setColor(ec.asColor());
		} catch (Exception e) {
			//Color is null, ignore and add our default.
			spec.setColor(GlobalConst.discalColor);
		}
	};
}
 
Example 9
Source File: AnnouncementMessageFormatter.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Gets the EmbedObject for a Condensed Announcement.
 *
 * @param a The Announcement to embed.
 * @return The EmbedObject for a Condensed Announcement.
 */
public static Consumer<EmbedCreateSpec> getCondensedAnnouncementEmbed(Announcement a, GuildSettings settings) {
	return spec -> {
		Guild guild = DisCalClient.getClient().getGuildById(settings.getGuildID()).block();

		if (settings.isBranded())
			spec.setAuthor(guild.getName(), GlobalConst.discalSite, guild.getIconUrl(Image.Format.PNG).orElse(GlobalConst.iconUrl));
		else
			spec.setAuthor("DisCal", GlobalConst.discalSite, GlobalConst.iconUrl);

		spec.setTitle(MessageManager.getMessage("Embed.Announcement.Condensed.Title", settings));
		spec.addField(MessageManager.getMessage("Embed.Announcement.Condensed.ID", settings), a.getAnnouncementId().toString(), false);
		spec.addField(MessageManager.getMessage("Embed.Announcement.Condensed.Time", settings), condensedTime(a), false);

		if (a.getAnnouncementType().equals(AnnouncementType.SPECIFIC)) {
			spec.addField(MessageManager.getMessage("Embed.Announcement.Condensed.EventID", settings), a.getEventId(), false);
			try {
				Calendar service = CalendarAuth.getCalendarService(settings);

				//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(), settings.isPatronGuild()))
					spec.setThumbnail(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)";
					}
					spec.addField(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, true, AnnouncementMessageFormatter.class);
			}
		} else if (a.getAnnouncementType().equals(AnnouncementType.COLOR)) {
			spec.addField(MessageManager.getMessage("Embed.Announcement.Condensed.Color", settings), a.getEventColor().name(), true);
		} else if (a.getAnnouncementType().equals(AnnouncementType.RECUR)) {
			spec.addField(MessageManager.getMessage("Embed.Announcement.Condensed.RecurID", settings), a.getEventId(), true);
		}
		spec.setFooter(MessageManager.getMessage("Embed.Announcement.Condensed.Type", "%type%", a.getAnnouncementType().name(), settings), null);

		if (a.getAnnouncementType().equals(AnnouncementType.COLOR)) {
			spec.setColor(a.getEventColor().asColor());
		} else {
			spec.setColor(GlobalConst.discalColor);
		}

		spec.addField(MessageManager.getMessage("Embed.Announcement.Info.Enabled", settings), a.isEnabled() + "", true);

	};
}
 
Example 10
Source File: PreEvent.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 4 votes vote down vote up
public PreEvent(Snowflake _guildId, Event e) {
	guildId = _guildId;
	eventId = e.getId();

	color = EventColor.fromNameOrHexOrID(e.getColorId());

	recurrence = new Recurrence();

	if (e.getRecurrence() != null && e.getRecurrence().size() > 0) {
		recur = true;
		recurrence.fromRRule(e.getRecurrence().get(0));
	}

	if (e.getSummary() != null)
		summary = e.getSummary();

	if (e.getDescription() != null)
		description = e.getDescription();

	if (e.getLocation() != null)
		location = e.getLocation();


	startDateTime = e.getStart();
	endDateTime = e.getEnd();

	//Here is where I need to fix the display times
	GuildSettings settings = DatabaseManager.getManager().getSettings(guildId);
	//TODO: Support multiple calendars
	CalendarData data = DatabaseManager.getManager().getMainCalendar(guildId);

	Calendar cal = null;
	try {
		cal = CalendarAuth.getCalendarService(settings).calendars().get(data.getCalendarAddress()).execute();
	} catch (Exception ex) {
		Logger.getLogger().exception(null, "Failed to get proper date time for event!", ex, true, this.getClass());
	}

	if (cal != null) {

		//Check if either DateTime or just Date...
		if (e.getStart().getDateTime() != null) {
			//DateTime
			viewableStartDate = new EventDateTime().setDateTime(new DateTime(TimeUtils.applyTimeZoneOffset(e.getStart().getDateTime().getValue(), cal.getTimeZone())));
			viewableEndDate = new EventDateTime().setDateTime(new DateTime(TimeUtils.applyTimeZoneOffset(e.getEnd().getDateTime().getValue(), cal.getTimeZone())));
		} else {
			//Just Date
			viewableStartDate = new EventDateTime().setDate(new DateTime(TimeUtils.applyTimeZoneOffset(e.getStart().getDate().getValue(), cal.getTimeZone())));
			viewableEndDate = new EventDateTime().setDate(new DateTime(TimeUtils.applyTimeZoneOffset(e.getEnd().getDate().getValue(), cal.getTimeZone())));
		}
	} else {
		//Almost definitely not correct, but we need something displayed here.
		viewableStartDate = e.getStart();
		viewableEndDate = e.getEnd();
	}

	eventData = DatabaseManager.getManager().getEventData(guildId, e.getId());

	editing = false;
	lastEdit = System.currentTimeMillis();
}