public async Task AddReminder([Name("Time"), NotExpiredPrecondition] DateTime reminderTime, [Name("Reminder"), Remainder()] string ReminderText)
        {
            var added = _reminderService.AddReminder(Context.Guild.Id, Context.Channel.Id, Context.User.Id,
                                                     ReminderText, reminderTime);

            // just reply back with the reminder that was created
            await GetReminderById(added.ID);
        }
Beispiel #2
0
        public async Task RemindMe(
            [Summary("The time until I should remind you, format: 0d:0h:0m:0s")]
            Timediff time,
            [Summary("The text you want to get reminded of")][Remainder]
            string text)
        {
            try
            {
                var user = Context.User as IGuildUser;
                if (user == null)
                {
                    await ReplyAsync("You can't set reminders in DM!");

                    return;
                }

                int maxDays = Information.MaximumRemindDays;
                if (time.Days > maxDays)
                {
                    await ReplyAsync(
                        $"Sorry I'm not allowing you to set a reminder for anything longer than {maxDays} days..");

                    return;
                }

                await ReminderService.AddReminder(Context.User, text, DateTime.Now + time.Span, Context.Guild);

                ConsoleHelper.Log(
                    $"{Helper.GetName(Context.User)} set a reminder for {DateTime.Now + time.Span:dd.MM.yyyy HH:mm}!",
                    LogSeverity.Info);

                //Don't say Day when it's the same day
                string when;
                if ((DateTime.Now + time.Span).DayOfYear == DateTime.Now.DayOfYear)
                {
                    when = (DateTime.Now + time.Span).ToString("HH:mm");
                }
                else
                {
                    when = (DateTime.Now + time.Span).ToString("dd.MM.yyyy HH:mm");
                }

                await ReplyAsync(
                    $"All set {Helper.GetName(Context.User)}, I'll remind you at **{when}**!");
            } catch (MaximumRemindersException)
            {
                await ReplyAsync($"You can't have more than {Information.MaximumReminders} reminders simultaneously!");
            } catch (Exception ex)
            {
                await ReplyAsync("Whoops, unfortunately I couldn't set that reminder.. :confused:");

                ConsoleHelper.Log($"Error setting reminder for {Helper.GetName(Context.User)} at " +
                                  $"{DateTime.Now + time.Span:yyyyMMddHHmm}! ({ex.Message})", LogSeverity.Error);
            }
        }
        public async Task AddReminderShouldReturnReminder()
        {
            Reminder reminder = new Reminder {
                NewsId = 102, Schedule = DateTime.Now.AddDays(1)
            };
            Reminder addedReminder = new Reminder {
                ReminderId = 2, NewsId = 102, Schedule = DateTime.Now.AddDays(1)
            };
            Reminder _reminder = null;
            var      mockRepo  = new Mock <IReminderRepository>();

            mockRepo.Setup(repo => repo.GetReminderByNewsId(reminder.NewsId)).Returns(Task.FromResult(_reminder));
            mockRepo.Setup(repo => repo.AddReminder(reminder)).Returns(Task.FromResult(addedReminder));
            var service = new ReminderService(mockRepo.Object);

            var actual = await service.AddReminder(reminder);

            Assert.NotNull(actual);
            Assert.IsAssignableFrom <Reminder>(actual);
            Assert.Equal(2, actual.ReminderId);
        }
Beispiel #4
0
        public async Task ReminderAsync(Team team)
        {
            var response = await reminderService.AddReminder(team);

            switch (response.Answer)
            {
            case ReminderAnswer.ReminderSet:
                response.Reminder.HalfTimeTrigger  += ReminderTrigger;
                response.Reminder.TenTimeTrigger   += ReminderTrigger;
                response.Reminder.OnTimeTrigger    += ReminderTrigger;
                response.Reminder.OtherTimeTrigger += ReminderTrigger;

                await ReplyAsync($"Lembrete definido para {response.Reminder.Team.Name}. Próximo jogo {response.Reminder.Game.ToString()} {response.Reminder.Game.MatchDate.ToString("dd/MM/yyyy HH:mm")}");

                await LoggindService.Log($"{Context.User.Username}#{Context.User.Discriminator} criou um novo lembrete para {response.Reminder.Team}", GetType(), Discord.LogSeverity.Info);

                break;

            case ReminderAnswer.ExistingReminder:
                await ReplyAsync($"Lembrete já definido para {response.Reminder.Team}. Próximo jogo {response.Reminder.Game.ToString()} {response.Reminder.Game.MatchDate.ToString("dd/MM/yyyy HH:mm")}");

                break;

            case ReminderAnswer.TeamNotFound:
                await ReplyAsync("team not found");

                break;

            case ReminderAnswer.NoUpcomingGames:
                await ReplyAsync($"Sem próximos jogos para {team}. Um lembrete será definido para quando houver um jogo.");

                break;

            default:
                break;
            }
        }
        public async Task AddReminderShouldThrowException()
        {
            int      newsId   = 101;
            Reminder reminder = new Reminder {
                NewsId = 101, Schedule = DateTime.Now.AddDays(2)
            };
            var mockRepo = new Mock <IReminderRepository>();

            mockRepo.Setup(repo => repo.GetReminderByNewsId(newsId)).Returns(Task.FromResult(reminder));
            var service = new ReminderService(mockRepo.Object);

            var actual = await Assert.ThrowsAsync <ReminderAlreadyExistsException>(() => service.AddReminder(reminder));

            Assert.Equal($"This news: {newsId} already have a reminder", actual.Message);
        }