Search in sources :

Example 6 with Announcement

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

the class AnnouncementCreator method init.

public Announcement init(MessageReceivedEvent e, String announcementId, GuildSettings settings) {
    if (!hasAnnouncement(e.getGuild().getLongID()) && AnnouncementUtils.announcementExists(announcementId, e)) {
        Announcement toCopy = DatabaseManager.getManager().getAnnouncement(UUID.fromString(announcementId), e.getGuild().getLongID());
        // Copy
        Announcement a = new Announcement(toCopy);
        if (PermissionChecker.botHasMessageManagePerms(e)) {
            IMessage msg = Message.sendMessage(AnnouncementMessageFormatter.getFormatAnnouncementEmbed(a, settings), MessageManager.getMessage("Creator.Announcement.Copy.Success", settings), e);
            a.setCreatorMessage(msg);
        } else {
            Message.sendMessage(MessageManager.getMessage("Creator.Notif.MANAGE_MESSAGES", settings), e);
        }
        announcements.add(a);
        return a;
    }
    return getAnnouncement(e.getGuild().getLongID());
}
Also used : Announcement(com.cloudcraftgaming.discal.api.object.announcement.Announcement) IMessage(sx.blah.discord.handle.obj.IMessage)

Example 7 with Announcement

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

the class AnnouncementCreator method confirmAnnouncement.

/**
 * Confirms the announcement and enters it into the Database.
 * @param e The event received upon confirmation.
 * @return An AnnouncementCreatorResponse with detailed information.
 */
public AnnouncementCreatorResponse confirmAnnouncement(MessageReceivedEvent e) {
    if (hasAnnouncement(e.getGuild().getLongID())) {
        long guildId = e.getGuild().getLongID();
        Announcement a = getAnnouncement(guildId);
        if (a.hasRequiredValues()) {
            DatabaseManager.getManager().updateAnnouncement(a);
            terminate(e);
            return new AnnouncementCreatorResponse(true, a);
        }
    }
    return new AnnouncementCreatorResponse(false);
}
Also used : Announcement(com.cloudcraftgaming.discal.api.object.announcement.Announcement) AnnouncementCreatorResponse(com.cloudcraftgaming.discal.api.object.announcement.AnnouncementCreatorResponse)

Example 8 with Announcement

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

the class AnnouncementCommand method moduleUnsubscribe.

