Search in sources :

Example 1 with AnnouncementType

use of com.cloudcraftgaming.discal.api.enums.announcement.AnnouncementType in project DisCal-Discord-Bot by NovaFox161.

the class AnnouncementCommand method moduleType.

private void moduleType(String[] args, MessageReceivedEvent event, GuildSettings settings) {
    long guildId = event.getGuild().getLongID();
    if (args.length == 2) {
        String value = args[1];
        if (AnnouncementCreator.getCreator().hasAnnouncement(guildId)) {
            if (AnnouncementType.isValid(value)) {
                AnnouncementType type = AnnouncementType.fromValue(value);
                AnnouncementCreator.getCreator().getAnnouncement(guildId).setAnnouncementType(type);
                if (type.equals(AnnouncementType.SPECIFIC)) {
                    if (AnnouncementCreator.getCreator().hasCreatorMessage(guildId)) {
                        Message.deleteMessage(AnnouncementCreator.getCreator().getCreatorMessage(guildId));
                        Message.deleteMessage(event);
                        AnnouncementCreator.getCreator().setCreatorMessage(Message.sendMessage(AnnouncementMessageFormatter.getFormatAnnouncementEmbed(AnnouncementCreator.getCreator().getAnnouncement(guildId), settings), MessageManager.getMessage("Creator.Announcement.Type.Success.Specific", settings), event));
                    } else {
                        Message.sendMessage(MessageManager.getMessage("Creator.Announcement.Type.Success.Specific", settings), event);
                    }
                } else if (type.equals(AnnouncementType.COLOR)) {
                    if (AnnouncementCreator.getCreator().hasCreatorMessage(guildId)) {
                        Message.deleteMessage(AnnouncementCreator.getCreator().getCreatorMessage(guildId));
                        Message.deleteMessage(event);
                        AnnouncementCreator.getCreator().setCreatorMessage(Message.sendMessage(AnnouncementMessageFormatter.getFormatAnnouncementEmbed(AnnouncementCreator.getCreator().getAnnouncement(guildId), settings), MessageManager.getMessage("Creator.Announcement.Type.Success.Color", settings), event));
                    } else {
                        Message.sendMessage(MessageManager.getMessage("Creator.Announcement.Type.Success.Color", settings), event);
                    }
                } else if (type.equals(AnnouncementType.RECUR)) {
                    if (AnnouncementCreator.getCreator().hasCreatorMessage(guildId)) {
                        Message.deleteMessage(AnnouncementCreator.getCreator().getCreatorMessage(guildId));
                        Message.deleteMessage(event);
                        AnnouncementCreator.getCreator().setCreatorMessage(Message.sendMessage(AnnouncementMessageFormatter.getFormatAnnouncementEmbed(AnnouncementCreator.getCreator().getAnnouncement(guildId), settings), MessageManager.getMessage("Creator.Announcement.Type.Success.Recur", settings), event));
                    } else {
                        Message.sendMessage(MessageManager.getMessage("Creator.Announcement.Type.Success.Recur", settings), event);
                    }
                } else {
                    if (AnnouncementCreator.getCreator().hasCreatorMessage(guildId)) {
                        Message.deleteMessage(AnnouncementCreator.getCreator().getCreatorMessage(guildId));
                        Message.deleteMessage(event);
                        AnnouncementCreator.getCreator().setCreatorMessage(Message.sendMessage(AnnouncementMessageFormatter.getFormatAnnouncementEmbed(AnnouncementCreator.getCreator().getAnnouncement(guildId), settings), MessageManager.getMessage("Creator.Announcement.Type.Success.Universal", settings), event));
                    } else {
                        Message.sendMessage(MessageManager.getMessage("Creator.Announcement.Type.Success.Universal", settings), event);
                    }
                }
            } else {
                if (AnnouncementCreator.getCreator().hasCreatorMessage(guildId)) {
                    Message.deleteMessage(AnnouncementCreator.getCreator().getCreatorMessage(guildId));
                    Message.deleteMessage(event);
                    AnnouncementCreator.getCreator().setCreatorMessage(Message.sendMessage(AnnouncementMessageFormatter.getFormatAnnouncementEmbed(AnnouncementCreator.getCreator().getAnnouncement(guildId), settings), MessageManager.getMessage("Creator.Announcement.Type.Specify", settings), event));
                } else {
                    Message.sendMessage(MessageManager.getMessage("Creator.Announcement.Type.Specify", settings), event);
                }
            }
        } else {
            Message.sendMessage(MessageManager.getMessage("Creator.Announcement.NotInit", settings), event);
        }
    } else {
        Message.sendMessage(MessageManager.getMessage("Creator.Announcement.Type.Specify", settings), event);
    }
}
Also used : AnnouncementType(com.cloudcraftgaming.discal.api.enums.announcement.AnnouncementType)

Example 2 with AnnouncementType

use of com.cloudcraftgaming.discal.api.enums.announcement.AnnouncementType 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)

Aggregations

AnnouncementType (com.cloudcraftgaming.discal.api.enums.announcement.AnnouncementType)2 Announcement (com.cloudcraftgaming.discal.api.object.announcement.Announcement)1 WebGuild (com.cloudcraftgaming.discal.api.object.web.WebGuild)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JSONException (org.json.JSONException)1