use of com.cloudcraftgaming.discal.api.object.event.EventCreatorResponse in project DisCal-Discord-Bot by NovaFox161.
the class EventCommand method moduleConfirm.
private void moduleConfirm(MessageReceivedEvent event, CalendarData calendarData, GuildSettings settings) {
long guildId = event.getGuild().getLongID();
if (EventCreator.getCreator().hasPreEvent(guildId)) {
if (EventCreator.getCreator().getPreEvent(guildId).hasRequiredValues()) {
if (!calendarData.getCalendarAddress().equalsIgnoreCase("primary")) {
EventCreatorResponse response = EventCreator.getCreator().confirmEvent(event, settings);
if (response.isSuccessful()) {
if (!response.isEdited()) {
if (EventCreator.getCreator().hasCreatorMessage(guildId)) {
Message.deleteMessage(event);
Message.deleteMessage(EventCreator.getCreator().getCreatorMessage(guildId));
EventCreator.getCreator().setCreatorMessage(Message.sendMessage(EventMessageFormatter.getEventConfirmationEmbed(response, settings), MessageManager.getMessage("Creator.Event.Confirm.Create", settings), event));
} else {
Message.sendMessage(EventMessageFormatter.getEventConfirmationEmbed(response, settings), MessageManager.getMessage("Creator.Event.Confirm.Create", settings), event);
}
} else {
if (EventCreator.getCreator().hasCreatorMessage(guildId)) {
Message.deleteMessage(event);
Message.deleteMessage(EventCreator.getCreator().getCreatorMessage(guildId));
EventCreator.getCreator().setCreatorMessage(Message.sendMessage(EventMessageFormatter.getEventConfirmationEmbed(response, settings), MessageManager.getMessage("Creator.Event.Confirm.Edit", settings), event));
} else {
Message.sendMessage(EventMessageFormatter.getEventConfirmationEmbed(response, settings), MessageManager.getMessage("Creator.Event.Confirm.Edit", 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.Confirm.Failure", settings), event));
} else {
Message.sendMessage(MessageManager.getMessage("Creator.Event.Confirm.Failure", 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.NoCalendar", settings), event));
} else {
Message.sendMessage(MessageManager.getMessage("Creator.Event.NoCalendar", 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.NoRequired", settings), event));
} else {
Message.sendMessage(MessageManager.getMessage("Creator.Event.NoRequired", settings), event);
}
}
} else {
Message.sendMessage(MessageManager.getMessage("Creator.Event.NotInit", settings), event);
}
}
use of com.cloudcraftgaming.discal.api.object.event.EventCreatorResponse in project DisCal-Discord-Bot by NovaFox161.
the class EventCreator method confirmEvent.
/**
* Confirms the event in the creator for the specific guild.
*
* @param e The event received upon confirmation.
* @return The response containing detailed info about the confirmation.
*/
public EventCreatorResponse confirmEvent(MessageReceivedEvent e, GuildSettings settings) {
if (hasPreEvent(e.getGuild().getLongID())) {
long guildId = e.getGuild().getLongID();
PreEvent preEvent = getPreEvent(guildId);
if (preEvent.hasRequiredValues()) {
Event event = new Event();
event.setSummary(preEvent.getSummary());
event.setDescription(preEvent.getDescription());
event.setStart(preEvent.getStartDateTime().setTimeZone(preEvent.getTimeZone()));
event.setEnd(preEvent.getEndDateTime().setTimeZone(preEvent.getTimeZone()));
event.setVisibility("public");
if (!preEvent.getColor().equals(EventColor.NONE)) {
event.setColorId(String.valueOf(preEvent.getColor().getId()));
}
if (preEvent.getLocation() != null && !preEvent.getLocation().equalsIgnoreCase("")) {
event.setLocation(preEvent.getLocation());
}
// Set recurrence
if (preEvent.shouldRecur()) {
String[] recurrence = new String[] { preEvent.getRecurrence().toRRule() };
event.setRecurrence(Arrays.asList(recurrence));
}
// TODO handle multiple calendars...
String calendarId = DatabaseManager.getManager().getMainCalendar(guildId).getCalendarAddress();
if (!preEvent.isEditing()) {
event.setId(KeyGenerator.generateEventId());
try {
Event confirmed;
if (settings.useExternalCalendar()) {
confirmed = CalendarAuth.getCalendarService(settings).events().insert(calendarId, event).execute();
} else {
confirmed = CalendarAuth.getCalendarService().events().insert(calendarId, event).execute();
}
if (preEvent.getEventData().shouldBeSaved()) {
preEvent.getEventData().setEventId(confirmed.getId());
preEvent.getEventData().setEventEnd(confirmed.getEnd().getDateTime().getValue());
DatabaseManager.getManager().updateEventData(preEvent.getEventData());
}
terminate(e);
EventCreatorResponse response = new EventCreatorResponse(true, confirmed);
response.setEdited(false);
return response;
} catch (Exception ex) {
Logger.getLogger().exception(e.getAuthor(), "Failed to create event.", ex, this.getClass(), true);
EventCreatorResponse response = new EventCreatorResponse(false);
response.setEdited(false);
return response;
}
} else {
try {
Event confirmed;
if (settings.useExternalCalendar()) {
confirmed = CalendarAuth.getCalendarService(settings).events().update(calendarId, preEvent.getEventId(), event).execute();
} else {
confirmed = CalendarAuth.getCalendarService().events().update(calendarId, preEvent.getEventId(), event).execute();
}
if (preEvent.getEventData().shouldBeSaved()) {
preEvent.getEventData().setEventId(confirmed.getId());
preEvent.getEventData().setEventEnd(confirmed.getEnd().getDateTime().getValue());
DatabaseManager.getManager().updateEventData(preEvent.getEventData());
}
terminate(e);
EventCreatorResponse response = new EventCreatorResponse(true, confirmed);
response.setEdited(true);
return response;
} catch (Exception ex) {
Logger.getLogger().exception(e.getAuthor(), "Failed to update event.", ex, this.getClass(), true);
EventCreatorResponse response = new EventCreatorResponse(false);
response.setEdited(true);
return response;
}
}
}
}
return new EventCreatorResponse(false);
}
Aggregations