Пример #1
0
        public async Task <RuntimeResult> RepeatEvent(string query, string date = "", string time = "")
        {
            try
            {
                DateTime?parsedDate;
                TimeSpan?parsedTime;
                ParseDateTime(date, time, out parsedDate, out parsedTime);
                if (!parsedDate.HasValue && !parsedTime.HasValue)
                {
                    throw new ArgumentException("Expecting at least new date or new time to repeat event");
                }

                ScheduledEvent se = _schedulingService.FindEventByIdOrText(Context.Guild.Id, query);

                DateTime targetDate = parsedDate.HasValue ? parsedDate.Value : se.TargetDate.Date;
                if (parsedTime.HasValue)
                {
                    targetDate += parsedTime.Value;
                }
                else
                {
                    targetDate += se.TargetDate.TimeOfDay;
                }

                int id = _schedulingService.ScheduleEvent(Context.Guild.Id, Context.User.Username, se.Message, targetDate);
                await ReplyAsync(string.Format("Copied event [{0}] as [{1}] at {2}", se.Id, id, targetDate.ToString("dd.MM.yyyy HH:mm")));

                return(CommandResult.FromSuccess());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.ToString());
                return(CommandResult.FromError(ex.Message));
            }
        }