Search in sources :

Example 11 with ScheduleEntry

use of ws.nmathe.saber.core.schedule.ScheduleEntry in project Saber-Bot by notem.

the class SkipCommand method action.

@Override
public void action(String prefix, String[] args, MessageReceivedEvent event) {
    int index = 0;
    Integer entryId = ParsingUtilities.encodeIDToInt(args[index++]);
    ScheduleEntry se = Main.getEntryManager().getEntryFromGuild(entryId, event.getGuild().getId());
    // send a confirmation to the channel
    String content;
    if (se.getRecurrence().shouldRepeat(se.getStart())) {
        se.repeat();
        content = "The event has been cancelled.\n" + "The event is next scheduled for " + se.getStart().format(DateTimeFormatter.ofPattern("MMM d, hh:mm a"));
    } else {
        se.repeat();
        content = "The event has been cancelled.";
    }
    MessageUtilities.sendMsg(content, event.getTextChannel(), null);
}
Also used : ScheduleEntry(ws.nmathe.saber.core.schedule.ScheduleEntry)

Example 12 with ScheduleEntry

use of ws.nmathe.saber.core.schedule.ScheduleEntry in project Saber-Bot by notem.

the class ManageCommand method verify.

@Override
public String verify(String prefix, String[] args, MessageReceivedEvent event) {
    String head = prefix + this.name();
    int index = 0;
    if (args.length < 3) {
        return "Incorrect amount of arguments!" + "\nUse ``" + head + " <id> <add|kick> <group> <@user>``";
    }
    // verify valid entry ID
    ScheduleEntry entry;
    if (VerifyUtilities.verifyEntryID(args[index])) {
        Integer entryId = ParsingUtilities.encodeIDToInt(args[index]);
        entry = Main.getEntryManager().getEntryFromGuild(entryId, event.getGuild().getId());
        if (entry == null) {
            return "The requested entry does not exist!";
        }
    } else {
        return "Argument *" + args[0] + "* is not a valid entry ID!";
    }
    // verify the schedule has RSVP enabled
    if (!Main.getScheduleManager().isRSVPEnabled(entry.getChannelId())) {
        return "That event is not on an RSVP enabled schedule!";
    }
    // verify valid action argument
    index++;
    switch(args[index].toLowerCase()) {
        case "a":
        case "add":
        case "k":
        case "kick":
            break;
        default:
            return "*" + args[index] + "* is not a valid action argument!\n" + "Please use either *add* or *kick*!";
    }
    // verify the group is a valid group
    index++;
    Map<String, String> options = Main.getScheduleManager().getRSVPOptions(entry.getChannelId());
    if (!options.values().contains(args[index])) {
        return "There is no RSVP group called *" + args[index] + "* on the event!";
    }
    return "";
}
Also used : ScheduleEntry(ws.nmathe.saber.core.schedule.ScheduleEntry)

Example 13 with ScheduleEntry

use of ws.nmathe.saber.core.schedule.ScheduleEntry in project Saber-Bot by notem.

the class ConfigCommand method action.

