Example #1
0
        public async Task GroupDescription(Context ctx, PKGroup target)
        {
            if (await ctx.MatchClear("this group's description"))
            {
                ctx.CheckOwnGroup(target);

                var patch = new GroupPatch {
                    Description = Partial <string> .Null()
                };
                await _db.Execute(conn => _repo.UpdateGroup(conn, target.Id, patch));

                await ctx.Reply($"{Emojis.Success} Group description cleared.");
            }
            else if (!ctx.HasNext())
            {
                if (target.Description == null)
                {
                    if (ctx.System?.Id == target.System)
                    {
                        await ctx.Reply($"This group does not have a description set. To set one, type `pk;group {target.Reference()} description <description>`.");
                    }
                    else
                    {
                        await ctx.Reply("This group does not have a description set.");
                    }
                }
                else if (ctx.MatchFlag("r", "raw"))
                {
                    await ctx.Reply($"```\n{target.Description}\n```");
                }
                else
                {
                    await ctx.Reply(embed : new DiscordEmbedBuilder()
                                    .WithTitle("Group description")
                                    .WithDescription(target.Description)
                                    .AddField("\u200B", $"To print the description with formatting, type `pk;group {target.Reference()} description -raw`."
                                              + (ctx.System?.Id == target.System ? $" To clear it, type `pk;group {target.Reference()} description -clear`." : ""))
                                    .Build());
                }
            }
            else
            {
                ctx.CheckOwnGroup(target);

                var description = ctx.RemainderOrNull().NormalizeLineEndSpacing();
                if (description.IsLongerThan(Limits.MaxDescriptionLength))
                {
                    throw Errors.DescriptionTooLongError(description.Length);
                }

                var patch = new GroupPatch {
                    Description = Partial <string> .Present(description)
                };
                await _db.Execute(conn => _repo.UpdateGroup(conn, target.Id, patch));

                await ctx.Reply($"{Emojis.Success} Group description changed.");
            }
        }
Example #2
0
        public async Task Description(Context ctx, PKMember target)
        {
            if (MatchClear(ctx))
            {
                CheckEditMemberPermission(ctx, target);
                target.Description = null;

                await _data.SaveMember(target);

                await ctx.Reply($"{Emojis.Success} Member description cleared.");
            }
            else if (!ctx.HasNext())
            {
                if (!target.DescriptionPrivacy.CanAccess(ctx.LookupContextFor(target.System)))
                {
                    throw Errors.LookupNotAllowed;
                }
                if (target.Description == null)
                {
                    if (ctx.System?.Id == target.System)
                    {
                        await ctx.Reply($"This member does not have a description set. To set one, type `pk;member {target.Hid} description <description>`.");
                    }
                    else
                    {
                        await ctx.Reply("This member does not have a description set.");
                    }
                }
                else if (ctx.MatchFlag("r", "raw"))
                {
                    await ctx.Reply($"```\n{target.Description}\n```");
                }
                else
                {
                    await ctx.Reply(embed : new DiscordEmbedBuilder()
                                    .WithTitle("Member description")
                                    .WithDescription(target.Description)
                                    .AddField("\u200B", $"To print the description with formatting, type `pk;member {target.Hid} description -raw`."
                                              + (ctx.System?.Id == target.System ? $" To clear it, type `pk;member {target.Hid} description -clear`." : ""))
                                    .Build());
                }
            }
            else
            {
                CheckEditMemberPermission(ctx, target);

                var description = ctx.RemainderOrNull().NormalizeLineEndSpacing();
                if (description.IsLongerThan(Limits.MaxDescriptionLength))
                {
                    throw Errors.DescriptionTooLongError(description.Length);
                }
                target.Description = description;

                await _data.SaveMember(target);

                await ctx.Reply($"{Emojis.Success} Member description changed.");
            }
        }
