public void AddRaid(ulong guildId, ulong channelId, ulong messageId, RaidInfoDto raidInfoDto) { var raidChannels = raidGuilds.GuildRaids.GetOrAdd(guildId, _ => new RaidChannelMapping()); var raidMessages = raidChannels.RaidChannels.GetOrAdd(channelId, _ => new RaidMessageMapping()); raidMessages.RaidMessages[messageId] = raidInfoDto; }
public async Task RaidCreate( [Summary("Název bosse.")] string bossName, [Summary("Místo.")] string location, [Summary("Čas (" + TimeService.TimeFormat + ").")] DateTime time) { time = timeService.EnsureUtc(time); if (time < DateTime.UtcNow) { await ReplyAsync($"Vážně chceš vytvořit raid v minulosti?"); return; } if (!timeService.IsToday(time)) { await ReplyAsync($"Raid není dnes."); return; } var raidChannelBinding = raidChannelService.TryGetRaidChannelBinding(Context.Guild.Id, Context.Channel.Id); var raidInfo = new RaidInfoDto(RaidType.Normal) { BossName = bossName, Location = location, DateTime = time, }; var roles = teamService.GuildTeamRoles[Context.Guild.Id].TeamRoles.Values; bool shouldMention = !(configuration.GetGuildOptions(Context.Guild.Id)?.IgnoreMention ?? false); string mention = string.Empty; if (shouldMention) { mention = raidChannelBinding.Mention == null?string.Join(' ', roles.Select(t => t.Mention)) : raidChannelBinding.Mention.Mention; } var message = await raidChannelBinding.Channel.SendMessageAsync($"{raidService.ToSimpleString(raidInfo)} {mention}", embed : raidService.ToEmbed(raidInfo)); logger.LogInformation($"New raid has been created '{raidService.ToSimpleString(raidInfo)}'"); raidInfo.Message = message; await Context.Message.AddReactionAsync(Emojis.Check); await raidService.SetDefaultReactions(message); raidStorageService.AddRaid(Context.Guild.Id, raidChannelBinding.Channel.Id, message.Id, raidInfo); await message.ModifyAsync(t => { t.Content = string.Empty; t.Embed = raidService.ToEmbed(raidInfo); }, retryOptions); }
RaidInfoDto ParseRaidInfo(IUserMessage message) { var embed = message.Embeds.FirstOrDefault(); if (embed == null || embed.Fields.Length < 3) { return(null); } RaidInfoDto result = null; if (embed.Fields[2].Name == "Čas") { var time = timeService.ParseTime(embed.Fields[2].Value, message.CreatedAt.Date); if (!time.HasValue) { return(null); } result = new RaidInfoDto(RaidType.Normal) { Message = message, CreatedAt = message.CreatedAt.UtcDateTime, BossName = embed.Fields[0].Value, Location = embed.Fields[1].Value, DateTime = time.Value, }; } else if (embed.Fields[2].Name == "Datum") { var dateTime = timeService.ParseDateTime(embed.Fields[2].Value); if (!dateTime.HasValue) { return(null); } result = new RaidInfoDto(RaidType.Scheduled) { Message = message, CreatedAt = message.CreatedAt.UtcDateTime, BossName = embed.Fields[0].Value, Location = embed.Fields[1].Value, DateTime = dateTime.Value, }; } return(result); }
public async Task StartScheduledRaid( [Summary("Název bosse.")] string bossName, [Summary("Místo.")] string location, [Remainder][Summary("Datum (" + TimeService.DateTimeFormat + ").")] string dateTime) { var raidChannelBinding = raidChannelService.TryGetRaidChannelBinding(Context.Guild.Id, Context.Channel.Id); if (raidChannelBinding == null || !raidChannelBinding.AllowScheduledRaids) { await ReplyAsync($"Z tohoto kanálu není možné vytvořit plánovanou raid anketu."); return; } var parsedDateTime = timeService.ParseDateTime(dateTime); if (!parsedDateTime.HasValue) { await ReplyAsync($"Datum není ve validním formátu ({TimeService.DateTimeFormat} 24H)."); return; } if (parsedDateTime < DateTime.UtcNow) { await ReplyAsync($"Vážně chceš vytvořit plánovaný raid v minulosti?"); return; } var raidInfo = new RaidInfoDto(RaidType.Scheduled) { BossName = bossName, Location = location, DateTime = parsedDateTime.Value, }; var message = await raidChannelBinding.Channel.SendMessageAsync(string.Empty, embed : raidService.ToEmbed(raidInfo)); logger.LogInformation($"New scheduled raid has been created '{raidService.ToSimpleString(raidInfo)}'"); raidInfo.Message = message; await Context.Message.AddReactionAsync(Emojis.Check); await raidService.SetDefaultReactions(message); raidStorageService.AddRaid(Context.Guild.Id, raidChannelBinding.Channel.Id, message.Id, raidInfo); }
public string ToSimpleString(RaidInfoDto raidInfo) => $"{raidInfo.BossName} {raidInfo.Location} {RaidDateTimeToString(raidInfo.DateTime, raidInfo.RaidType)}";
public Embed ToEmbed(RaidInfoDto raidInfo) { EmbedBuilder embedBuilder = new EmbedBuilder(); embedBuilder .WithColor(GetColor()) .AddField("Boss", raidInfo.BossName, true) .AddField("Místo", raidInfo.Location, true) .AddField(raidInfo.RaidType == RaidType.Normal ? "Čas" : "Datum", RaidDateTimeToString(raidInfo.DateTime, raidInfo.RaidType), true) ; if (raidInfo.Players.Count > 0) { string playerFieldValue = raidInfo.Players.Count >= 10 ? PlayersToGroupString(raidInfo.Players.Values) : PlayersToString(raidInfo.Players.Values); embedBuilder.AddField($"Hráči ({raidInfo.Players.Count})", playerFieldValue); } if (raidInfo.ExtraPlayers.Count > 0) { string extraPlayersFieldValue = string.Join(" + ", raidInfo.ExtraPlayers.Select(t => t.Count)); embedBuilder.AddField($"Další hráči (bez Discordu, 2. mobil atd.) ({raidInfo.ExtraPlayers.Sum(t => t.Count)})", extraPlayersFieldValue); } return(embedBuilder.Build()); Color GetColor() { if (raidInfo.RaidType == RaidType.Scheduled) { return(!raidInfo.IsExpired ? new Color(191, 155, 48) : Color.Red); } var remainingTime = raidInfo.DateTime - DateTime.UtcNow; if (remainingTime.TotalMinutes <= 0) { return(Color.Red); } if (remainingTime.TotalMinutes <= 15) { return(Color.Orange); } return(Color.Green); } string PlayersToString(IEnumerable <PlayerDto> players) => string.Join(", ", players); string PlayersToGroupString(IEnumerable <PlayerDto> allPlayers) { string TeamToString(PokemonTeam?team) => team != null?team.ToString() : "Bez teamu"; List <string> formatterGroupedPlayers = new List <string>(); var teams = new PokemonTeam?[] { PokemonTeam.Mystic, PokemonTeam.Instinct, PokemonTeam.Valor, null }; foreach (PokemonTeam?team in teams) { var players = allPlayers.Where(t => t.Team == team).ToList(); if (players.Any()) { formatterGroupedPlayers.Add($"{TeamToString(team)} ({players.Count}) - {PlayersToString(players)}"); } } return(string.Join(Environment.NewLine, formatterGroupedPlayers)); } }