예제 #1
0
        private async Task <DiscordMessage> GetPublicStatusMessage()
        {
            var pinnedMessages = await _publicStatusChannel.GetPinnedMessagesAsync();

            if (pinnedMessages.Count > 0)
            {
                return(pinnedMessages[0]);
            }

            var statusMessage = await _publicStatusChannel.SendMessageAsync("**Placeholder**");

            await statusMessage.PinAsync();

            return(statusMessage);
        }
예제 #2
0
파일: Meta.cs 프로젝트: eclipseanu/WamBot
        internal static async Task UpdatePinsAsync(DateTimeOffset lastPinTimestamp, DiscordChannel channel, GuildData d, DiscordClient client)
        {
            if (d.Webhook != null)
            {
                if (!WebhookClient.Webhooks.Any(w => w.Id == d.Webhook.Id))
                {
                    d.Webhook = await client.GetWebhookWithTokenAsync(d.Webhook.Id, d.Webhook.Token);

                    WebhookClient.AddWebhook(d.Webhook);
                }

                DiscordChannel pinsChannel = await client.GetChannelAsync(d.Webhook.ChannelId);

                if (lastPinTimestamp > d.LastPinTimestamp)
                {
                    List <DiscordMessage> pins          = new List <DiscordMessage>();
                    DiscordMember         currentMember = channel.Guild.CurrentMember;

                    if (!d.HasUpdatedPins)
                    {
                        var channels = channel.Guild.Channels.Where(c => c.Type == ChannelType.Text && !c.IsPrivate && c.PermissionsFor(currentMember).HasPermission(Permissions.AccessChannels));

                        if (!pinsChannel.IsNSFW)
                        {
                            channels = channels.Where(c => !c.IsNSFW);
                        }

                        foreach (DiscordChannel c in channels)
                        {
                            pins.AddRange(await c.GetPinnedMessagesAsync());
                            await Task.Delay(6000);
                        }
                        d.HasUpdatedPins = true;
                    }
                    else
                    {
                        pins.AddRange(await channel.GetPinnedMessagesAsync());
                    }

                    foreach (var pin in pins.OrderBy(p => p.CreationTimestamp).Where(p => p.Id > d.LastPinnedMessage))
                    {
                        try
                        {
                            var embeds = new List <DiscordEmbed>();

                            foreach (var attachment in pin.Attachments)
                            {
                                var builder = new DiscordEmbedBuilder()
                                              .WithAuthor(pin.Author?.Username ?? "Okay what the f**k?", null, pin.Author?.AvatarUrl)
                                              .WithTitle(attachment.FileName)
                                              .WithFooter($"In #{pin.Channel.Name}")
                                              .WithTimestamp(pin.CreationTimestamp);

                                if (attachment.Width != 0)
                                {
                                    builder = builder.WithImageUrl(attachment.Url);
                                }
                                else
                                {
                                    builder = builder.WithUrl(attachment.Url);
                                    builder.AddField("Attachment URL", attachment.Url);
                                }

                                embeds.Add(builder.Build());
                            }

                            string content = pin.Content
                                             .Replace("@everyone", "@ everyone")
                                             .Replace("@here", "@ here");

                            foreach (var user in pin.MentionedUsers)
                            {
                                content = content.Replace($"<@{user.Id}>", $"@{user.Username}")
                                          .Replace($"<@!{user.Id}>", $"@{user.Username}");
                            }

                            foreach (var role in pin.MentionedRoles)
                            {
                                content = content.Replace(role.Mention, $"@{role.Name}");
                            }

                            if (embeds.Any() || !string.IsNullOrWhiteSpace(content))
                            {
                                await d.Webhook.ExecuteAsync(content, $"{(pin.Author?.Username ?? "Okay what the f**k?")} - in #{pin.Channel.Name}", pin.Author?.AvatarUrl ?? currentMember.DefaultAvatarUrl, false, embeds);

                                await Task.Delay(1000);

                                d.LastPinnedMessage = pin.Id;
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex);
                        }
                    }
                }

                d.LastPinTimestamp = lastPinTimestamp;
            }
        }
