Search in sources :

Example 11 with WebGuild

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

the class DashboardHandler method deleteAnnouncement.

public static String deleteAnnouncement(Request request, Response response) {
    try {
        String announcementId = request.queryParams("id");
        Map m = DiscordAccountHandler.getHandler().getAccount(request.session().id());
        WebGuild g = (WebGuild) m.get("selected");
        if (g.isManageServer()) {
            DatabaseManager.getManager().deleteAnnouncement(announcementId);
            // Update announcements list to display correctly.
            g.getAnnouncements().clear();
            g.getAnnouncements().addAll(DatabaseManager.getManager().getAnnouncements(Long.valueOf(g.getId())));
        }
        response.redirect("/dashboard/guild/announcements", 301);
    } catch (Exception e) {
        Logger.getLogger().exception(null, "[WEB] Failed to delete announcement!", e, DashboardHandler.class, true);
    }
    return response.body();
}
Also used : WebGuild(com.cloudcraftgaming.discal.api.object.web.WebGuild) HashMap(java.util.HashMap) Map(java.util.Map) JSONException(org.json.JSONException)

Example 12 with WebGuild

use of com.cloudcraftgaming.discal.api.object.web.WebGuild 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)

Example 13 with WebGuild

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

the class DashboardHandler method handleAnnouncementCreate.

public static String handleAnnouncementCreate(Request request, Response response) {
    try {
        String channelId = request.queryParams("channel");
        AnnouncementType type = AnnouncementType.fromValue(request.queryParams("type"));
        // Skip event ID or color here, only get it later if needed.
        String minutesRaw = request.queryParams("minutes");
        String hoursRaw = request.queryParams("hours");
        String info = request.queryParams("info");
        Map m = DiscordAccountHandler.getHandler().getAccount(request.session().id());
        WebGuild g = (WebGuild) m.get("selected");
        if (g.isDiscalRole()) {
            Announcement a = new Announcement(Long.valueOf(g.getId()));
            a.setAnnouncementChannelId(channelId);
            a.setMinutesBefore(Integer.valueOf(minutesRaw));
            a.setHoursBefore(Integer.valueOf(hoursRaw));
            a.setInfo(info);
            a.setAnnouncementType(type);
            if (type == AnnouncementType.COLOR) {
                a.setEventColor(EventColor.fromNameOrHexOrID(request.queryParams("color")));
            } else if (type == AnnouncementType.SPECIFIC) {
                a.setEventId(request.queryParams("event-id"));
            } else if (type == AnnouncementType.RECUR) {
                String value = request.queryParams("event-id");
                if (value.contains("_")) {
                    String[] stuff = value.split("_");
                    value = stuff[0];
                }
                a.setEventId(value);
            }
            // Create announcement
            DatabaseManager.getManager().updateAnnouncement(a);
            // Update WebGuild to display correctly...
            g.getAnnouncements().clear();
            g.getAnnouncements().addAll(DatabaseManager.getManager().getAnnouncements(Long.valueOf(g.getId())));
        }
        // Finally redirect back to the dashboard
        response.redirect("/dashboard/guild/announcements", 301);
    } catch (Exception e) {
        Logger.getLogger().exception(null, "[WEB] Announcement create failed!", e, DashboardHandler.class, true);
        halt(500, "Internal Server Exception");
    }
    return response.body();
}
Also used : Announcement(com.cloudcraftgaming.discal.api.object.announcement.Announcement) WebGuild(com.cloudcraftgaming.discal.api.object.web.WebGuild) HashMap(java.util.HashMap) Map(java.util.Map) JSONException(org.json.JSONException) AnnouncementType(com.cloudcraftgaming.discal.api.enums.announcement.AnnouncementType)

Example 14 with WebGuild

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

the class DashboardHandler method handleAnnouncementUpdate.

public static String handleAnnouncementUpdate(Request request, Response response) {
    try {
        String announcementId = request.queryParams("id");
        Map m = DiscordAccountHandler.getHandler().getAccount(request.session().id());
        WebGuild g = (WebGuild) m.get("selected");
        if (g.isManageServer()) {
            Announcement a = DatabaseManager.getManager().getAnnouncement(UUID.fromString(announcementId), Long.valueOf(g.getId()));
            a.setAnnouncementChannelId(request.queryParams("channel"));
            a.setAnnouncementType(AnnouncementType.fromValue(request.queryParams("type")));
            if (a.getAnnouncementType() == AnnouncementType.COLOR) {
                a.setEventColor(EventColor.fromNameOrHexOrID(request.queryParams("color")));
            } else if (a.getAnnouncementType() == AnnouncementType.SPECIFIC || a.getAnnouncementType() == AnnouncementType.RECUR) {
                String value = request.queryParams("event-id");
                if (value.contains("_")) {
                    String[] stuff = value.split("_");
                    value = stuff[0];
                }
                a.setEventId(value);
            }
            a.setMinutesBefore(Integer.valueOf(request.queryParams("minutes")));
            a.setHoursBefore(Integer.valueOf(request.queryParams("hours")));
            a.setInfo(request.queryParams("info"));
            DatabaseManager.getManager().updateAnnouncement(a);
            // Update announcements list to display correctly.
            g.getAnnouncements().clear();
            g.getAnnouncements().addAll(DatabaseManager.getManager().getAnnouncements(Long.valueOf(g.getId())));
        }
        response.redirect("/dashboard/guild/announcements", 301);
    } catch (Exception e) {
        Logger.getLogger().exception(null, "[WEB] Failed to update/edit announcement!", e, DashboardHandler.class, true);
    }
    return response.body();
}
Also used : Announcement(com.cloudcraftgaming.discal.api.object.announcement.Announcement) WebGuild(com.cloudcraftgaming.discal.api.object.web.WebGuild) HashMap(java.util.HashMap) Map(java.util.Map) JSONException(org.json.JSONException)

Aggregations

WebGuild (com.cloudcraftgaming.discal.api.object.web.WebGuild)14 Map (java.util.Map)13 HashMap (java.util.HashMap)8 JSONException (org.json.JSONException)8 GuildSettings (com.cloudcraftgaming.discal.api.object.GuildSettings)6 CalendarData (com.cloudcraftgaming.discal.api.object.calendar.CalendarData)6 JSONObject (org.json.JSONObject)5 DateTime (com.google.api.client.util.DateTime)4 Calendar (com.google.api.services.calendar.Calendar)4 Event (com.google.api.services.calendar.model.Event)4 EventDateTime (com.google.api.services.calendar.model.EventDateTime)4 EventData (com.cloudcraftgaming.discal.api.object.event.EventData)3 Recurrence (com.cloudcraftgaming.discal.api.object.event.Recurrence)3 WebCalendar (com.cloudcraftgaming.discal.api.object.web.WebCalendar)3 ArrayList (java.util.ArrayList)3 IGuild (sx.blah.discord.handle.obj.IGuild)3 Announcement (com.cloudcraftgaming.discal.api.object.announcement.Announcement)2 Calendar (com.google.api.services.calendar.model.Calendar)2 Events (com.google.api.services.calendar.model.Events)2 IUser (sx.blah.discord.handle.obj.IUser)2