use of com.cloudcraftgaming.discal.api.object.calendar.CalendarData in project DisCal-Discord-Bot by NovaFox161.
the class CalendarCommand method issueCommand.
/**
* Issues the command this Object is responsible for.
* @param args The command arguments.
* @param event The event received.
* @return <code>true</code> if successful, else <code>false</code>.
*/
@Override
public Boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
if (args.length < 1) {
Message.sendMessage(MessageManager.getMessage("Notification.Args.Few", settings), event);
} else {
long guildId = event.getGuild().getLongID();
// TODO: Add support for multiple calendars...
CalendarData calendarData = DatabaseManager.getManager().getMainCalendar(guildId);
switch(args[0].toLowerCase()) {
case "create":
if (PermissionChecker.hasSufficientRole(event)) {
moduleCreate(args, event, calendarData, settings);
} else {
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
}
break;
case "cancel":
if (PermissionChecker.hasSufficientRole(event)) {
moduleCancel(event, calendarData, settings);
} else {
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
}
break;
case "view":
moduleView(event, calendarData, settings);
break;
case "review":
moduleView(event, calendarData, settings);
break;
case "confirm":
if (PermissionChecker.hasSufficientRole(event)) {
moduleConfirm(event, calendarData, settings);
} else {
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
}
break;
case "delete":
if (PermissionChecker.hasSufficientRole(event)) {
moduleDelete(event, calendarData, settings);
} else {
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
}
break;
case "remove":
if (PermissionChecker.hasSufficientRole(event)) {
moduleDelete(event, calendarData, settings);
} else {
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
}
break;
case "name":
moduleSummary(args, event, calendarData, settings);
break;
case "summary":
moduleSummary(args, event, calendarData, settings);
break;
case "description":
moduleDescription(args, event, calendarData, settings);
break;
case "timezone":
moduleTimezone(args, event, calendarData, settings);
break;
case "edit":
if (PermissionChecker.hasSufficientRole(event)) {
moduleEdit(event, calendarData, settings);
} else {
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
}
break;
default:
Message.sendMessage(MessageManager.getMessage("Notification.Args.Invalid", settings), event);
break;
}
}
return false;
}
use of com.cloudcraftgaming.discal.api.object.calendar.CalendarData in project DisCal-Discord-Bot by NovaFox161.
the class DevCommand method moduleCleanupDatabase.
private void moduleCleanupDatabase(MessageReceivedEvent event) {
Message.sendMessage("Cleaning up database! This may take some time....", event);
Message.sendMessage("Cleaning out calendars....", event);
for (CalendarData cd : DatabaseManager.getManager().getAllCalendars()) {
if (Main.client.getGuildByID(cd.getGuildId()) == null) {
// Guild not connected... delete calendar...
CalendarUtils.deleteCalendar(cd, DatabaseManager.getManager().getSettings(cd.getGuildId()));
}
}
Message.sendMessage("Calendars cleaned up!", event);
Message.sendMessage("Cleaned up database!", event);
// Message.sendMessage("Disabled because I am a dumb", event);
}
use of com.cloudcraftgaming.discal.api.object.calendar.CalendarData in project DisCal-Discord-Bot by NovaFox161.
the class EventCommand method issueCommand.
/**
* Issues the command this Object is responsible for.
*
* @param args The command arguments.
* @param event The event received.
* @return <code>true</code> if successful, else <code>false</code>.
*/
@Override
public Boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
long guildId = event.getGuild().getLongID();
// TODO: Add multiple calendar handling.
CalendarData calendarData = DatabaseManager.getManager().getMainCalendar(guildId);
if (args.length < 1) {
Message.sendMessage(MessageManager.getMessage("Notification.Args.Few", settings), event);
} else {
switch(args[0].toLowerCase()) {
case "create":
if (PermissionChecker.hasSufficientRole(event)) {
moduleCreate(args, event, calendarData, settings);
} else {
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
}
break;
case "copy":
if (PermissionChecker.hasSufficientRole(event)) {
moduleCopy(args, event, calendarData, settings);
} else {
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
}
break;
case "edit":
if (PermissionChecker.hasSufficientRole(event)) {
moduleEdit(args, event, calendarData, settings);
} else {
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
}
break;
case "restart":
if (PermissionChecker.hasSufficientRole(event)) {
moduleRestart(args, event, calendarData, settings);
} else {
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
}
break;
case "cancel":
if (PermissionChecker.hasSufficientRole(event)) {
moduleCancel(event, settings);
} else {
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
}
break;
case "delete":
if (PermissionChecker.hasSufficientRole(event)) {
moduleDelete(args, event, calendarData, settings);
} else {
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
}
break;
case "view":
moduleView(args, event, calendarData, settings);
break;
case "review":
moduleView(args, event, calendarData, settings);
break;
case "confirm":
if (PermissionChecker.hasSufficientRole(event)) {
moduleConfirm(event, calendarData, settings);
} else {
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
}
break;
case "startdate":
moduleStartDate(args, event, settings);
break;
case "start":
moduleStartDate(args, event, settings);
break;
case "enddate":
moduleEndDate(args, event, settings);
break;
case "end":
moduleEndDate(args, event, settings);
break;
case "summary":
moduleSummary(args, event, settings);
break;
case "description":
moduleDescription(args, event, settings);
break;
case "color":
moduleColor(args, event, settings);
break;
case "colour":
moduleColor(args, event, settings);
break;
case "location":
moduleLocation(args, event, settings);
break;
case "loc":
moduleLocation(args, event, settings);
break;
case "image":
moduleAttachment(args, event, settings);
break;
case "attachment":
moduleAttachment(args, event, settings);
break;
case "recur":
moduleRecur(args, event, settings);
break;
case "frequency":
moduleFrequency(args, event, settings);
break;
case "freq":
moduleFrequency(args, event, settings);
break;
case "count":
moduleCount(args, event, settings);
break;
case "interval":
moduleInterval(args, event, settings);
break;
default:
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("Notification.Args.Invalid", settings), event));
} else {
Message.sendMessage(MessageManager.getMessage("Notification.Args.Invalid", settings), event);
}
break;
}
}
return false;
}
use of com.cloudcraftgaming.discal.api.object.calendar.CalendarData in project DisCal-Discord-Bot by NovaFox161.
the class CalendarCreator method confirmCalendar.
/**
* Confirms the calendar and creates it within Google Calendar.
*
* @param e The event received upon confirmation.
* @return A CalendarCreatorResponse Object with detailed info about the confirmation.
*/
public CalendarCreatorResponse confirmCalendar(MessageReceivedEvent e, GuildSettings settings) {
if (hasPreCalendar(e.getMessage().getGuild().getLongID())) {
long guildId = e.getMessage().getGuild().getLongID();
PreCalendar preCalendar = getPreCalendar(guildId);
if (preCalendar.hasRequiredValues()) {
if (!preCalendar.isEditing()) {
Calendar calendar = new Calendar();
calendar.setSummary(preCalendar.getSummary());
calendar.setDescription(preCalendar.getDescription());
calendar.setTimeZone(preCalendar.getTimezone());
try {
com.google.api.services.calendar.Calendar service;
if (settings.useExternalCalendar()) {
service = CalendarAuth.getCalendarService(settings);
} else {
service = CalendarAuth.getCalendarService();
}
Calendar confirmed = service.calendars().insert(calendar).execute();
AclRule rule = new AclRule();
AclRule.Scope scope = new AclRule.Scope();
scope.setType("default");
rule.setScope(scope).setRole("reader");
service.acl().insert(confirmed.getId(), rule).execute();
CalendarData calendarData = new CalendarData(guildId, 1);
calendarData.setCalendarId(confirmed.getId());
calendarData.setCalendarAddress(confirmed.getId());
DatabaseManager.getManager().updateCalendar(calendarData);
terminate(e);
CalendarCreatorResponse response = new CalendarCreatorResponse(true, confirmed);
response.setEdited(false);
response.setCreatorMessage(preCalendar.getCreatorMessage());
return response;
} catch (Exception ex) {
Logger.getLogger().exception(e.getMessage().getAuthor(), "Failed to confirm calendar.", ex, this.getClass(), true);
CalendarCreatorResponse response = new CalendarCreatorResponse(false);
response.setEdited(false);
response.setCreatorMessage(preCalendar.getCreatorMessage());
return response;
}
} else {
// Editing calendar...
Calendar calendar = new Calendar();
calendar.setSummary(preCalendar.getSummary());
calendar.setDescription(preCalendar.getDescription());
calendar.setTimeZone(preCalendar.getTimezone());
try {
com.google.api.services.calendar.Calendar service;
if (settings.useExternalCalendar()) {
service = CalendarAuth.getCalendarService(settings);
} else {
service = CalendarAuth.getCalendarService();
}
Calendar confirmed = service.calendars().update(preCalendar.getCalendarId(), calendar).execute();
AclRule rule = new AclRule();
AclRule.Scope scope = new AclRule.Scope();
scope.setType("default");
rule.setScope(scope).setRole("reader");
service.acl().insert(confirmed.getId(), rule).execute();
terminate(e);
CalendarCreatorResponse response = new CalendarCreatorResponse(true, confirmed);
response.setEdited(true);
response.setCreatorMessage(preCalendar.getCreatorMessage());
return response;
} catch (Exception ex) {
Logger.getLogger().exception(e.getMessage().getAuthor(), "Failed to update calendar.", ex, this.getClass(), true);
CalendarCreatorResponse response = new CalendarCreatorResponse(false);
response.setEdited(true);
response.setCreatorMessage(preCalendar.getCreatorMessage());
return response;
}
}
}
}
return new CalendarCreatorResponse(false);
}
use of com.cloudcraftgaming.discal.api.object.calendar.CalendarData in project DisCal-Discord-Bot by NovaFox161.
the class EventMessageFormatter method getHumanReadableDateTime.
public static String getHumanReadableDateTime(@Nullable EventDateTime eventDateTime, GuildSettings settings, boolean preEvent) {
try {
if (eventDateTime == null) {
return "NOT SET";
} else {
// Get timezone
CalendarData data = DatabaseManager.getManager().getMainCalendar(settings.getGuildID());
String timezone;
if (!preEvent) {
if (settings.useExternalCalendar()) {
timezone = CalendarAuth.getCalendarService(settings).calendars().get(data.getCalendarAddress()).execute().getTimeZone();
} else {
timezone = CalendarAuth.getCalendarService().calendars().get(data.getCalendarAddress()).execute().getTimeZone();
}
} else {
timezone = "America/Chicago";
}
if (eventDateTime.getDateTime() != null) {
long dateTime = eventDateTime.getDateTime().getValue();
LocalDateTime ldt = LocalDateTime.ofInstant(Instant.ofEpochMilli(dateTime), ZoneId.of(timezone));
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy/MM/dd hh:mm:ss a");
return format.format(ldt);
} else {
long dateTime = eventDateTime.getDate().getValue();
LocalDateTime ldt = LocalDateTime.ofInstant(Instant.ofEpochMilli(dateTime), ZoneId.of(timezone));
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy/MM/dd hh:mm:ss a");
return format.format(ldt);
}
}
} catch (Exception e) {
Logger.getLogger().exception(null, "Failed to format date", e, EventMessageFormatter.class, true);
return "ERROR! Code: E003";
}
}
Aggregations