internal static RestSimpleCommunity Create(BaseRestClient client, Model model)
        {
            var entity = new RestSimpleCommunity(client, model.Id);

            entity.Update(model);
            return(entity);
        }
Example #2
0
        internal static Task ReportChannelAsync(RestSimpleCommunity community, ulong userId, ulong channelId)
        {
            if (!TokenHelper.TryGetToken(community.Client, userId, out RestTokenInfo info))
            {
                throw new InvalidOperationException("No valid token specified for this user.");
            }

            return(community.Client.RestClient.CommunityReportInternalAsync(info.Token, community.Id, channelId));
        }
Example #3
0
        public static Task RemoveAvatarAsync(RestSimpleCommunity community, ulong userId)
        {
            if (!TokenHelper.TryGetToken(community.Client, userId, out RestTokenInfo info))
            {
                throw new MissingScopeException("communities_edit");
            }
            if (!info.Authorization.Scopes.Contains("communities_edit"))
            {
                throw new MissingScopeException("communities_edit");
            }

            return(community.Client.RestClient.RemoveAvatarInternalAsync(info.Token, community.Id));
        }
Example #4
0
        internal static Task RemoveTimeoutAsync(RestSimpleCommunity community, ulong userId, ulong victimId)
        {
            if (!TokenHelper.TryGetToken(community.Client, userId, out RestTokenInfo info))
            {
                throw new MissingScopeException("communities_moderate");
            }
            if (!info.Authorization.Scopes.Contains("communities_moderate"))
            {
                throw new MissingScopeException("communities_moderate");
            }

            return(community.Client.RestClient.RemoveCommunityTimeoutInternalAsync(info.Token, community.Id, victimId));
        }
Example #5
0
        internal static async Task <RestCommunityPermissions> GetPermissionsAsync(RestSimpleCommunity community, ulong userId)
        {
            if (!TokenHelper.TryGetToken(community.Client, userId, out RestTokenInfo info))
            {
                throw new InvalidOperationException("No valid token specified for this user.");
            }

            var model = await community.Client.RestClient.GetCommunityPermissionsInternalAsync(info.Token, community.Id);

            var entity = new RestCommunityPermissions();

            entity.Update(model);
            return(entity);
        }
Example #6
0
        public static async Task SetAvatarAsync(RestSimpleCommunity community, ulong userId, Stream avatarStream)
        {
            if (!TokenHelper.TryGetToken(community.Client, userId, out RestTokenInfo info))
            {
                throw new MissingScopeException("communities_edit");
            }
            if (!info.Authorization.Scopes.Contains("communities_edit"))
            {
                throw new MissingScopeException("communities_edit");
            }

            var imageString = GetBase64String(avatarStream);
            await community.Client.RestClient.SetAvatarInternalAsync(info.Token, community.Id, imageString).ConfigureAwait(false);

            //if (community is RestCommunity c)
            //    await c.UpdateAsync().ConfigureAwait(false);
        }
Example #7
0
        public static Task ModifyAsync(RestSimpleCommunity community, ulong userId, Action <ModifyCommunityParams> options)
        {
            if (!TokenHelper.TryGetToken(community.Client, userId, out RestTokenInfo info))
            {
                throw new MissingScopeException("communities_edit");
            }
            if (!info.Authorization.Scopes.Contains("communities_edit"))
            {
                throw new MissingScopeException("communities_edit");
            }

            var changes = new ModifyCommunityParams();

            options.Invoke(changes);

            return(community.Client.RestClient.ModifyCommunityInternalAsync(info.Token, community.Id, changes));
        }
Example #8
0
        public static Task SetAvatarAsync(RestSimpleCommunity community, ulong userId, string avatarPath)
        {
            var avatarStream = File.Open(avatarPath, FileMode.Open);

            return(SetAvatarAsync(community, userId, avatarStream));
        }
Example #9
0
        internal static async Task <IReadOnlyCollection <RestBannedUser> > GetTimeoutsAsync(RestSimpleCommunity community, ulong userId, uint limit)
        {
            if (!TokenHelper.TryGetToken(community.Client, userId, out RestTokenInfo info))
            {
                throw new MissingScopeException("communities_moderate");
            }
            if (!info.Authorization.Scopes.Contains("communities_moderate"))
            {
                throw new MissingScopeException("communities_moderate");
            }

            var model = await community.Client.RestClient.GetCommunityTimeoutsInternalAsync(info.Token, community.Id, limit);

            var entity = model.Timeouts.Select(x =>
            {
                var user = new RestBannedUser(community.Client, x.Id);
                user.Update(x);
                return(user);
            });

            return(entity.ToArray());
        }
Example #10
0
        public static Task SetCoverAsync(RestSimpleCommunity community, ulong userId, string coverPath)
        {
            var coverStream = File.Open(coverPath, FileMode.Open);

            return(SetCoverAsync(community, userId, coverStream));
        }
 internal void Update(RestSimpleCommunity community)
 {
     Name      = community.Name;
     AvatarUrl = community.AvatarUrl;
 }