@Override
public void action(String head, String[] args, MessageReceivedEvent event) {
    int index = 0;
    String cId = args[index].replaceAll("[^\\d]", "");
    TextChannel scheduleChan = event.getGuild().getTextChannelById(cId);
    index++;
    if (args.length > 1) {
        switch(args[index++].toLowerCase()) {
            case "m":
            case "msg":
            case "message":
                String msgFormat = formatHelper(args[index]);
                Main.getScheduleManager().setAnnounceFormat(scheduleChan.getId(), msgFormat);
                MessageUtilities.sendMsg(this.genMsgStr(cId, Mode.ANN, event.getJDA()), event.getChannel(), null);
                break;
            case "ch":
            case "chan":
            case "channel":
                String chanIdentifier = chanHelper(args[index], event);
                Main.getScheduleManager().setAnnounceChan(scheduleChan.getId(), chanIdentifier);
                MessageUtilities.sendMsg(this.genMsgStr(cId, Mode.ANN, event.getJDA()), event.getChannel(), null);
                break;
            case "em":
            case "end-msg":
            case "end-message":
                String endFormat;
                endFormat = formatHelper(args[index]);
                Main.getScheduleManager().setEndAnnounceFormat(scheduleChan.getId(), endFormat);
                MessageUtilities.sendMsg(this.genMsgStr(cId, Mode.ANN, event.getJDA()), event.getChannel(), null);
                break;
            case "ech":
            case "end-chan":
            case "end-channel":
                String endChanIdentifier;
                switch(args[index].toLowerCase()) {
                    case "reset":
                    case "default":
                    case "null":
                        endChanIdentifier = null;
                        break;
                    default:
                        endChanIdentifier = chanHelper(args[index], event);
                }
                Main.getScheduleManager().setEndAnnounceChan(scheduleChan.getId(), endChanIdentifier);
                MessageUtilities.sendMsg(this.genMsgStr(cId, Mode.ANN, event.getJDA()), event.getChannel(), null);
                break;
            case "z":
            case "zone":
                ZoneId zone = ParsingUtilities.parseZone(args[index]);
                Main.getScheduleManager().setTimeZone(scheduleChan.getId(), zone);
                // correct/reload the event displays
                Main.getDBDriver().getEventCollection().find(eq("channelId", scheduleChan.getId())).forEach((Consumer<? super Document>) document -> {
                    Integer id = document.getInteger("_id");
                    ScheduleEntry se = Main.getEntryManager().getEntry(id);
                    if (se.getStart().isAfter(se.getEnd())) {
                        Main.getDBDriver().getEventCollection().updateOne(eq("_id", id), set("end", Date.from(se.getEnd().plusDays(1).toInstant())));
                    }
                    Main.getEntryManager().reloadEntry(id);
                });
                // disable auto-sync'ing timezone
                Main.getDBDriver().getScheduleCollection().updateOne(eq("_id", scheduleChan.getId()), set("timezone_sync", false));
                MessageUtilities.sendMsg(this.genMsgStr(cId, Mode.MISC, event.getJDA()), event.getChannel(), null);
                break;
            case "cl":
            case "clock":
                Main.getScheduleManager().setClockFormat(scheduleChan.getId(), args[index]);
                // reload the schedule display
                Main.getDBDriver().getEventCollection().find(eq("channelId", scheduleChan.getId())).forEach((Consumer<? super Document>) document -> Main.getEntryManager().reloadEntry((Integer) document.get("_id")));
                MessageUtilities.sendMsg(this.genMsgStr(cId, Mode.MISC, event.getJDA()), event.getChannel(), null);
                break;
            case "s":
            case "sync":
                Credential credential = GoogleAuth.getCredential(event.getAuthor().getId());
                if (credential == null)
                    break;
                Calendar service = GoogleAuth.getCalendarService(credential);
                if (Main.getCalendarConverter().checkValidAddress(args[index], service))
                    Main.getScheduleManager().setAddress(scheduleChan.getId(), args[index]);
                else
                    Main.getScheduleManager().setAddress(scheduleChan.getId(), "off");
                MessageUtilities.sendMsg(this.genMsgStr(cId, Mode.SYNC, event.getJDA()), event.getChannel(), null);
                break;
            case "t":
            case "time":
                ZonedDateTime syncTime = ZonedDateTime.of(LocalDate.now(), ParsingUtilities.parseTime(args[index]), Main.getScheduleManager().getTimeZone(cId));
                // don't allow times set in the past
                if (syncTime.isBefore(ZonedDateTime.now()))
                    syncTime.plusDays(1);
                Main.getScheduleManager().setSyncTime(cId, Date.from(syncTime.toInstant()));
                MessageUtilities.sendMsg(this.genMsgStr(cId, Mode.SYNC, event.getJDA()), event.getChannel(), null);
                break;
            case "r":
            case "remind":
            case "reminder":
            case "reminders":
                Set<Integer> list = this.reminderHelper(args, index, cId);
                // convert set to a list
                List<Integer> rem = new ArrayList<>(list);
                Main.getScheduleManager().setReminders(cId, rem);
                // for every entry on channel, update
                Main.getDBDriver().getEventCollection().find(eq("channelId", scheduleChan.getId())).forEach((Consumer<? super Document>) document -> {
                    ScheduleEntry se = new ScheduleEntry(document).reloadReminders(Main.getScheduleManager().getReminders(scheduleChan.getId()));
                    Main.getEntryManager().updateEntry(se, false);
                });
                MessageUtilities.sendMsg(this.genMsgStr(cId, Mode.REM, event.getJDA()), event.getChannel(), null);
                break;
            case "er":
            case "end-remind":
            case "end-reminder":
            case "end-reminders":
                Set<Integer> list2 = this.reminderHelper(args, index, cId);
                // convert set to a list
                List<Integer> rem2 = new ArrayList<>(list2);
                Main.getScheduleManager().setEndReminders(cId, rem2);
                // for every entry on channel, update
                Main.getDBDriver().getEventCollection().find(eq("channelId", scheduleChan.getId())).forEach((Consumer<? super Document>) document -> {
                    ScheduleEntry se = new ScheduleEntry(document).reloadEndReminders(Main.getScheduleManager().getEndReminders(scheduleChan.getId()));
                    Main.getEntryManager().updateEntry(se, false);
                });
                MessageUtilities.sendMsg(this.genMsgStr(cId, Mode.REM, event.getJDA()), event.getChannel(), null);
                break;
            case "rm":
            case "rem-msg":
            case "remind-msg":
            case "remind-message":
                String remindFormat;
                remindFormat = formatHelper(args[index]);
                Main.getScheduleManager().setReminderFormat(scheduleChan.getId(), remindFormat);
                MessageUtilities.sendMsg(this.genMsgStr(cId, Mode.REM, event.getJDA()), event.getChannel(), null);
                break;
            case "rc":
            case "rem-chan":
            case "remind-chan":
            case "remind-channel":
                String remindChanIdentifier;
                switch(args[index].toLowerCase()) {
                    case "reset":
                    case "default":
                    case "null":
                        remindChanIdentifier = null;
                        break;
                    default:
                        remindChanIdentifier = chanHelper(args[index], event);
                        break;
                }
                Main.getScheduleManager().setReminderChan(scheduleChan.getId(), remindChanIdentifier);
                MessageUtilities.sendMsg(this.genMsgStr(cId, Mode.REM, event.getJDA()), event.getChannel(), null);
                break;
            case "rsvp":
                boolean enabled = Main.getScheduleManager().isRSVPEnabled(cId);
                Map<String, String> options = Main.getScheduleManager().getRSVPOptions(cId);
                Boolean new_enabled = null;
                switch(args[index++].toLowerCase()) {
                    case "add":
                    case "a":
                        String emoji = args[index + 1].trim();
                        if (!EmojiManager.isEmoji(emoji)) {
                            emoji = emoji.replaceAll("[^\\d]", "");
                        }
                        options.put(emoji, args[index].trim());
                        Main.getScheduleManager().setRSVPOptions(cId, options);
                        break;
                    case "remove":
                    case "r":
                        if (options.containsKey(args[index])) {
                            options.remove(args[index]);
                        } else if (options.containsValue(args[index])) {
                            options.values().remove(args[index]);
                        }
                        Main.getScheduleManager().setRSVPOptions(cId, options);
                        break;
                    case "on":
                    case "true":
                        new_enabled = true;
                        break;
                    case "off":
                    case "false":
                        new_enabled = false;
                        break;
                }
                String clearEmoji = Main.getScheduleManager().getRSVPClear(cId);
                // if add or remove option was used, clear the reactions and re-add the new reactions
                if (new_enabled == null) {
                    // for each entry on the schedule
                    Main.getDBDriver().getEventCollection().find(eq("channelId", scheduleChan.getId())).forEach((Consumer<? super Document>) document -> {
                        event.getGuild().getTextChannelById(document.getString("channelId")).getMessageById(document.getString("messageId")).complete().clearReactions().queue((message) -> {
                            Map<String, String> map = Main.getScheduleManager().getRSVPOptions(document.getString("channelId"));
                            event.getGuild().getTextChannelById(document.getString("channelId")).getMessageById(document.getString("messageId")).queue(msg -> EntryManager.addRSVPReactions(map, clearEmoji, msg));
                        });
                        Main.getEntryManager().reloadEntry(document.getInteger("_id"));
                    });
                } else // otherwise, if the rsvp setting was changes
                if (enabled != new_enabled) {
                    // set schedule settings
                    Main.getScheduleManager().setRSVPEnable(cId, new_enabled);
                    if (new_enabled) {
                        // for each entry on the schedule
                        Main.getDBDriver().getEventCollection().find(eq("channelId", scheduleChan.getId())).forEach((Consumer<? super Document>) document -> {
                            Map<String, String> map = Main.getScheduleManager().getRSVPOptions(document.getString("channelId"));
                            event.getGuild().getTextChannelById(document.getString("channelId")).getMessageById(document.getString("messageId")).queue(msg -> EntryManager.addRSVPReactions(map, clearEmoji, msg));
                            Main.getEntryManager().reloadEntry(document.getInteger("_id"));
                        });
                    } else {
                        // for each entry on the schedule
                        Main.getDBDriver().getEventCollection().find(eq("channelId", scheduleChan.getId())).forEach((Consumer<? super Document>) document -> {
                            event.getGuild().getTextChannelById(document.getString("channelId")).getMessageById(document.getString("messageId")).complete().clearReactions().queue();
                            Main.getEntryManager().reloadEntry(document.getInteger("_id"));
                        });
                    }
                }
                MessageUtilities.sendMsg(this.genMsgStr(cId, Mode.RSVP, event.getJDA()), event.getChannel(), null);
                break;
            case "c":
            case "clear":
                String emoji = args[index].trim();
                if (emoji.equalsIgnoreCase("off")) {
                    emoji = "";
                } else if (!EmojiManager.isEmoji(emoji)) {
                    emoji = emoji.replaceAll("[^\\d]", "");
                }
                Main.getScheduleManager().setRSVPClear(cId, emoji);
                String finalEmoji = emoji;
                Map<String, String> rsvpOptions = Main.getScheduleManager().getRSVPOptions(cId);
                Main.getEntryManager().getEntriesFromChannel(cId).forEach(se -> {
                    Message message = se.getMessageObject();
                    message.clearReactions().queue(ignored -> EntryManager.addRSVPReactions(rsvpOptions, finalEmoji, message));
                });
                MessageUtilities.sendMsg(this.genMsgStr(cId, Mode.RSVP, event.getJDA()), event.getChannel(), null);
                break;
            case "co":
            case "confirm":
            case "confirmation":
            case "confirmations":
                boolean confirmation = true;
                switch(args[index].toLowerCase()) {
                    case "no":
                    case "false":
                    case "off":
                        confirmation = false;
                        break;
                }
                Main.getScheduleManager().setRSVPConfirmations(cId, confirmation);
                MessageUtilities.sendMsg(this.genMsgStr(cId, Mode.RSVP, event.getJDA()), event.getChannel(), null);
                break;
            case "ex":
            case "exclude":
            case "exclusivity":
                boolean exclusive = true;
                switch(args[index].toLowerCase()) {
                    case "no":
                    case "off":
                    case "false":
                        exclusive = false;
                        break;
                }
                Main.getScheduleManager().setRSVPExclusivity(cId, exclusive);
                MessageUtilities.sendMsg(this.genMsgStr(cId, Mode.RSVP, event.getJDA()), event.getChannel(), null);
                break;
            case "log":
            case "logging":
                String loggingChannel = null;
                switch(args[index].toLowerCase()) {
                    case "no":
                    case "off":
                    case "false":
                        break;
                    default:
                        loggingChannel = args[index].replaceAll("[^\\d]", "");
                        break;
                }
                Main.getScheduleManager().setRSVPLoggingChannel(cId, loggingChannel);
                MessageUtilities.sendMsg(this.genMsgStr(cId, Mode.RSVP, event.getJDA()), event.getChannel(), null);
                break;
            case "st":
            case "style":
                String style = args[index].toLowerCase();
                if (style.equals("full"))
                    Main.getScheduleManager().setStyle(cId, style);
                else if (style.equals("narrow"))
                    Main.getScheduleManager().setStyle(cId, style);
                // for each entry on the schedule
                Main.getDBDriver().getEventCollection().find(eq("channelId", scheduleChan.getId())).forEach((Consumer<? super Document>) document -> Main.getEntryManager().reloadEntry(document.getInteger("_id")));
                MessageUtilities.sendMsg(this.genMsgStr(cId, Mode.MISC, event.getJDA()), event.getChannel(), null);
                break;
            case "l":
            case "len":
            case "length":
                Main.getScheduleManager().setSyncLength(cId, Integer.parseInt(args[index]));
                MessageUtilities.sendMsg(this.genMsgStr(cId, Mode.SYNC, event.getJDA()), event.getChannel(), null);
                break;
            case "so":
            case "sort":
                int sortType;
                switch(args[index]) {
                    case "on":
                    case "asc":
                    case "ascending":
                        sortType = 1;
                        break;
                    case "desc":
                    case "descending":
                        sortType = 2;
                        break;
                    default:
                        sortType = 0;
                        break;
                }
                Main.getScheduleManager().setAutoSort(cId, sortType);
                MessageUtilities.sendMsg(this.genMsgStr(cId, Mode.MISC, event.getJDA()), event.getChannel(), null);
                // now sort the schedule
                if (sortType == 1)
                    Main.getScheduleManager().sortSchedule(cId, false);
                if (sortType == 2)
                    Main.getScheduleManager().sortSchedule(cId, true);
                break;
        }
    } else // print out all settings
    {
        MessageUtilities.sendMsg(this.genMsgStr(cId, Mode.FULL, event.getJDA()), event.getChannel(), null);
    }
}
Also used : Document(org.bson.Document) Command(ws.nmathe.saber.commands.Command) java.util(java.util) CommandInfo(ws.nmathe.saber.commands.CommandInfo) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) Updates.set(com.mongodb.client.model.Updates.set) ScheduleEntry(ws.nmathe.saber.core.schedule.ScheduleEntry) GoogleAuth(ws.nmathe.saber.core.google.GoogleAuth) Consumer(java.util.function.Consumer) EmojiManager(com.vdurmont.emoji.EmojiManager) java.time(java.time) ChronoUnit(java.time.temporal.ChronoUnit) MessageReceivedEvent(net.dv8tion.jda.core.events.message.MessageReceivedEvent) EntryManager(ws.nmathe.saber.core.schedule.EntryManager) MessageUtilities(ws.nmathe.saber.utils.MessageUtilities) JDA(net.dv8tion.jda.core.JDA) Filters.eq(com.mongodb.client.model.Filters.eq) Credential(com.google.api.client.auth.oauth2.Credential) Calendar(com.google.api.services.calendar.Calendar) Main(ws.nmathe.saber.Main) VerifyUtilities(ws.nmathe.saber.utils.VerifyUtilities) ParsingUtilities(ws.nmathe.saber.utils.ParsingUtilities) Credential(com.google.api.client.auth.oauth2.Credential) Calendar(com.google.api.services.calendar.Calendar) Document(org.bson.Document) ScheduleEntry(ws.nmathe.saber.core.schedule.ScheduleEntry) Consumer(java.util.function.Consumer)

