Пример #1
0
        /// <summary>
        /// Create a new Open Data blog posting.
        /// </summary>
        /// <param name="Id">The unique identification of this blog posting.</param>
        /// <param name="Text">The (multi-language) text of this blog posting.</param>
        /// <param name="PublicationDate">The timestamp of the publication of this blog posting.</param>
        /// <param name="GeoLocation">An optional geographical location of this blog posting.</param>
        /// <param name="Tags">An enumeration of multi-language tags and their relevance.</param>
        /// <param name="PrivacyLevel">Whether the blog posting will be shown in blog posting listings, or not.</param>
        /// <param name="IsHidden">The blog posting is hidden.</param>
        /// <param name="Signatures">All signatures of this blog posting.</param>
        /// <param name="DataSource">The source of all this data, e.g. an automatic importer.</param>
        public BlogPosting(BlogPosting_Id Id,
                           I18NString Text,
                           DateTime?PublicationDate        = null,
                           GeoCoordinate?GeoLocation       = null,
                           IEnumerable <TagRelevance> Tags = null,
                           PrivacyLevel?PrivacyLevel       = null,
                           Boolean IsHidden = false,
                           IEnumerable <BlogPostingSignature> Signatures = null,
                           String DataSource = "")

            : base(Id,
                   DefaultJSONLDContext,
                   null,
                   DataSource)

        {
            this.Text            = Text;
            this.PublicationDate = PublicationDate ?? DateTime.Now;
            this.GeoLocation     = GeoLocation;
            this.Tags            = Tags ?? new TagRelevance[0];
            this.PrivacyLevel    = PrivacyLevel ?? social.OpenData.UsersAPI.PrivacyLevel.Private;
            this.IsHidden        = false;
            this.Signatures      = Signatures ?? new BlogPostingSignature[0];

            CalcHash();
        }
Пример #2
0
        public async Task Privacy(Context ctx, PKMember target, PrivacyLevel?newValueFromCommand)
        {
            if (ctx.System == null)
            {
                throw Errors.NoSystemError;
            }
            if (target.System != ctx.System.Id)
            {
                throw Errors.NotOwnMemberError;
            }

            PrivacyLevel newValue;

            if (ctx.Match("private", "hide", "hidden", "on", "enable", "yes"))
            {
                newValue = PrivacyLevel.Private;
            }
            else if (ctx.Match("public", "show", "shown", "displayed", "off", "disable", "no"))
            {
                newValue = PrivacyLevel.Public;
            }
            else if (ctx.HasNext())
            {
                throw new PKSyntaxError("You must pass either \"private\" or \"public\".");
            }
            // If we're getting a value from command (eg. "pk;m <name> private" == always private, "pk;m <name> public == always public"), use that instead of parsing
            else if (newValueFromCommand != null)
            {
                newValue = newValueFromCommand.Value;
            }
            else
            {
                if (target.MemberPrivacy == PrivacyLevel.Public)
                {
                    await ctx.Reply("This member's privacy is currently set to **public**. This member will show up in member lists and will return all information when queried by other accounts.");
                }
                else
                {
                    await ctx.Reply("This member's privacy is currently set to **private**. This member will not show up in member lists and will return limited information when queried by other accounts.");
                }

                return;
            }

            target.MemberPrivacy = newValue;
            await _data.SaveMember(target);

            if (newValue == PrivacyLevel.Private)
            {
                await ctx.Reply($"{Emojis.Success} Member privacy set to **private**. This member will no longer show up in member lists and will return limited information when queried by other accounts.");
            }
            else
            {
                await ctx.Reply($"{Emojis.Success} Member privacy set to **public**. This member will now show up in member lists and will return all information when queried by other accounts.");
            }
        }
        public Task <int> GetSystemMemberCount(IPKConnection conn, SystemId id, PrivacyLevel?privacyFilter = null)
        {
            var query = new StringBuilder("select count(*) from members where system = @Id");

            if (privacyFilter != null)
            {
                query.Append($" and member_visibility = {(int) privacyFilter.Value}");
            }
            return(conn.QuerySingleAsync <int>(query.ToString(), new { Id = id }));
        }
    public Task <int> GetSystemGroupCount(SystemId system, PrivacyLevel?privacyFilter = null)
    {
        var query = new Query("groups").SelectRaw("count(*)").Where("system", system);

        if (privacyFilter != null)
        {
            query.Where("visibility", (int)privacyFilter.Value);
        }

        return(_db.QueryFirst <int>(query));
    }
