use of com.cloudcraftgaming.discal.api.object.event.PreEvent in project DisCal-Discord-Bot by NovaFox161.
the class EventCreator method init.
public PreEvent init(MessageReceivedEvent e, GuildSettings settings, String summary, boolean handleMessage) {
if (!hasPreEvent(e.getGuild().getLongID())) {
PreEvent event = new PreEvent(e.getGuild().getLongID());
event.setSummary(summary);
try {
// TODO: Handle multiple calendars...
String calId = DatabaseManager.getManager().getMainCalendar(e.getGuild().getLongID()).getCalendarAddress();
if (!settings.useExternalCalendar()) {
event.setTimeZone(CalendarAuth.getCalendarService().calendars().get(calId).execute().getTimeZone());
} else {
event.setTimeZone(CalendarAuth.getCalendarService(settings).calendars().get(calId).execute().getTimeZone());
}
} catch (Exception exc) {
// Failed to get timezone, ignore safely.
}
if (handleMessage) {
if (PermissionChecker.botHasMessageManagePerms(e)) {
IMessage message = Message.sendMessage(EventMessageFormatter.getPreEventEmbed(event, settings), MessageManager.getMessage("Creator.Event.Create.Init", settings), e);
event.setCreatorMessage(message);
Message.deleteMessage(e);
} else {
Message.sendMessage(MessageManager.getMessage("Creator.Notif.MANAGE_MESSAGES", settings), e);
}
}
events.add(event);
return event;
}
return getPreEvent(e.getGuild().getLongID());
}
use of com.cloudcraftgaming.discal.api.object.event.PreEvent in project DisCal-Discord-Bot by NovaFox161.
the class EventCommand method moduleCopy.
private void moduleCopy(String[] args, MessageReceivedEvent event, CalendarData calendarData, GuildSettings settings) {
long guildId = event.getGuild().getLongID();
if (!calendarData.getCalendarAddress().equalsIgnoreCase("primary")) {
if (!EventCreator.getCreator().hasPreEvent(guildId)) {
if (args.length == 2) {
String eventId = args[1];
if (EventUtils.eventExists(settings, eventId)) {
PreEvent preEvent = EventCreator.getCreator().init(event, eventId, settings, true);
if (preEvent != null) {
if (preEvent.getCreatorMessage() == null) {
Message.sendMessage(EventMessageFormatter.getPreEventEmbed(preEvent, settings), MessageManager.getMessage("Creator.Event.Copy.Init", settings), event);
}
} else {
Message.sendMessage(MessageManager.getMessage("Notification.Error.Unknown", settings), event);
}
} else {
Message.sendMessage(MessageManager.getMessage("Creator.Event.NotFound", settings), event);
}
} else {
Message.sendMessage(MessageManager.getMessage("Creator.Event.Copy.Specify", settings), event);
}
} else {
if (EventCreator.getCreator().getPreEvent(guildId).getCreatorMessage() != null) {
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.AlreadyInit", settings), event));
} else {
Message.sendMessage(MessageManager.getMessage("Creator.Event.AlreadyInit", settings), event);
}
}
} else {
Message.sendMessage(MessageManager.getMessage("Creator.Event.NoCalendar", settings), event);
}
}
use of com.cloudcraftgaming.discal.api.object.event.PreEvent in project DisCal-Discord-Bot by NovaFox161.
the class EventCommand method moduleCreate.
private void moduleCreate(String[] args, MessageReceivedEvent event, CalendarData calendarData, GuildSettings settings) {
long guildId = event.getGuild().getLongID();
if (EventCreator.getCreator().hasPreEvent(guildId)) {
if (EventCreator.getCreator().getPreEvent(guildId).getCreatorMessage() != null) {
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.AlreadyInit", settings), event));
} else {
Message.sendMessage(MessageManager.getMessage("Creator.Event.AlreadyInit", settings), event);
}
} else {
if (!calendarData.getCalendarAddress().equalsIgnoreCase("primary")) {
PreEvent e;
if (args.length == 1) {
e = EventCreator.getCreator().init(event, settings, true);
} else {
e = EventCreator.getCreator().init(event, settings, GeneralUtils.getContent(args, 1), true);
}
if (e.getCreatorMessage() == null) {
Message.sendMessage(MessageManager.getMessage("Creator.Event.Create.Init", settings), event);
}
} else {
Message.sendMessage(MessageManager.getMessage("Creator.Event.NoCalendar", settings), event);
}
}
}
use of com.cloudcraftgaming.discal.api.object.event.PreEvent in project DisCal-Discord-Bot by NovaFox161.
the class EventCreator method init.
// Functionals
/**
* Initiates the EventCreator for a specific guild.
*
* @param e The event received upon initialization.
* @return The PreEvent for the guild.
*/
public PreEvent init(MessageReceivedEvent e, GuildSettings settings, boolean handleMessage) {
if (!hasPreEvent(e.getGuild().getLongID())) {
PreEvent event = new PreEvent(e.getGuild().getLongID());
try {
// TODO: Handle multiple calendars...
String calId = DatabaseManager.getManager().getMainCalendar(e.getGuild().getLongID()).getCalendarAddress();
event.setTimeZone(CalendarAuth.getCalendarService().calendars().get(calId).execute().getTimeZone());
} catch (IOException exc) {
// Failed to get timezone, ignore safely.
}
if (handleMessage) {
if (PermissionChecker.botHasMessageManagePerms(e)) {
IMessage message = Message.sendMessage(EventMessageFormatter.getPreEventEmbed(event, settings), MessageManager.getMessage("Creator.Event.Create.Init", settings), e);
event.setCreatorMessage(message);
Message.deleteMessage(e);
} else {
Message.sendMessage(MessageManager.getMessage("Creator.Notif.MANAGE_MESSAGES", settings), e);
}
}
events.add(event);
return event;
}
return getPreEvent(e.getGuild().getLongID());
}
use of com.cloudcraftgaming.discal.api.object.event.PreEvent in project DisCal-Discord-Bot by NovaFox161.
the class EventUtils method copyEvent.
public static PreEvent copyEvent(long guildId, Event event) {
PreEvent pe = new PreEvent(guildId);
pe.setSummary(event.getSummary());
pe.setDescription(event.getDescription());
pe.setLocation(event.getLocation());
if (event.getColorId() != null) {
pe.setColor(EventColor.fromNameOrHexOrID(event.getColorId()));
} else {
pe.setColor(EventColor.RED);
}
pe.setEventData(DatabaseManager.getManager().getEventData(guildId, event.getId()));
return pe;
}
Aggregations