예제 #3
0
        private async Task CreatePinnedLobbyMessage(Lobby lobby, DiscordChannel lobbyChannel, DiscordUser user, bool isOtw)
        {
            _logger.Trace($"RaidLobbyManager::CreatePinnedLobbyMessage [Lobby={lobby.ChannelName}, DiscordChannel={lobbyChannel.Name}, DiscordUser={user}, IsOtw={isOtw}]");

            var pkmnImage = lobby.Gym.IsEgg
                ? string.Format(Strings.EggImage, lobby.Gym.RaidLevel)
                : lobby.Gym.RaidPokemonId.GetPokemonImage(lobby.Gym.RaidPokemonForm.ToString());
            var eb = new DiscordEmbedBuilder
            {
                Title        = $"{lobby.City}: {lobby.Gym.Name}",
                Color        = lobby.Gym.RaidLevel.BuildRaidColor(),
                Url          = string.Format(Strings.GoogleMaps, lobby.Gym.Latitude, lobby.Gym.Longitude),
                ImageUrl     = string.Format(Strings.GoogleMapsStaticImage, lobby.Gym.Latitude, lobby.Gym.Longitude) + $"&key={_config.GmapsKey}",
                ThumbnailUrl = pkmnImage,
                Footer       = new DiscordEmbedBuilder.EmbedFooter
                {
                    Text    = $"versx | {DateTime.Now}",
                    IconUrl = _client.Guilds.ContainsKey(_config.GuildId) ? _client.Guilds[_config.GuildId].IconUrl : string.Empty
                }
            };

            var item = lobby.Gym.IsEgg ? $"Level {lobby.Gym.RaidLevel} Egg" : Database.Pokemon[lobby.Gym.RaidPokemonId].Name;

            eb.AddField("Raid Boss", item, true);
            if (lobby.Gym.ExRaidEligible)
            {
                eb.AddField("EX-Eligible Raid", "Yes", true);
            }

            eb.AddField("Level", lobby.Gym.RaidLevel.ToString(), true);
            if (lobby.Gym.IsEgg)
            {
                eb.AddField("Starts", lobby.Gym.RaidBattleTimestamp.FromUnix().ToLongTimeString(), true);
            }
            else
            {
                eb.AddField("CP", lobby.Gym.RaidPokemonCP.ToString("N0"), true);
                eb.AddField("Ends", lobby.Gym.RaidEndTimestamp.FromUnix().ToLongTimeString(), true);
                if (Database.Movesets.ContainsKey(lobby.Gym.RaidPokemonMove1))
                {
                    var fastMove       = Database.Movesets[lobby.Gym.RaidPokemonMove1];
                    var fastMoveTypeId = _client.Guilds[_config.GuildId].GetEmojiId($"types_{fastMove.Type}");
                    if (fastMoveTypeId > 0)
                    {
                        eb.AddField("Fast Move", string.Format(Strings.TypeEmojiSchema, fastMove.Type.ToLower(), fastMoveTypeId) + $" {fastMove.Name}", true);
                    }
                }
                if (Database.Movesets.ContainsKey(lobby.Gym.RaidPokemonMove2))
                {
                    var chargeMove       = Database.Movesets[lobby.Gym.RaidPokemonMove2];
                    var chargeMoveTypeId = _client.Guilds[_config.GuildId].GetEmojiId($"types_{chargeMove.Type}");
                    if (chargeMoveTypeId > 0)
                    {
                        eb.AddField("Charge Move", string.Format(Strings.TypeEmojiSchema, chargeMove.Type.ToLower(), chargeMoveTypeId) + $" {chargeMove.Name}", true);
                    }
                }

                var weaknessesEmojis = Database.Pokemon[lobby.Gym.RaidPokemonId].Types.GetWeaknessEmojiIcons(_client, _config.GuildId);
                if (!string.IsNullOrEmpty(weaknessesEmojis))
                {
                    eb.AddField("Weaknesses", weaknessesEmojis + "\r\n", true);
                }
            }

            if (_client.Guilds.ContainsKey(_config.GuildId))
            {
                if (lobby.Gym.ExRaidEligible)
                {
                    var exEmojiId = _client.Guilds.ContainsKey(_config.GuildId) ? _client.Guilds[_config.GuildId].GetEmojiId("ex") : 0;
                    var exEmoji   = exEmojiId > 0 ? $"<:ex:{exEmojiId}>" : "EX";
                    eb.AddField("Ex-Eligible", exEmoji + " **Gym!**");
                }

                var teamId = _client.Guilds[_config.GuildId].GetEmojiId(lobby.Gym.Team.ToString().ToLower());
                eb.AddField("Team", $"<:{lobby.Gym.Team.ToString().ToLower()}:{teamId}>", true);
            }

            if (!string.IsNullOrEmpty(lobby.StartedBy))
            {
                eb.AddField("Started By", lobby.StartedBy, true);
            }
            eb.AddField("Location", $"{Math.Round(lobby.Gym.Latitude, 5)},{Math.Round(lobby.Gym.Longitude, 5)}\r\n" +
                        $"**[[Google Maps]({string.Format(Strings.GoogleMaps, lobby.Gym.Latitude, lobby.Gym.Longitude)})]**\r\n" +
                        $"**[[Apple Maps]({string.Format(Strings.AppleMaps, lobby.Gym.Latitude, lobby.Gym.Longitude)})]**", true);

            if (!_config.RaidLobbies.ContainsKey(lobby.ChannelName))
            {
                _logger.Warn($"Raid lobby does not exist yet for '{lobby.ChannelName}'.");
                return;
            }

            var raidLobby = _config.RaidLobbies[lobby.ChannelName];

            AddOrUpdateUser(raidLobby, user, isOtw);

            if (raidLobby.Users?.Count == 0)
            {
                //Delete the channel if no one is interested anymore.
                await lobbyChannel.DeleteAsync();

                return;
            }

            var usersOtw = string.Join(Environment.NewLine, raidLobby.Users?.Where(x => x.IsOnTheWay).Select(x => x.Username));

            eb.AddField("Trainers On the Way:", string.IsNullOrEmpty(usersOtw) ? "Unknown" : usersOtw, true);

            var usersHere = string.Join(Environment.NewLine, raidLobby.Users?.Where(x => x.IsHere).Select(x => x.Username));

            eb.AddField("Trainers At the Raid:", string.IsNullOrEmpty(usersHere) ? "Unknown" : usersHere, true);

            eb.Footer = new DiscordEmbedBuilder.EmbedFooter
            {
                Text    = $"➡ On your way ✅ Here ❌ No longer interested 🔄 Refresh lobby message.",
                IconUrl = lobbyChannel.Guild?.IconUrl
            };

            var lobbyMessage = default(DiscordMessage);
            var pinned       = await lobbyChannel.GetPinnedMessagesAsync();

            if (pinned?.Count > 0)
            {
                lobbyMessage = await pinned[0].ModifyAsync(string.Empty, eb);
            }
            else
            {
                lobbyMessage = await lobbyChannel.SendMessageAsync($"{user.Username}#{user.Discriminator} started a raid lobby for {item} at {lobby.Gym.Name}", false, eb);

                await lobbyMessage.PinAsync();
            }
            await _client.SetDefaultRaidReactions(lobbyMessage, true);
        }