Пример #5
0
    public Task <int> GetGroupMemberCount(GroupId id, PrivacyLevel?privacyFilter = null)
    {
        var query = new Query("group_members")
                    .SelectRaw("count(*)")
                    .Where("group_members.group_id", id);

        if (privacyFilter != null)
        {
            query = query
                    .Join("members", "group_members.member_id", "members.id")
                    .Where("members.member_visibility", privacyFilter);
        }

        return(_db.QueryFirst <int>(query));
    }
Пример #6
0
        public Task <int> GetGroupMemberCount(IPKConnection conn, GroupId id, PrivacyLevel?privacyFilter = null)
        {
            var query = new StringBuilder("select count(*) from group_members");

            if (privacyFilter != null)
            {
                query.Append(" inner join members on group_members.member_id = members.id");
            }
            query.Append(" where group_members.group_id = @Id");
            if (privacyFilter != null)
            {
                query.Append(" and members.member_visibility = @PrivacyFilter");
            }
            return(conn.QuerySingleOrDefaultAsync <int>(query.ToString(), new { Id = id, PrivacyFilter = privacyFilter }));
        }
Пример #7
0
        /// <summary>
        /// Modifies fields of an existing Stage instance.
        /// Requires the user to be a moderator of the Stage channel.
        /// See <a href="https://discord.com/developers/docs/resources/stage-instance#modify-stage-instance">Update Stage Instance</a>
        /// </summary>
        /// <param name="client">Client to use</param>
        /// <param name="topic">The new topic for the stage instance</param>
        /// <param name="privacyLevel">Privacy level for the stage instance</param>
        /// <param name="callback">Callback when the updated stage instance</param>
        /// <param name="error">Callback when an error occurs with error information</param>
        public void ModifyStageInstance(DiscordClient client, string topic = null, PrivacyLevel?privacyLevel = null, Action <StageInstance> callback = null, Action <RestError> error = null)
        {
            Dictionary <string, string> data = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(topic))
            {
                data["topic"] = topic;
            }

            if (privacyLevel.HasValue)
            {
                data["privacy_level"] = ((int)privacyLevel).ToString();
            }

            client.Bot.Rest.DoRequest($"/stage-instances/{ChannelId}", RequestMethod.PATCH, data, callback, error);
        }
Пример #8
0
            /// <summary>
            /// Create a new Posting builder.
            /// </summary>
            /// <param name="Id">The unique identification of this blog posting.</param>
            /// <param name="Text">The (multi-language) text of this blog posting.</param>
            /// <param name="PublicationDate">The timestamp of the publication of this blog posting.</param>
            /// <param name="GeoLocation">An optional geographical location of this blog posting.</param>
            /// <param name="Tags">An enumeration of multi-language tags and their relevance.</param>
            /// <param name="PrivacyLevel">Whether the blog posting will be shown in blog posting listings, or not.</param>
            /// <param name="IsHidden">The blog posting is hidden.</param>
            /// <param name="Signatures">All signatures of this blog posting.</param>
            /// <param name="DataSource">The source of all this data, e.g. an automatic importer.</param>
            public Builder(BlogPosting_Id Id,
                           I18NString Text,
                           DateTime?PublicationDate        = null,
                           GeoCoordinate?GeoLocation       = null,
                           IEnumerable <TagRelevance> Tags = null,
                           PrivacyLevel?PrivacyLevel       = null,
                           Boolean IsHidden = false,
                           IEnumerable <BlogPostingSignature> Signatures = null,
                           String DataSource = "")

            {
                this.Id              = Id;
                this.Text            = Text;
                this.PublicationDate = PublicationDate ?? DateTime.Now;
                this.GeoLocation     = GeoLocation;
                this.Tags            = Tags ?? new TagRelevance[0];
                this.PrivacyLevel    = PrivacyLevel ?? social.OpenData.UsersAPI.PrivacyLevel.Private;
                this.IsHidden        = false;
                this.Signatures      = Signatures ?? new BlogPostingSignature[0];
                this.DataSource      = DataSource;
            }
