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();
}
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();
}
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();
}
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();
}
Aggregations