Search in sources :

Example 1 with WebCalendar

use of com.cloudcraftgaming.discal.api.object.web.WebCalendar in project DisCal-Discord-Bot by NovaFox161.

the class DashboardHandler method handleCalendarCreate.

public static String handleCalendarCreate(Request request, Response response) {
    try {
        String name = request.queryParams("cal-name");
        String desc = request.queryParams("cal-desc");
        String tz = request.queryParams("cal-tz");
        Map m = DiscordAccountHandler.getHandler().getAccount(request.session().id());
        WebGuild g = (WebGuild) m.get("selected");
        if (g.isDiscalRole()) {
            Calendar calendar = new Calendar();
            calendar.setSummary(name);
            calendar.setDescription(desc);
            calendar.setTimeZone(tz.replace("___", "/"));
            try {
                com.google.api.services.calendar.Calendar service;
                if (g.getSettings().useExternalCalendar()) {
                    service = CalendarAuth.getCalendarService(g.getSettings());
                } 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(Long.valueOf(g.getId()), 1);
                calendarData.setCalendarId(confirmed.getId());
                calendarData.setCalendarAddress(confirmed.getId());
                DatabaseManager.getManager().updateCalendar(calendarData);
                // Refresh to display correct info...
                g.setCalendar(new WebCalendar().fromCalendar(calendarData, g.getSettings()));
            } catch (Exception ex) {
                Logger.getLogger().exception(null, "[WEB] Failed to confirm calendar.", ex, DashboardHandler.class, true);
            }
        }
        // Finally redirect back to the dashboard
        response.redirect("/dashboard/guild/calendar", 301);
    } catch (Exception e) {
        Logger.getLogger().exception(null, "[WEB] Calendar create failed!", e, DashboardHandler.class, true);
        halt(500, "Internal Server Exception");
    }
    return response.body();
}
Also used : Calendar(com.google.api.services.calendar.model.Calendar) WebCalendar(com.cloudcraftgaming.discal.api.object.web.WebCalendar) WebGuild(com.cloudcraftgaming.discal.api.object.web.WebGuild) WebCalendar(com.cloudcraftgaming.discal.api.object.web.WebCalendar) JSONException(org.json.JSONException) CalendarData(com.cloudcraftgaming.discal.api.object.calendar.CalendarData) AclRule(com.google.api.services.calendar.model.AclRule) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with WebCalendar

use of com.cloudcraftgaming.discal.api.object.web.WebCalendar in project DisCal-Discord-Bot by NovaFox161.

the class DashboardHandler method deleteCalendar.

public static String deleteCalendar(Request request, Response response) {
    try {
        // TODO: Handle multiple calendars...
        String calId = request.queryParams("calendar-id");
        Map m = DiscordAccountHandler.getHandler().getAccount(request.session().id());
        WebGuild g = (WebGuild) m.get("selected");
        if (g.isManageServer()) {
            CalendarData data = DatabaseManager.getManager().getMainCalendar(Long.valueOf(g.getId()));
            GuildSettings settings = DatabaseManager.getManager().getSettings(Long.valueOf(g.getId()));
            CalendarUtils.deleteCalendar(data, settings);
            g.setCalendar(new WebCalendar().fromCalendar(DatabaseManager.getManager().getMainCalendar(Long.valueOf(g.getId())), DatabaseManager.getManager().getSettings(Long.valueOf(g.getId()))));
            response.redirect("/dashboard/guild/calendar", 301);
        } else {
            response.redirect("/dashboard/guild/calendar", 301);
        }
    } catch (Exception e) {
        Logger.getLogger().exception(null, "[WEB] Failed to delete/remove calendar!", e, DashboardHandler.class, true);
    }
    return response.body();
}
Also used : CalendarData(com.cloudcraftgaming.discal.api.object.calendar.CalendarData) WebGuild(com.cloudcraftgaming.discal.api.object.web.WebGuild) WebCalendar(com.cloudcraftgaming.discal.api.object.web.WebCalendar) HashMap(java.util.HashMap) Map(java.util.Map) GuildSettings(com.cloudcraftgaming.discal.api.object.GuildSettings) JSONException(org.json.JSONException)

Aggregations

CalendarData (com.cloudcraftgaming.discal.api.object.calendar.CalendarData)2 WebCalendar (com.cloudcraftgaming.discal.api.object.web.WebCalendar)2 WebGuild (com.cloudcraftgaming.discal.api.object.web.WebGuild)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JSONException (org.json.JSONException)2 GuildSettings (com.cloudcraftgaming.discal.api.object.GuildSettings)1 AclRule (com.google.api.services.calendar.model.AclRule)1 Calendar (com.google.api.services.calendar.model.Calendar)1