@Deprecated
@SuppressWarnings("unused")
private void moduleUnsubscribe(String[] args, MessageReceivedEvent event) {
    long guildId = event.getGuild().getLongID();
    if (args.length == 1) {
        Message.sendMessage("Please specify the ID of the announcement you wish to unsubscribe from!", event);
    } else if (args.length == 2) {
        String value = args[1];
        if (AnnouncementUtils.announcementExists(value, event)) {
            Announcement a = DatabaseManager.getManager().getAnnouncement(UUID.fromString(value), guildId);
            String senderId = event.getMessage().getAuthor().getStringID();
            if (a.getSubscriberUserIds().contains(senderId)) {
                a.getSubscriberUserIds().remove(senderId);
                DatabaseManager.getManager().updateAnnouncement(a);
                Message.sendMessage("You have unsubscribed to the announcement with the ID: `" + value + "`" + MessageUtils.lineBreak + "To re-subscribe use `!announcement subscribe <id>`", event);
            } else {
                Message.sendMessage("You are not subscribed to this event!", event);
            }
        } else {
            Message.sendMessage("Hmm.. it seems the specified announcement does not exist, are you sure you wrote the ID correctly?", event);
        }
    } else if (args.length == 3) {
        String value1 = args[1];
        String value2 = args[2];
        if (AnnouncementUtils.announcementExists(value1, event)) {
            Announcement a = DatabaseManager.getManager().getAnnouncement(UUID.fromString(value1), guildId);
            IUser user = UserUtils.getUserFromMention(value2, event);
            if (user != null) {
                // Valid user, let's add that user to the announcement.
                if (a.getSubscriberUserIds().contains(user.getStringID())) {
                    String username = user.getDisplayName(event.getMessage().getGuild());
                    a.getSubscriberUserIds().remove(user.getStringID());
                    DatabaseManager.getManager().updateAnnouncement(a);
                    Message.sendMessage("`" + username + "` has been unsubscribed from the announcement with the ID `" + a.getAnnouncementId() + "`" + MessageUtils.lineBreak + "To re-subscribe them use `!announcement subscribe <announcement ID> <mention>", event);
                } else {
                    Message.sendMessage("That user is not subscribed to the specified announcement! To subscribe them use `!announcement unsubscribe <announcement ID> <mention>`", event);
                }
            } else if (value2.equalsIgnoreCase("everyone") || value2.equalsIgnoreCase("here")) {
                // Here or everyone is to be mentioned...
                String men = value2.toLowerCase();
                if (a.getSubscriberRoleIds().contains(men)) {
                    a.getSubscriberRoleIds().remove(men);
                    DatabaseManager.getManager().updateAnnouncement(a);
                    Message.sendMessage("`" + men + "` has been unsubscribed from the announcement with the ID `" + a.getAnnouncementId() + "`" + MessageUtils.lineBreak + "To re-subscribe them use `!announcement subscribe <announcement ID> <value>", event);
                } else {
                    Message.sendMessage(men + " is not subscribed to the specified announcement! To subscribe them use `!announcement unsubscribe <announcement ID> <value>`", event);
                }
            } else {
                // User does not exist, see if a role.
                IRole role = RoleUtils.getRoleFromMention(value2, event);
                if (role != null) {
                    // Role valid, let's add that role to the announcement.
                    if (a.getSubscriberRoleIds().contains(role.getStringID())) {
                        String roleName = role.getName();
                        a.getSubscriberRoleIds().remove(role.getStringID());
                        DatabaseManager.getManager().updateAnnouncement(a);
                        Message.sendMessage("`" + roleName + "` has been unsubscribed from the announcement with the ID `" + a.getAnnouncementId() + "`" + MessageUtils.lineBreak + "To re-subscribe them use `!announcement subscribe <announcement ID> <mention>", event);
                    } else {
                        Message.sendMessage("That role is not subscribed to the specified announcement! To subscribe them use `!announcement unsubscribe <announcement ID> <mention>`", event);
                    }
                } else {
                    // Role does not exist...
                    Message.sendMessage("Role or user not found! Are you sure you typed them correctly?", event);
                }
            }
        } else {
            Message.sendMessage("Hmm.. it seems the specified announcement does not exist, are you sure you wrote the ID correctly?", event);
        }
    } else {
        Message.sendMessage("Please use `!announcement unsubscribe <ID>` or `!announcement unsubscribe <ID> <user mention/role mention/here/everyone>`", event);
    }
}
Also used : Announcement(com.cloudcraftgaming.discal.api.object.announcement.Announcement)

Example 9 with Announcement

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

the class AnnouncementCommand method moduleSubscribeRewriteArgsThree.

