Пример #1
0
        private async Task OnGuildMemberUpdate(GuildMemberUpdateEventArgs arg)
        {
            try
            {
                DiscordGuildPacket guild = await _discordClient.GetGuildAsync(arg.GuildId);

                if (guild.Members == null)
                {
                    guild.Members = new List <DiscordGuildMemberPacket>();
                }

                int index = guild.Members.FindIndex(x => x.UserId == arg.User.Id);

                DiscordGuildMemberPacket packet;

                if (index == -1)
                {
                    packet = new DiscordGuildMemberPacket
                    {
                        User     = arg.User,
                        Roles    = arg.RoleIds.ToList(),
                        Nickname = arg.Nickname,
                        UserId   = arg.User.Id,
                        GuildId  = arg.GuildId,
                    };

                    guild.Members.Add(packet);
                }
                else
                {
                    guild.Members[index].Nickname = arg.Nickname;
                    guild.Members[index].Roles    = arg.RoleIds.ToList();
                    guild.Members[index].User     = arg.User;

                    packet = guild.Members[index];
                }

                var cache = _cacheClient.Get;

                await cache.UpsertAsync($"discord:guild:{arg.GuildId}:user:{arg.User.Id}", packet);

                await cache.UpsertAsync($"discord:guild:{arg.GuildId}", guild);
            }
            catch (Exception e)
            {
                Log.Trace(e.ToString());
            }
        }
Пример #2
0
 public async Task <IDiscordGuild> GetGuildAsync(ulong id)
 => new DiscordGuild(
     await _apiClient.GetGuildAsync(id),
     this
     );