示例#1
0
        //Users
        public static async Task <RestGuildUser> AddGuildUserAsync(IGuild guild, BaseDiscordClient client, ulong userId, string accessToken,
                                                                   Action <AddGuildUserProperties> func, RequestOptions options)
        {
            AddGuildUserProperties args = new AddGuildUserProperties();

            func?.Invoke(args);

            if (args.Roles.IsSpecified)
            {
                IEnumerable <ulong> ids = args.Roles.Value.Select(r => r.Id);

                if (args.RoleIds.IsSpecified)
                {
                    args.RoleIds.Value.Concat(ids);
                }
                else
                {
                    args.RoleIds = Optional.Create(ids);
                }
            }
            AddGuildMemberParams apiArgs = new AddGuildMemberParams
            {
                AccessToken = accessToken,
                Nickname    = args.Nickname,
                IsDeafened  = args.Deaf,
                IsMuted     = args.Mute,
                RoleIds     = args.RoleIds.IsSpecified ? args.RoleIds.Value.Distinct().ToArray() : Optional.Create <ulong[]>()
            };

            GuildMemberJson model = await client.ApiClient.AddGuildMemberAsync(guild.Id, userId, apiArgs, options);

            return(model is null ? null : RestGuildUser.Create(client, guild, model));
        }
示例#2
0
        public static async Task <RestGuildUser> GetUserAsync(IGuild guild, BaseDiscordClient client,
                                                              ulong id, RequestOptions options)
        {
            GuildMemberJson model = await client.ApiClient.GetGuildMemberAsync(guild.Id, id, options).ConfigureAwait(false);

            if (model != null)
            {
                return(RestGuildUser.Create(client, guild, model));
            }
            return(null);
        }
示例#3
0
 private void Load(GuildMemberJson guildMemberJson)
 {
     if (guildMemberJson != null)
     {
         Rank = guildMemberJson.Rank;
         if (guildMemberJson.Member != null)
         {
             CharacterId   = guildMemberJson.Member.Id;
             CharacterName = guildMemberJson.Member.Name;
             if (guildMemberJson.Member.Realm != null)
             {
                 CharacterRealmSlug = guildMemberJson.Member.Realm.Slug;
             }
         }
     }
 }
示例#4
0
 public GuildMember(GuildMemberJson guildMemberJson) : base()
 {
     Load(guildMemberJson);
 }