private void moduleSubscribeRewriteArgsThree(String[] args, MessageReceivedEvent event, GuildSettings settings) {
    IMessage message = event.getMessage();
    IGuild guild = message.getGuild();
    List<String> subscribedUsers = new ArrayList<>();
    List<String> subscribedRoles = new ArrayList<>();
    String announcementID;
    boolean updateDb;
    if (args[1].length() > 32) {
        AnnouncementCreator.getCreator().getAnnouncement(guild.getLongID());
        updateDb = true;
        announcementID = args[1];
    } else {
        updateDb = false;
        if (AnnouncementCreator.getCreator().hasAnnouncement(guild.getLongID())) {
            announcementID = AnnouncementCreator.getCreator().getAnnouncement(guild.getLongID()).getAnnouncementId().toString();
        } else {
            Message.sendMessage(MessageManager.getMessage("Creator.Announcement.Subscribe.Other.Specify", settings), event);
            return;
        }
    }
    if (AnnouncementUtils.announcementExists(announcementID, event) || !updateDb) {
        Announcement a = updateDb ? DatabaseManager.getManager().getAnnouncement(UUID.fromString(announcementID), guild.getLongID()) : AnnouncementCreator.getCreator().getAnnouncement(guild.getLongID());
        for (int i = 1; i < args.length; i++) {
            IUser u = guild.getUserByID(UserUtils.getUser(args[i].matches("<@?!?#?&?[0-9]+>") ? args[i].replaceAll("<@?!?#?&?[0-9]+>", "") : args[i], event.getGuild()));
            IRole r = guild.getRoleByID(RoleUtils.getRole(args[i].matches("<@?!?#?&?[0-9]+>") ? args[i].replaceAll("<@?!?#?&?[0-9]+>", "") : args[i], event.getGuild()));
            if (args[i].equalsIgnoreCase("everyone") || args[i].equalsIgnoreCase("here")) {
                // Here or everyone is to be subscribed...
                String men = args[i].toLowerCase();
                if (!a.getSubscriberRoleIds().contains(men)) {
                    a.getSubscriberRoleIds().add(men);
                    Message.sendMessage(MessageManager.getMessage("Creator.Announcement.Subscribe.Other.Success", "%value%", men, settings), event);
                    subscribedUsers.add(men);
                } else {
                    Message.sendMessage(MessageManager.getMessage("Creator.Announcement.Subscribe.Other.Already", "%value%", men, settings), event);
                }
            }
            if (u != null) {
                if (!a.getSubscriberUserIds().contains(u.getStringID())) {
                    subscribedUsers.add(u.getName());
                    a.getSubscriberUserIds().add(u.getStringID());
                }
            } else if (r != null) {
                if (!a.getSubscriberRoleIds().contains(r.getStringID())) {
                    subscribedRoles.add(r.getName());
                    a.getSubscriberRoleIds().add(r.getStringID());
                }
            }
        }
        EmbedBuilder em = new EmbedBuilder();
        em.withColor(EventColor.TURQUOISE.getR(), EventColor.TURQUOISE.getG(), EventColor.TURQUOISE.getB());
        em.withAuthorIcon(event.getClient().getApplicationIconURL());
        em.withAuthorName(MessageManager.getMessage("Embed.Announcement.Subscribe.Title", settings));
        em.withDesc(MessageManager.getMessage("Embed.Announcement.Subscribe.Users", "%users%", subscribedUsers.toString(), settings) + MessageUtils.lineBreak + MessageManager.getMessage("Embed.Announcement.Subscribe.Roles", "%roles%", subscribedRoles.toString(), settings));
        em.withFooterText(MessageManager.getMessage("Embed.Announcement.Subscribe.Footer", "%id%", a.getAnnouncementId().toString(), settings));
        Message.sendMessage(em.build(), event);
        if (updateDb) {
            DatabaseManager.getManager().updateAnnouncement(a);
        }
    } else {
        Message.sendMessage(MessageManager.getMessage("Creator.Announcement.CannotFind.Announcement", settings), event);
    }
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) Announcement(com.cloudcraftgaming.discal.api.object.announcement.Announcement) ArrayList(java.util.ArrayList)

Example 10 with Announcement

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

the class AnnouncementCommand method moduleEnable.

private void moduleEnable(String[] args, MessageReceivedEvent event, GuildSettings settings) {
    long guildId = event.getGuild().getLongID();
    if (args.length == 2) {
        if (AnnouncementCreator.getCreator().hasAnnouncement(guildId)) {
            Message.sendMessage(MessageManager.getMessage("Announcement.Enable.Creator", settings), event);
        } else {
            String value = args[1];
            if (!AnnouncementUtils.announcementExists(value, event)) {
                Message.sendMessage(MessageManager.getMessage("Creator.Announcement.CannotFind.Announcement", settings), event);
            } else {
                Announcement a = DatabaseManager.getManager().getAnnouncement(UUID.fromString(value), guildId);
                a.setEnabled(!a.isEnabled());
                DatabaseManager.getManager().updateAnnouncement(a);
                Message.sendMessage(MessageManager.getMessage("Announcement.Enable.Success", "%value%", a.isEnabled() + "", settings), event);
            }
        }
    } else {
        Message.sendMessage(MessageManager.getMessage("Announcement.Enable.Specify", settings), event);
    }
}
Also used : Announcement(com.cloudcraftgaming.discal.api.object.announcement.Announcement)

Aggregations

Announcement (com.cloudcraftgaming.discal.api.object.announcement.Announcement)28 ArrayList (java.util.ArrayList)7 JSONException (org.json.JSONException)6 JSONObject (org.json.JSONObject)4 IMessage (sx.blah.discord.handle.obj.IMessage)3 WebGuild (com.cloudcraftgaming.discal.api.object.web.WebGuild)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)2 AnnouncementType (com.cloudcraftgaming.discal.api.enums.announcement.AnnouncementType)1 GuildSettings (com.cloudcraftgaming.discal.api.object.GuildSettings)1 AnnouncementCreatorResponse (com.cloudcraftgaming.discal.api.object.announcement.AnnouncementCreatorResponse)1 CalendarData (com.cloudcraftgaming.discal.api.object.calendar.CalendarData)1 PreCalendar (com.cloudcraftgaming.discal.api.object.calendar.PreCalendar)1 PreEvent (com.cloudcraftgaming.discal.api.object.event.PreEvent)1 Calendar (com.google.api.services.calendar.Calendar)1 Event (com.google.api.services.calendar.model.Event)1 IOException (java.io.IOException)1