Example 14 with ScheduleEntry

use of ws.nmathe.saber.core.schedule.ScheduleEntry in project Saber-Bot by notem.

the class EditCommand method action.

@Override
public void action(String head, String[] args, MessageReceivedEvent event) {
    int index = 0;
    Integer entryId = ParsingUtilities.encodeIDToInt(args[index]);
    ScheduleEntry se = Main.getEntryManager().getEntry(entryId);
    Message msg = se.getMessageObject();
    if (msg == null)
        return;
    // otherwise skip this and print out the event configuration
    if (args.length > 1) {
        // 1
        index++;
        while (index < args.length) {
            ZoneId zone = Main.getScheduleManager().getTimeZone(se.getChannelId());
            ArrayList<String> comments;
            switch(args[index++].toLowerCase()) {
                case "c":
                case "comment":
                case "comments":
                    comments = se.getComments();
                    switch(args[index++]) {
                        case "a":
                        case "add":
                            comments.add(args[index]);
                            se.setComments(comments);
                            index++;
                            break;
                        case "r":
                        case "remove":
                            if (VerifyUtilities.verifyInteger(args[index])) {
                                comments.remove(Integer.parseInt(args[index]) - 1);
                            } else {
                                comments.remove(args[index]);
                            }
                            se.setComments(comments);
                            index++;
                            break;
                        case "s":
                        case "swap":
                            String a = comments.get(Integer.parseInt(args[index]) - 1);
                            String b = comments.get(Integer.parseInt(args[index + 1]) - 1);
                            comments.set(Integer.parseInt(args[index]) - 1, b);
                            comments.set(Integer.parseInt(args[index + 1]) - 1, a);
                            se.setComments(comments);
                            index += 2;
                            break;
                    }
                    break;
                case "s":
                case "starts":
                case "start":
                    // create new datetime and update the schedule entry object
                    ZonedDateTime newStart = ZonedDateTime.of(se.getStart().toLocalDate(), ParsingUtilities.parseTime(args[index]), se.getStart().getZone());
                    se.setStart(newStart);
                    // do some final processing on start/end times
                    if (ZonedDateTime.now().isAfter(se.getStart())) {
                        // add a day if the time has already passed
                        se.setStart(se.getStart().plusDays(1));
                    }
                    if (se.getStart().isAfter(se.getEnd())) {
                        // add a day to end if end is after start
                        se.setEnd(se.getEnd().plusDays(1));
                        // reload end reminders
                        se.reloadEndReminders(Main.getScheduleManager().getEndReminders(se.getChannelId()));
                    }
                    // reload start reminders
                    se.reloadReminders(Main.getScheduleManager().getReminders(se.getChannelId())).regenerateAnnouncementOverrides();
                    index++;
                    break;
                case "e":
                case "ends":
                case "end":
                    // if off, use start
                    if (args[index].equalsIgnoreCase("off")) {
                        se.setEnd(se.getStart());
                    } else {
                        // otherwise parse the input for a time
                        se.setEnd(ZonedDateTime.of(se.getEnd().toLocalDate(), ParsingUtilities.parseTime(args[index]), se.getEnd().getZone()));
                    }
                    // add a day if the time has already passed
                    if (ZonedDateTime.now().isAfter(se.getEnd()))
                        se.setEnd(se.getEnd().plusDays(1));
                    // add a day to end if end is after start
                    if (se.getStart().isAfter(se.getEnd()))
                        se.setEnd(se.getEnd().plusDays(1));
                    // reload end reminders
                    se.reloadEndReminders(Main.getScheduleManager().getEndReminders(se.getChannelId())).regenerateAnnouncementOverrides();
                    index++;
                    break;
                case "t":
                case "title":
                    se.setTitle(args[index]);
                    index++;
                    break;
                case "d":
                case "date":
                    ZonedDateTime date = ParsingUtilities.parseDate(args[index].toLowerCase(), zone);
                    se.setStart(se.getStart().withMonth(date.getMonthValue()).withDayOfMonth(date.getDayOfMonth()).withYear(date.getYear()));
                    se.setEnd(se.getEnd().withMonth(date.getMonthValue()).withDayOfMonth(date.getDayOfMonth()).withYear(date.getYear()));
                    se.reloadReminders(Main.getScheduleManager().getReminders(se.getChannelId())).reloadEndReminders(Main.getScheduleManager().getEndReminders(se.getChannelId())).regenerateAnnouncementOverrides();
                    index++;
                    break;
                case "sd":
                case "start date":
                case "start-date":
                    ZonedDateTime sdate = ParsingUtilities.parseDate(args[index].toLowerCase(), zone);
                    se.setStart(se.getStart().withMonth(sdate.getMonthValue()).withDayOfMonth(sdate.getDayOfMonth()).withYear(sdate.getYear()));
                    if (se.getEnd().isBefore(se.getStart())) {
                        se.setEnd(se.getStart());
                        se.reloadEndReminders(Main.getScheduleManager().getEndReminders(se.getChannelId()));
                    }
                    se.reloadReminders(Main.getScheduleManager().getReminders(se.getChannelId())).regenerateAnnouncementOverrides();
                    index++;
                    break;
                case "ed":
                case "end date":
                case "end-date":
                    ZonedDateTime edate = ParsingUtilities.parseDate(args[index].toLowerCase(), zone);
                    se.setEnd(se.getEnd().withMonth(edate.getMonthValue()).withDayOfMonth(edate.getDayOfMonth()).withYear(edate.getYear()));
                    if (se.getEnd().isBefore(se.getStart())) {
                        se.setStart(se.getEnd());
                        se.reloadReminders(Main.getScheduleManager().getReminders(se.getChannelId()));
                    }
                    se.reloadEndReminders(Main.getScheduleManager().getEndReminders(se.getChannelId())).regenerateAnnouncementOverrides();
                    index++;
                    break;
                case "r":
                case "repeats":
                case "repeat":
                    se.setRepeat(EventRecurrence.parseRepeat(args[index].toLowerCase()));
                    index++;
                    break;
                case "i":
                case "interval":
                    se.setRepeat(EventRecurrence.parseInterval(args[index]));
                    index++;
                    break;
                case "u":
                case "url":
                    se.setTitleUrl(ParsingUtilities.parseUrl(args[index]));
                    index++;
                    break;
                case "im":
                case "image":
                    se.setImageUrl(ParsingUtilities.parseUrl(args[index]));
                    index++;
                    break;
                case "th":
                case "thumbnail":
                    se.setThumbnailUrl(ParsingUtilities.parseUrl(args[index]));
                    index++;
                    break;
                case "ex":
                case "expire":
                    se.setExpire(ParsingUtilities.parseNullableDate(args[index], zone));
                    index++;
                    break;
                case "deadline":
                case "dl":
                    se.setRsvpDeadline(ParsingUtilities.parseNullableDate(args[index], zone));
                    index++;
                    break;
                case "count":
                case "co":
                    Integer c = null;
                    if (!args[index].equalsIgnoreCase("off"))
                        c = Integer.parseInt(args[index]);
                    se.setCount(c);
                    // set the original start to the current start
                    se.setOriginalStart(se.getStart());
                    index++;
                    break;
                case "qs":
                case "quiet-start":
                    se.setQuietStart(!se.isQuietStart());
                    break;
                case "qe":
                case "quiet-end":
                    se.setQuietEnd(!se.isQuietEnd());
                    break;
                case "qr":
                case "quiet-remind":
                    se.setQuietRemind(!se.isQuietRemind());
                    break;
                case "qa":
                case "quiet-all":
                    if (se.isQuietRemind() && se.isQuietEnd() && se.isQuietStart()) {
                        se.setQuietRemind(false).setQuietEnd(false).setQuietStart(false);
                    } else {
                        se.setQuietRemind(true).setQuietEnd(true).setQuietStart(true);
                    }
                    break;
                case "limit":
                case "l":
                    Integer lim = null;
                    if (!args[index + 1].equalsIgnoreCase("off")) {
                        lim = Integer.parseInt(args[index + 1]);
                    }
                    se.setRsvpLimit(args[index], lim);
                    index += 2;
                    break;
                case "lo":
                case "location":
                    if (args[index].equalsIgnoreCase("off"))
                        se.setLocation(null);
                    else
                        se.setLocation(args[index]);
                    index++;
                    break;
                case "an":
                case "announce":
                case "announcement":
                case "announcements":
                    switch(args[index++].toLowerCase()) {
                        case "a":
                        case "add":
                            String target = args[index].replaceAll("[^\\d]", "");
                            String time = args[index + 1];
                            String message = args[index + 2];
                            se.addAnnouncementOverride(target, time, message);
                            index += 3;
                            break;
                        case "r":
                        case "remove":
                            Integer id = Integer.parseInt(args[index].replaceAll("[^\\d]", "")) - 1;
                            se.removeAnnouncementOverride(id);
                            index++;
                            break;
                    }
                    break;
                case "a":
                case "add":
                    switch(args[index++].toLowerCase()) {
                        case "a":
                        case "an":
                        case "announce":
                        case "announcement":
                        case "announcements":
                            String target = args[index].replaceAll("[^\\d]", "");
                            String time = args[index + 1];
                            String message = args[index + 2];
                            se.addAnnouncementOverride(target, time, message);
                            index += 3;
                            break;
                        case "c":
                        case "comment":
                        case "comments":
                            comments = se.getComments();
                            comments.add(args[index]);
                            se.setComments(comments);
                            index++;
                            break;
                    }
                    break;
                case "re":
                case "remove":
                    switch(args[index++].toLowerCase()) {
                        case "a":
                        case "an":
                        case "announce":
                        case "announcement":
                        case "announcements":
                            Integer id = Integer.parseInt(args[index].replaceAll("[^\\d]", "")) - 1;
                            se.removeAnnouncementOverride(id);
                            index++;
                            break;
                        case "c":
                        case "comment":
                        case "comments":
                            comments = se.getComments();
                            if (VerifyUtilities.verifyInteger(args[index])) {
                                comments.remove(Integer.parseInt(args[index]) - 1);
                            } else {
                                comments.remove(args[index]);
                            }
                            se.setComments(comments);
                            index++;
                            break;
                    }
                    break;
            }
        }
        Main.getEntryManager().updateEntry(se, true);
    }
    // 
    // send the event summary to the command channel
    // 
    String body = "Updated event :id: **" + ParsingUtilities.intToEncodedID(se.getId()) + "** on <#" + se.getChannelId() + ">\n" + se.toString();
    MessageUtilities.sendMsg(body, event.getChannel(), null);
}
Also used : ScheduleEntry(ws.nmathe.saber.core.schedule.ScheduleEntry) Message(net.dv8tion.jda.core.entities.Message) ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime)

