示例#1
0
        public async Task AdjustRaidTime(
            [Summary("Nový čas raidu (" + TimeService.TimeFormat + ").")] string time,
            [Summary("Počet anket odspodu.")] int skip = 0)
        {
            // TODO scheduled raid
            var raid = GetRaid(skip);

            if (raid == null)
            {
                await ReplyAsync("Raid nenalezen.");

                return;
            }

            var parsedTime = timeService.ParseTime(time);

            if (!parsedTime.HasValue)
            {
                await ReplyAsync($"Čas není ve validním formátu ({TimeService.TimeFormat} 24H).");

                return;
            }

            if (parsedTime < DateTime.UtcNow)
            {
                await ReplyAsync($"Vážně změnit čas do minulosti?");

                return;
            }

            var currentUser = Context.User as SocketGuildUser;

            logger.LogInformation($"User '{currentUser.Nickname ?? Context.User.Username}' with id '{Context.User.Id}'" +
                                  $" changed raid with id '{raid.Message.Id}'" +
                                  $" time changed from {timeService.ConvertToLocalString(raid.DateTime, TimeService.TimeFormat)} to {timeService.ConvertToLocalString(parsedTime.Value, TimeService.TimeFormat)}");

            foreach (var player in raid.Players.Values)
            {
                var user = player.User;
                await user.SendMessageAsync(
                    $"Změna raid času z {timeService.ConvertToLocalString(raid.DateTime, TimeService.TimeFormat)} na {timeService.ConvertToLocalString(parsedTime.Value, TimeService.TimeFormat)}!" +
                    $" Jestli ti změna nevyhovuje, tak se odhlaš z raidu nebo se domluv s ostatními na jiném čase.");
            }

            raid.DateTime = parsedTime.Value;
            await raid.Message.ModifyAsync(t => t.Embed = raidService.ToEmbed(raid));
        }