use of com.cloudcraftgaming.discal.api.object.announcement.Announcement in project DisCal-Discord-Bot by NovaFox161.
the class AnnouncementEndpoint method getAnnouncement.
public static String getAnnouncement(Request request, Response response) {
try {
JSONObject jsonMain = new JSONObject(request.body());
Long guildId = jsonMain.getLong("guild_id");
String announcementId = jsonMain.getString("id");
Announcement a = DatabaseManager.getManager().getAnnouncement(UUID.fromString(announcementId), guildId);
if (a != null) {
response.type("application/json");
response.status(200);
JSONObject body = new JSONObject();
body.put("channel", a.getAnnouncementChannelId());
body.put("event_id", a.getEventId());
body.put("event_color", a.getEventColor().name());
body.put("type", a.getAnnouncementType().name());
body.put("hours", a.getHoursBefore());
body.put("minutes", a.getMinutesBefore());
body.put("info", a.getInfo());
body.put("enabled", a.isEnabled());
body.put("info_only", a.isInfoOnly());
body.put("subscribers_role", a.getSubscriberRoleIds());
body.put("subscribers_user", a.getSubscriberUserIds());
response.body(body.toString());
} else {
response.type("application/json");
response.status(404);
response.body(ResponseUtils.getJsonResponseMessage("Announcement not found."));
}
} catch (JSONException e) {
e.printStackTrace();
halt(400, "Bad Request");
} catch (Exception e) {
Logger.getLogger().exception(null, "[WEB-API] Internal get announcement error", e, AnnouncementEndpoint.class, true);
halt(500, "Internal Server Error");
}
return response.body();
}
use of com.cloudcraftgaming.discal.api.object.announcement.Announcement 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.announcement.Announcement 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