Example #3
0
        public async Task Description(Context ctx)
        {
            ctx.CheckSystem();

            if (ctx.MatchClear())
            {
                var patch = new SystemPatch {
                    Description = null
                };
                await _db.Execute(conn => conn.UpdateSystem(ctx.System.Id, patch));

                await ctx.Reply($"{Emojis.Success} System description cleared.");

                return;
            }

            var newDescription = ctx.RemainderOrNull()?.NormalizeLineEndSpacing();

            if (newDescription == null)
            {
                if (ctx.System.Description == null)
                {
                    await ctx.Reply("Your system does not have a description set. To set one, type `pk;s description <description>`.");
                }
                else if (ctx.MatchFlag("r", "raw"))
                {
                    await ctx.Reply($"```\n{ctx.System.Description}\n```");
                }
                else
                {
                    await ctx.Reply(embed : new DiscordEmbedBuilder()
                                    .WithTitle("System description")
                                    .WithDescription(ctx.System.Description)
                                    .WithFooter("To print the description with formatting, type `pk;s description -raw`. To clear it, type `pk;s description -clear`. To change it, type `pk;s description <new description>`.")
                                    .Build());
                }
            }
            else
            {
                if (newDescription.Length > Limits.MaxDescriptionLength)
                {
                    throw Errors.DescriptionTooLongError(newDescription.Length);
                }

                var patch = new SystemPatch {
                    Description = newDescription
                };
                await _db.Execute(conn => conn.UpdateSystem(ctx.System.Id, patch));

                await ctx.Reply($"{Emojis.Success} System description changed.");
            }
        }
Example #4
0
        public async Task Description(Context ctx)
        {
            ctx.CheckSystem();

            var newDescription = ctx.RemainderOrNull()?.NormalizeLineEndSpacing();

            if (newDescription != null && newDescription.Length > Limits.MaxDescriptionLength)
            {
                throw Errors.DescriptionTooLongError(newDescription.Length);
            }

            ctx.System.Description = newDescription;
            await _data.SaveSystem(ctx.System);

            await ctx.Reply($"{Emojis.Success} System description {(newDescription != null ? "changed" : "cleared")}.");
        }
Example #5
0
        public async Task Description(Context ctx, PKMember target)
        {
            if (ctx.System == null)
            {
                throw Errors.NoSystemError;
            }
            if (target.System != ctx.System.Id)
            {
                throw Errors.NotOwnMemberError;
            }

            var description = ctx.RemainderOrNull()?.NormalizeLineEndSpacing();

            if (description.IsLongerThan(Limits.MaxDescriptionLength))
            {
                throw Errors.DescriptionTooLongError(description.Length);
            }

            target.Description = description;
            await _data.SaveMember(target);

            await ctx.Reply($"{Emojis.Success} Member description {(description == null ? "cleared" : "changed")}.");
        }
Example #6
0
        public async Task Description(Context ctx, PKMember target)
        {
            if (await ctx.MatchClear("this member's description"))
            {
                ctx.CheckOwnMember(target);

                var patch = new MemberPatch {
                    Description = Partial <string> .Null()
                };
                await _db.Execute(conn => _repo.UpdateMember(conn, target.Id, patch));

                await ctx.Reply($"{Emojis.Success} Member description cleared.");
            }
            else if (!ctx.HasNext())
            {
                if (!target.DescriptionPrivacy.CanAccess(ctx.LookupContextFor(target.System)))
                {
                    throw Errors.LookupNotAllowed;
                }
                if (target.Description == null)
                {
                    if (ctx.System?.Id == target.System)
                    {
                        await ctx.Reply($"This member does not have a description set. To set one, type `pk;member {target.Reference()} description <description>`.");
                    }
                    else
                    {
                        await ctx.Reply("This member does not have a description set.");
                    }
                }
                else if (ctx.MatchFlag("r", "raw"))
                {
                    await ctx.Reply($"```\n{target.Description}\n```");
                }
                else
                {
                    await ctx.Reply(embed : new EmbedBuilder()
                                    .Title("Member description")
                                    .Description(target.Description)
                                    .Field(new("\u200B", $"To print the description with formatting, type `pk;member {target.Reference()} description -raw`."
                                               + (ctx.System?.Id == target.System ? $" To clear it, type `pk;member {target.Reference()} description -clear`." : "")))
                                    .Build());
                }
            }
            else
            {
                ctx.CheckOwnMember(target);

                var description = ctx.RemainderOrNull().NormalizeLineEndSpacing();
                if (description.IsLongerThan(Limits.MaxDescriptionLength))
                {
                    throw Errors.DescriptionTooLongError(description.Length);
                }

                var patch = new MemberPatch {
                    Description = Partial <string> .Present(description)
                };
                await _db.Execute(conn => _repo.UpdateMember(conn, target.Id, patch));

                await ctx.Reply($"{Emojis.Success} Member description changed.");
            }
        }