Пример #9
0
            /// <summary>
            /// Create a new Posting builder.
            /// </summary>
            /// <param name="Text">The (multi-language) text of this blog posting.</param>
            /// <param name="PublicationDate">The timestamp of the publication of this blog posting.</param>
            /// <param name="GeoLocation">An optional geographical location of this blog posting.</param>
            /// <param name="Tags">An enumeration of multi-language tags and their relevance.</param>
            /// <param name="PrivacyLevel">Whether the blog posting will be shown in blog posting listings, or not.</param>
            /// <param name="IsHidden">The blog posting is hidden.</param>
            /// <param name="Signatures">All signatures of this blog posting.</param>
            /// <param name="DataSource">The source of all this data, e.g. an automatic importer.</param>
            public Builder(I18NString Text,
                           DateTime?PublicationDate        = null,
                           GeoCoordinate?GeoLocation       = null,
                           IEnumerable <TagRelevance> Tags = null,
                           PrivacyLevel?PrivacyLevel       = null,
                           Boolean IsHidden = false,
                           IEnumerable <BlogPostingSignature> Signatures = null,
                           String DataSource = "")

                : this(BlogPosting_Id.Random(),
                       Text,
                       PublicationDate,
                       GeoLocation,
                       Tags,
                       PrivacyLevel,
                       IsHidden,
                       Signatures,
                       DataSource)

            {
            }