Example 15 with ScheduleEntry

use of ws.nmathe.saber.core.schedule.ScheduleEntry in project Saber-Bot by notem.

the class DeleteCommand method verify.

@Override
public String verify(String prefix, String[] args, MessageReceivedEvent event) {
    String head = prefix + this.name();
    if (args.length > 1) {
        return "Too many arguments! Use ``" + head + " <ID|channel|'all'>``";
    }
    if (args.length == 0) {
        return "Not enough arguments! Use ``" + head + " <ID|channel|'all'>``";
    }
    // pass if "all"
    if (args[0].toLowerCase().equals("all")) {
        return "";
    }
    // checks to verify arg is hex and entry exists
    if (VerifyUtilities.verifyEntryID(args[0])) {
        Integer entryId = ParsingUtilities.encodeIDToInt(args[0]);
        ScheduleEntry entry = Main.getEntryManager().getEntryFromGuild(entryId, event.getGuild().getId());
        if (entry == null) {
            return "The requested entry does not exist!";
        }
        return "";
    } else // arg should be a schedule id
    {
        if (!Main.getScheduleManager().isASchedule(args[0].replaceAll("[^\\d]", ""))) {
            return "Argument ``" + args[0] + "`` is not a schedule channel or an event id!";
        }
        return "";
    }
}
Also used : ScheduleEntry(ws.nmathe.saber.core.schedule.ScheduleEntry)

Aggregations

ScheduleEntry (ws.nmathe.saber.core.schedule.ScheduleEntry)21 JDA (net.dv8tion.jda.core.JDA)6 Main (ws.nmathe.saber.Main)6 ZonedDateTime (java.time.ZonedDateTime)5 java.util (java.util)5 Message (net.dv8tion.jda.core.entities.Message)5 ZoneId (java.time.ZoneId)4 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4 Permission (net.dv8tion.jda.core.Permission)4 net.dv8tion.jda.core.entities (net.dv8tion.jda.core.entities)4 StringUtils (org.apache.commons.lang3.StringUtils)4 DateTimeFormatter (java.time.format.DateTimeFormatter)3 ChronoUnit (java.time.temporal.ChronoUnit)3 Consumer (java.util.function.Consumer)3 Collectors (java.util.stream.Collectors)3 MessageReceivedEvent (net.dv8tion.jda.core.events.message.MessageReceivedEvent)3 Document (org.bson.Document)3 MessageUtilities (ws.nmathe.saber.utils.MessageUtilities)3 ParsingUtilities (ws.nmathe.saber.utils.ParsingUtilities)3