public async Task SetReminder(CommandContext context, string day, DateTime time, [RemainingText] string message = "")
        {
            ZonedDateTime zonedDateTime;
            var           timezone = this._repository.GetUserTimezone(context.User.Id);
            var           today    = Instant.FromDateTimeUtc(DateTime.UtcNow).InZone(timezone);

            zonedDateTime = (today.Date.ToDateTimeUnspecified() + time.TimeOfDay).InTimeZone(timezone);
            switch (day)
            {
            case "today": {
                break;
            }

            case "tomorrow": {
                zonedDateTime = zonedDateTime.PlusHours(24);
                break;
            }

            default: {
                await context.RespondAsync($"'{day}' not supported. Only 'today' or 'tomorrow'");

                return;
            }
            }
            Reminder reminder = new Reminder(zonedDateTime, message, context.User.Id);

            this._repository.AddReminder(reminder);
            await context.RespondAsync(embed : reminder.CreateEmbed());

            return;
        }
Ejemplo n.º 2
0
        private async Task SendReminderAsync(Reminder reminder)
        {
            var channel = Bot.GetChannel(reminder.GuildId, reminder.ChannelId);

            var localMessage = new LocalMessage()
                               .WithContent(Mention.User(reminder.UserId))
                               .AddEmbed(reminder.CreateEmbed());

            // Channel where reminder was created no longer exists and hence the reminder no longer exists
            if (channel is not null)
            {
                await Bot.SendMessageAsync(reminder.ChannelId, localMessage);
            }
            else
            {
                try
                {
                    localMessage.Embeds.First().WithFooter("Your are receiving a DM because the channel this reminder was scheduled in no longer exists");
                    var dmChannel = await Bot.CreateDirectChannelAsync(reminder.UserId);

                    await dmChannel.SendMessageAsync(localMessage);
                }
                catch (RestApiException e) when(e.ErrorModel.Code.GetValueOrDefault() == RestApiErrorCode.CannotSendMessagesToThisUser)
                {
                    Logger.LogInformation("Could not notify user {0} about a reminder.  Deleting reminder without notifying user.", reminder.UserId);
                }
            }

            await RemoveReminderAsync(reminder);
        }