Пример #10
0
        public static Task <IEnumerable <ListedMember> > QueryMemberList(this IPKConnection conn, SystemId system, PrivacyLevel?privacyFilter = null, string?filter = null, bool includeDescriptionInNameFilter = false)
        {
            StringBuilder query = new StringBuilder("select * from member_list where system = @system");

            if (privacyFilter != null)
            {
                query.Append($" and member_privacy = {(int) privacyFilter}");
            }

            if (filter != null)
            {
Пример #11
0
        public async Task Privacy(Context ctx, PKMember target, PrivacyLevel?newValueFromCommand)
        {
            ctx.CheckSystem().CheckOwnMember(target);

            // Display privacy settings
            if (!ctx.HasNext() && newValueFromCommand == null)
            {
                await ctx.Reply(embed : new EmbedBuilder()
                                .Title($"Current privacy settings for {target.NameFor(ctx)}")
                                .Field(new("Name (replaces name with display name if member has one)", target.NamePrivacy.Explanation()))
                                .Field(new("Description", target.DescriptionPrivacy.Explanation()))
                                .Field(new("Avatar", target.AvatarPrivacy.Explanation()))
                                .Field(new("Birthday", target.BirthdayPrivacy.Explanation()))
                                .Field(new("Pronouns", target.PronounPrivacy.Explanation()))
                                .Field(new("Meta (message count, last front, last message)", target.MetadataPrivacy.Explanation()))
                                .Field(new("Visibility", target.MemberVisibility.Explanation()))
                                .Description("To edit privacy settings, use the command:\n`pk;member <member> privacy <subject> <level>`\n\n- `subject` is one of `name`, `description`, `avatar`, `birthday`, `pronouns`, `created`, `messages`, `visibility`, or `all`\n- `level` is either `public` or `private`.")
                                .Build());

                return;
            }

            // Get guild settings (mostly for warnings and such)
            MemberGuildSettings guildSettings = null;

            if (ctx.Guild != null)
            {
                guildSettings = await _db.Execute(c => _repo.GetMemberGuild(c, ctx.Guild.Id, target.Id));
            }

            async Task SetAll(PrivacyLevel level)
            {
                await _db.Execute(c => _repo.UpdateMember(c, target.Id, new MemberPatch().WithAllPrivacy(level)));

                if (level == PrivacyLevel.Private)
                {
                    await ctx.Reply($"{Emojis.Success} All {target.NameFor(ctx)}'s privacy settings have been set to **{level.LevelName()}**. Other accounts will now see nothing on the member card.");
                }
                else
                {
                    await ctx.Reply($"{Emojis.Success} All {target.NameFor(ctx)}'s privacy settings have been set to **{level.LevelName()}**. Other accounts will now see everything on the member card.");
                }
            }

            async Task SetLevel(MemberPrivacySubject subject, PrivacyLevel level)
            {
                await _db.Execute(c => _repo.UpdateMember(c, target.Id, new MemberPatch().WithPrivacy(subject, level)));

                var subjectName = subject switch
                {
                    MemberPrivacySubject.Name => "name privacy",
                    MemberPrivacySubject.Description => "description privacy",
                    MemberPrivacySubject.Avatar => "avatar privacy",
                    MemberPrivacySubject.Pronouns => "pronoun privacy",
                    MemberPrivacySubject.Birthday => "birthday privacy",
                    MemberPrivacySubject.Metadata => "metadata privacy",
                    MemberPrivacySubject.Visibility => "visibility",
                    _ => throw new ArgumentOutOfRangeException($"Unknown privacy subject {subject}")
                };

                var explanation = (subject, level) switch
                {
                    (MemberPrivacySubject.Name, PrivacyLevel.Private) => "This member's name is now hidden from other systems, and will be replaced by the member's display name.",
                    (MemberPrivacySubject.Description, PrivacyLevel.Private) => "This member's description is now hidden from other systems.",
                    (MemberPrivacySubject.Avatar, PrivacyLevel.Private) => "This member's avatar is now hidden from other systems.",
                    (MemberPrivacySubject.Birthday, PrivacyLevel.Private) => "This member's birthday is now hidden from other systems.",
                    (MemberPrivacySubject.Pronouns, PrivacyLevel.Private) => "This member's pronouns are now hidden from other systems.",
                    (MemberPrivacySubject.Metadata, PrivacyLevel.Private) => "This member's metadata (eg. created timestamp, message count, etc) is now hidden from other systems.",
                    (MemberPrivacySubject.Visibility, PrivacyLevel.Private) => "This member is now hidden from member lists.",

                    (MemberPrivacySubject.Name, PrivacyLevel.Public) => "This member's name is no longer hidden from other systems.",
                    (MemberPrivacySubject.Description, PrivacyLevel.Public) => "This member's description is no longer hidden from other systems.",
                    (MemberPrivacySubject.Avatar, PrivacyLevel.Public) => "This member's avatar is no longer hidden from other systems.",
                    (MemberPrivacySubject.Birthday, PrivacyLevel.Public) => "This member's birthday is no longer hidden from other systems.",
                    (MemberPrivacySubject.Pronouns, PrivacyLevel.Public) => "This member's pronouns are no longer hidden other systems.",
                    (MemberPrivacySubject.Metadata, PrivacyLevel.Public) => "This member's metadata (eg. created timestamp, message count, etc) is no longer hidden from other systems.",
                    (MemberPrivacySubject.Visibility, PrivacyLevel.Public) => "This member is no longer hidden from member lists.",

                    _ => throw new InvalidOperationException($"Invalid subject/level tuple ({subject}, {level})")
                };

                await ctx.Reply($"{Emojis.Success} {target.NameFor(ctx)}'s **{subjectName}** has been set to **{level.LevelName()}**. {explanation}");

                // Name privacy only works given a display name
                if (subject == MemberPrivacySubject.Name && level == PrivacyLevel.Private && target.DisplayName == null)
                {
                    await ctx.Reply($"{Emojis.Warn} This member does not have a display name set, and name privacy **will not take effect**.");
                }

                // Avatar privacy doesn't apply when proxying if no server avatar is set
                if (subject == MemberPrivacySubject.Avatar && level == PrivacyLevel.Private && guildSettings?.AvatarUrl == null)
                {
                    await ctx.Reply($"{Emojis.Warn} This member does not have a server avatar set, so *proxying* will **still show the member avatar**. If you want to hide your avatar when proxying here, set a server avatar: `pk;member {target.Reference()} serveravatar`");
                }
            }

            if (ctx.Match("all") || newValueFromCommand != null)
            {
                await SetAll(newValueFromCommand ?? ctx.PopPrivacyLevel());
            }
            else
            {
                await SetLevel(ctx.PopMemberPrivacySubject(), ctx.PopPrivacyLevel());
            }
        }
Пример #12
0
        public async Task Privacy(Context ctx, PKMember target, PrivacyLevel?newValueFromCommand)
        {
            if (ctx.System == null)
            {
                throw Errors.NoSystemError;
            }
            if (target.System != ctx.System.Id)
            {
                throw Errors.NotOwnMemberError;
            }

            // Display privacy settings
            if (!ctx.HasNext() && newValueFromCommand == null)
            {
                await ctx.Reply(embed : CreatePrivacyEmbed(ctx, target));

                return;
            }

            // Get guild settings (mostly for warnings and such)
            MemberGuildSettings guildSettings = null;

            if (ctx.Guild != null)
            {
                guildSettings = await _db.Execute(c => c.QueryOrInsertMemberGuildConfig(ctx.Guild.Id, target.Id));
            }

            // Set Privacy Settings
            PrivacyLevel PopPrivacyLevel(string subjectName)
            {
                if (ctx.Match("public", "show", "shown", "visible"))
                {
                    return(PrivacyLevel.Public);
                }

                if (ctx.Match("private", "hide", "hidden"))
                {
                    return(PrivacyLevel.Private);
                }

                if (!ctx.HasNext())
                {
                    throw new PKSyntaxError($"You must pass a privacy level for `{subjectName}` (`public` or `private`)");
                }
                throw new PKSyntaxError($"Invalid privacy level `{ctx.PopArgument()}` (must be `public` or `private`).");
            }

            // See if we have a subject given
            PrivacyLevel newLevel;

            if (PrivacyUtils.TryParseMemberPrivacy(ctx.PeekArgument(), out var subject))
            {
                // We peeked before, pop it now
                ctx.PopArgument();

                // Read the privacy level from args
                newLevel = PopPrivacyLevel(subject.Name());

                // Set the level on the given subject
                target.SetPrivacy(subject, newLevel);
                await _data.SaveMember(target);

                // Print response
                var explanation = (subject, newLevel) switch
                {
                    (MemberPrivacySubject.Name, PrivacyLevel.Private) => "This member's name is now hidden from other systems, and will be replaced by the member's display name.",
                    (MemberPrivacySubject.Description, PrivacyLevel.Private) => "This member's description is now hidden from other systems.",
                    (MemberPrivacySubject.Avatar, PrivacyLevel.Private) => "This member's avatar is now hidden from other systems.",
                    (MemberPrivacySubject.Birthday, PrivacyLevel.Private) => "This member's birthday is now hidden from other systems.",
                    (MemberPrivacySubject.Pronouns, PrivacyLevel.Private) => "This member's pronouns are now hidden from other systems.",
                    (MemberPrivacySubject.Metadata, PrivacyLevel.Private) => "This member's metadata (eg. created timestamp, message count, etc) is now hidden from other systems.",
                    (MemberPrivacySubject.Visibility, PrivacyLevel.Private) => "This member is now hidden from member lists.",

                    (MemberPrivacySubject.Name, PrivacyLevel.Public) => "This member's name is no longer hidden from other systems.",
                    (MemberPrivacySubject.Description, PrivacyLevel.Public) => "This member's description is no longer hidden from other systems.",
                    (MemberPrivacySubject.Avatar, PrivacyLevel.Public) => "This member's avatar is no longer hidden from other systems.",
                    (MemberPrivacySubject.Birthday, PrivacyLevel.Public) => "This member's birthday is no longer hidden from other systems.",
                    (MemberPrivacySubject.Pronouns, PrivacyLevel.Public) => "This member's pronouns are no longer hidden other systems.",
                    (MemberPrivacySubject.Metadata, PrivacyLevel.Public) => "This member's metadata (eg. created timestamp, message count, etc) is no longer hidden from other systems.",
                    (MemberPrivacySubject.Visibility, PrivacyLevel.Public) => "This member is no longer hidden from member lists.",

                    _ => throw new InvalidOperationException($"Invalid subject/level tuple ({subject}, {newLevel})")
                };

                await ctx.Reply($"{Emojis.Success} {target.NameFor(ctx)}'s {subject.Name()} has been set to **{newLevel.LevelName()}**. {explanation}");
            }
            else if (ctx.Match("all") || newValueFromCommand != null)
            {
                newLevel = newValueFromCommand ?? PopPrivacyLevel("all");
                target.SetAllPrivacy(newLevel);
                await _data.SaveMember(target);

                if (newLevel == PrivacyLevel.Private)
                {
                    await ctx.Reply($"All {target.NameFor(ctx)}'s privacy settings have been set to **{newLevel.LevelName()}**. Other accounts will now see nothing on the member card.");
                }
                else
                {
                    await ctx.Reply($"All {target.NameFor(ctx)}'s privacy settings have been set to **{newLevel.LevelName()}**. Other accounts will now see everything on the member card.");
                }
            }
            else
            {
                var subjectList = "`name`, `description`, `avatar`, `birthday`, `pronouns`, `metadata`, `visibility`, or `all`";
                throw new PKSyntaxError($"Invalid privacy subject `{ctx.PopArgument()}` (must be {subjectList}).");
            }

            // Name privacy only works given a display name
            if (subject == MemberPrivacySubject.Name && newLevel == PrivacyLevel.Private && target.DisplayName == null)
            {
                await ctx.Reply($"{Emojis.Warn} This member does not have a display name set, and name privacy **will not take effect**.");
            }
            // Avatar privacy doesn't apply when proxying if no server avatar is set
            if (subject == MemberPrivacySubject.Avatar && newLevel == PrivacyLevel.Private &&
                guildSettings?.AvatarUrl == null)
            {
                await ctx.Reply($"{Emojis.Warn} This member does not have a server avatar set, so *proxying* will **still show the member avatar**. If you want to hide your avatar when proxying here, set a server avatar: `pk;member {target.Hid} serveravatar`");
            }
        }