예제 #1
0
        public async Task RemindMe(
            [Summary("The reminder query"), Remainder]
            string remind)
        {
            var dueDate = ParseTime(remind);

            if (!dueDate.HasValue)
            {
                await ReplyFailureEmbedExtended(
                    "Reminder was not correctly formatted!",
                    "Make sure the reminder is of the format: `<what to remind you> in <when>`\n" +
                    "Where in the first space you just add the text that Sora should remind you of and then the **in** is very important. " +
                    "After it you should add when he should remind you.\n" +
                    "For example: `3 hours` or `10 hours and 5 minutes.`");

                return;
            }

            // Check that there's actually a message and not just timer
            string msg = remind
                         .Substring(0, remind.LastIndexOf(" in ", StringComparison.InvariantCultureIgnoreCase))
                         .Trim();

            if (string.IsNullOrWhiteSpace(msg))
            {
                await ReplyFailureEmbedExtended(
                    "Reminder was not correctly formatted!",
                    "Make sure the reminder is of the format: `<what to remind you> in <when>`\n" +
                    "Where in the first space you just add the text that Sora should remind you of and then the **in** is very important. " +
                    "After it you should add when he should remind you.\n" +
                    "For example: `3 hours` or `10 hours and 5 minutes.`");

                return;
            }

            // Otherwise see how many reminders we already have. We don't want to allow users to spam with reminders!
            var userRemCount = await _remindRepo.GetUserReminderCount(Context.User.Id).ConfigureAwait(false);

            if (userRemCount >= _MAX_USER_REMINDERS)
            {
                await ReplyFailureEmbed(
                    $"You already have the maximum amount of {_MAX_USER_REMINDERS.ToString()} reminders!");

                return;
            }

            // Just add the reminder to the user :D
            await _remindRepo.AddReminderToUser(Context.User.Id, msg, ~dueDate).ConfigureAwait(false);

            var remindIn = dueDate.Some().Subtract(DateTime.UtcNow);

            await ReplySuccessEmbedExtended(
                "Successfully set reminder",
                $"I will remind you to `{msg}` in {remindIn.Humanize(minUnit: TimeUnit.Second, maxUnit: TimeUnit.Year, precision: 10)}");
        }