Search in sources :

Example 6 with PreEvent

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());
}
Also used : PreEvent(com.cloudcraftgaming.discal.api.object.event.PreEvent) IMessage(sx.blah.discord.handle.obj.IMessage) IOException(java.io.IOException)

Example 7 with PreEvent

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);
    }
}
Also used : PreEvent(com.cloudcraftgaming.discal.api.object.event.PreEvent)

Example 8 with PreEvent

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);
        }
    }
}
Also used : PreEvent(com.cloudcraftgaming.discal.api.object.event.PreEvent)

Example 9 with PreEvent

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());
}
Also used : PreEvent(com.cloudcraftgaming.discal.api.object.event.PreEvent) IMessage(sx.blah.discord.handle.obj.IMessage) IOException(java.io.IOException)

Example 10 with PreEvent

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;
}
Also used : PreEvent(com.cloudcraftgaming.discal.api.object.event.PreEvent)

Aggregations

PreEvent (com.cloudcraftgaming.discal.api.object.event.PreEvent)10 IOException (java.io.IOException)4 IMessage (sx.blah.discord.handle.obj.IMessage)3 Event (com.google.api.services.calendar.model.Event)2 MessageReceivedEvent (sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent)2 Announcement (com.cloudcraftgaming.discal.api.object.announcement.Announcement)1 PreCalendar (com.cloudcraftgaming.discal.api.object.calendar.PreCalendar)1 EventCreatorResponse (com.cloudcraftgaming.discal.api.object.event.EventCreatorResponse)1 Calendar (com.google.api.services.calendar.Calendar)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1