mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
implement rest of group and member commands
This commit is contained in:
parent
95fc7e9f60
commit
1943687c70
13 changed files with 705 additions and 443 deletions
|
|
@ -65,6 +65,9 @@ public partial class CommandTree
|
|||
Commands.MemberDelete(var param, _) => ctx.Execute<MemberEdit>(MemberDelete, m => m.Delete(ctx, param.target)),
|
||||
Commands.MemberPrivacyShow(var param, _) => ctx.Execute<MemberEdit>(MemberPrivacy, m => m.ShowPrivacy(ctx, param.target)),
|
||||
Commands.MemberPrivacyUpdate(var param, _) => ctx.Execute<MemberEdit>(MemberPrivacy, m => m.ChangePrivacy(ctx, param.target, param.member_privacy_target, param.new_privacy_level)),
|
||||
Commands.MemberGroupAdd(var param, _) => ctx.Execute<GroupMember>(MemberGroupAdd, m => m.AddRemoveGroups(ctx, param.target, param.groups, Groups.AddRemoveOperation.Add)),
|
||||
Commands.MemberGroupRemove(var param, _) => ctx.Execute<GroupMember>(MemberGroupRemove, m => m.AddRemoveGroups(ctx, param.target, param.groups, Groups.AddRemoveOperation.Remove)),
|
||||
Commands.MemberId(var param, _) => ctx.Execute<Member>(MemberId, m => m.DisplayId(ctx, param.target)),
|
||||
Commands.CfgApAccountShow => ctx.Execute<Config>(null, m => m.ViewAutoproxyAccount(ctx)),
|
||||
Commands.CfgApAccountUpdate(var param, _) => ctx.Execute<Config>(null, m => m.EditAutoproxyAccount(ctx, param.toggle)),
|
||||
Commands.CfgApTimeoutShow => ctx.Execute<Config>(null, m => m.ViewAutoproxyTimeout(ctx)),
|
||||
|
|
@ -185,6 +188,36 @@ public partial class CommandTree
|
|||
Commands.SystemSearchGroups(var param, var flags) => ctx.Execute<Groups>(GroupList, g => g.ListSystemGroups(ctx, param.target, param.query, flags)),
|
||||
Commands.GroupListGroups(var param, var flags) => ctx.Execute<Groups>(GroupList, g => g.ListSystemGroups(ctx, ctx.System, null, flags)),
|
||||
Commands.GroupSearchGroups(var param, var flags) => ctx.Execute<Groups>(GroupList, g => g.ListSystemGroups(ctx, ctx.System, param.query, flags)),
|
||||
Commands.GroupNew(var param, _) => ctx.Execute<Groups>(GroupNew, g => g.CreateGroup(ctx, param.name)),
|
||||
Commands.GroupInfo(var param, _) => ctx.Execute<Groups>(GroupInfo, g => g.ShowGroupCard(ctx, param.target)),
|
||||
Commands.GroupShowName(var param, var flags) => ctx.Execute<Groups>(GroupRename, g => g.ShowGroupDisplayName(ctx, param.target, flags.GetReplyFormat())),
|
||||
Commands.GroupClearName(var param, var flags) => ctx.Execute<Groups>(GroupRename, g => g.RenameGroup(ctx, param.target, null)),
|
||||
Commands.GroupRename(var param, _) => ctx.Execute<Groups>(GroupRename, g => g.RenameGroup(ctx, param.target, param.name)),
|
||||
Commands.GroupShowDisplayName(var param, var flags) => ctx.Execute<Groups>(GroupDisplayName, g => g.ShowGroupDisplayName(ctx, param.target, flags.GetReplyFormat())),
|
||||
Commands.GroupClearDisplayName(var param, var flags) => ctx.Execute<Groups>(GroupDisplayName, g => g.ClearGroupDisplayName(ctx, param.target)),
|
||||
Commands.GroupChangeDisplayName(var param, _) => ctx.Execute<Groups>(GroupDisplayName, g => g.ChangeGroupDisplayName(ctx, param.target, param.name)),
|
||||
Commands.GroupShowDescription(var param, var flags) => ctx.Execute<Groups>(GroupDesc, g => g.ShowGroupDescription(ctx, param.target, flags.GetReplyFormat())),
|
||||
Commands.GroupClearDescription(var param, var flags) => ctx.Execute<Groups>(GroupDesc, g => g.ClearGroupDescription(ctx, param.target)),
|
||||
Commands.GroupChangeDescription(var param, _) => ctx.Execute<Groups>(GroupDesc, g => g.ChangeGroupDescription(ctx, param.target, param.description)),
|
||||
Commands.GroupShowIcon(var param, var flags) => ctx.Execute<Groups>(GroupIcon, g => g.ShowGroupIcon(ctx, param.target, flags.GetReplyFormat())),
|
||||
Commands.GroupClearIcon(var param, var flags) => ctx.Execute<Groups>(GroupIcon, g => g.ClearGroupIcon(ctx, param.target)),
|
||||
Commands.GroupChangeIcon(var param, _) => ctx.Execute<Groups>(GroupIcon, g => g.ChangeGroupIcon(ctx, param.target, param.icon)),
|
||||
Commands.GroupShowBanner(var param, var flags) => ctx.Execute<Groups>(GroupBannerImage, g => g.ShowGroupBanner(ctx, param.target, flags.GetReplyFormat())),
|
||||
Commands.GroupClearBanner(var param, var flags) => ctx.Execute<Groups>(GroupBannerImage, g => g.ClearGroupBanner(ctx, param.target)),
|
||||
Commands.GroupChangeBanner(var param, _) => ctx.Execute<Groups>(GroupBannerImage, g => g.ChangeGroupBanner(ctx, param.target, param.banner)),
|
||||
Commands.GroupShowColor(var param, var flags) => ctx.Execute<Groups>(GroupColor, g => g.ShowGroupColor(ctx, param.target, flags.GetReplyFormat())),
|
||||
Commands.GroupClearColor(var param, var flags) => ctx.Execute<Groups>(GroupColor, g => g.ClearGroupColor(ctx, param.target)),
|
||||
Commands.GroupChangeColor(var param, _) => ctx.Execute<Groups>(GroupColor, g => g.ChangeGroupColor(ctx, param.target, param.color)),
|
||||
Commands.GroupAddMember(var param, var flags) => ctx.Execute<GroupMember>(GroupAdd, g => g.AddRemoveMembers(ctx, param.target, param.targets, Groups.AddRemoveOperation.Add, flags.all)),
|
||||
Commands.GroupRemoveMember(var param, var flags) => ctx.Execute<GroupMember>(GroupRemove, g => g.AddRemoveMembers(ctx, param.target, param.targets, Groups.AddRemoveOperation.Remove, flags.all)),
|
||||
Commands.GroupShowPrivacy(var param, _) => ctx.Execute<Groups>(GroupPrivacy, g => g.ShowGroupPrivacy(ctx, param.target)),
|
||||
Commands.GroupChangePrivacyAll(var param, _) => ctx.Execute<Groups>(GroupPrivacy, g => g.SetAllGroupPrivacy(ctx, param.target, param.level)),
|
||||
Commands.GroupChangePrivacy(var param, _) => ctx.Execute<Groups>(GroupPrivacy, g => g.SetGroupPrivacy(ctx, param.target, param.privacy, param.level)),
|
||||
Commands.GroupSetPublic(var param, _) => ctx.Execute<Groups>(GroupPrivacy, g => g.SetAllGroupPrivacy(ctx, param.target, PrivacyLevel.Public)),
|
||||
Commands.GroupSetPrivate(var param, _) => ctx.Execute<Groups>(GroupPrivacy, g => g.SetAllGroupPrivacy(ctx, param.target, PrivacyLevel.Private)),
|
||||
Commands.GroupDelete(var param, var flags) => ctx.Execute<Groups>(GroupDelete, g => g.DeleteGroup(ctx, param.target)),
|
||||
Commands.GroupId(var param, _) => ctx.Execute<Groups>(GroupId, g => g.DisplayId(ctx, param.target)),
|
||||
Commands.GroupFronterPercent(var param, var flags) => ctx.Execute<SystemFront>(GroupFrontPercent, g => g.FrontPercent(ctx, null, flags.duration, flags.fronters_only, flags.flat, param.target)),
|
||||
_ =>
|
||||
// this should only ever occur when deving if commands are not implemented...
|
||||
ctx.Reply(
|
||||
|
|
@ -428,8 +461,6 @@ public partial class CommandTree
|
|||
{
|
||||
if (ctx.Match("commands", "help"))
|
||||
await PrintCommandList(ctx, "members", MemberCommands);
|
||||
else if (await ctx.MatchMember() is PKMember target)
|
||||
await HandleMemberCommandTargeted(ctx, target);
|
||||
else if (!ctx.HasNext())
|
||||
await PrintCommandExpectedError(ctx, MemberNew, MemberInfo, MemberRename, MemberDisplayName,
|
||||
MemberServerName, MemberDesc, MemberPronouns,
|
||||
|
|
@ -438,69 +469,11 @@ public partial class CommandTree
|
|||
await ctx.Reply($"{Emojis.Error} {ctx.CreateNotFoundError("Member", ctx.PopArgument())}");
|
||||
}
|
||||
|
||||
private async Task HandleMemberCommandTargeted(Context ctx, PKMember target)
|
||||
{
|
||||
// Commands that have a member target (eg. pk;member <member> delete)
|
||||
if (ctx.Match("group", "groups", "g"))
|
||||
if (ctx.Match("add", "a"))
|
||||
await ctx.Execute<GroupMember>(MemberGroupAdd,
|
||||
m => m.AddRemoveGroups(ctx, target, Groups.AddRemoveOperation.Add));
|
||||
else if (ctx.Match("remove", "rem"))
|
||||
await ctx.Execute<GroupMember>(MemberGroupRemove,
|
||||
m => m.AddRemoveGroups(ctx, target, Groups.AddRemoveOperation.Remove));
|
||||
else if (ctx.Match("id"))
|
||||
await ctx.Execute<Member>(MemberId, m => m.DisplayId(ctx, target));
|
||||
else
|
||||
await PrintCommandNotFoundError(ctx, MemberInfo, MemberRename, MemberDisplayName, MemberServerName,
|
||||
MemberDesc, MemberPronouns, MemberColor, MemberBirthday, MemberProxy, MemberDelete, MemberAvatar,
|
||||
SystemList);
|
||||
}
|
||||
|
||||
private async Task HandleGroupCommand(Context ctx)
|
||||
{
|
||||
// Commands with no group argument
|
||||
if (ctx.Match("n", "new"))
|
||||
await ctx.Execute<Groups>(GroupNew, g => g.CreateGroup(ctx));
|
||||
else if (ctx.Match("commands", "help"))
|
||||
if (ctx.Match("commands", "help"))
|
||||
await PrintCommandList(ctx, "groups", GroupCommands);
|
||||
else if (await ctx.MatchGroup() is { } target)
|
||||
{
|
||||
// Commands with group argument
|
||||
if (ctx.Match("rename", "name", "changename", "setname", "rn"))
|
||||
await ctx.Execute<Groups>(GroupRename, g => g.RenameGroup(ctx, target));
|
||||
else if (ctx.Match("nick", "dn", "displayname", "nickname"))
|
||||
await ctx.Execute<Groups>(GroupDisplayName, g => g.GroupDisplayName(ctx, target));
|
||||
else if (ctx.Match("description", "desc", "describe", "d", "bio", "info", "text", "intro"))
|
||||
await ctx.Execute<Groups>(GroupDesc, g => g.GroupDescription(ctx, target));
|
||||
else if (ctx.Match("add", "a"))
|
||||
await ctx.Execute<GroupMember>(GroupAdd,
|
||||
g => g.AddRemoveMembers(ctx, target, Groups.AddRemoveOperation.Add));
|
||||
else if (ctx.Match("remove", "rem"))
|
||||
await ctx.Execute<GroupMember>(GroupRemove,
|
||||
g => g.AddRemoveMembers(ctx, target, Groups.AddRemoveOperation.Remove));
|
||||
else if (ctx.Match("privacy"))
|
||||
await ctx.Execute<Groups>(GroupPrivacy, g => g.GroupPrivacy(ctx, target, null));
|
||||
else if (ctx.Match("public", "pub"))
|
||||
await ctx.Execute<Groups>(GroupPrivacy, g => g.GroupPrivacy(ctx, target, PrivacyLevel.Public));
|
||||
else if (ctx.Match("private", "priv"))
|
||||
await ctx.Execute<Groups>(GroupPrivacy, g => g.GroupPrivacy(ctx, target, PrivacyLevel.Private));
|
||||
else if (ctx.Match("delete", "destroy", "erase", "yeet"))
|
||||
await ctx.Execute<Groups>(GroupDelete, g => g.DeleteGroup(ctx, target));
|
||||
else if (ctx.Match("avatar", "picture", "icon", "image", "pic", "pfp"))
|
||||
await ctx.Execute<Groups>(GroupIcon, g => g.GroupIcon(ctx, target));
|
||||
else if (ctx.Match("banner", "splash", "cover"))
|
||||
await ctx.Execute<Groups>(GroupBannerImage, g => g.GroupBannerImage(ctx, target));
|
||||
else if (ctx.Match("fp", "frontpercent", "front%", "frontbreakdown"))
|
||||
await ctx.Execute<SystemFront>(GroupFrontPercent, g => g.FrontPercent(ctx, group: target));
|
||||
else if (ctx.Match("color", "colour"))
|
||||
await ctx.Execute<Groups>(GroupColor, g => g.GroupColor(ctx, target));
|
||||
else if (ctx.Match("id"))
|
||||
await ctx.Execute<Groups>(GroupId, g => g.DisplayId(ctx, target));
|
||||
else if (!ctx.HasNext())
|
||||
await ctx.Execute<Groups>(GroupInfo, g => g.ShowGroupCard(ctx, target));
|
||||
else
|
||||
await PrintCommandNotFoundError(ctx, GroupCommandsTargeted);
|
||||
}
|
||||
else if (!ctx.HasNext())
|
||||
await PrintCommandExpectedError(ctx, GroupCommands);
|
||||
else
|
||||
|
|
|
|||
|
|
@ -127,16 +127,6 @@ public static class ContextArgumentsExt
|
|||
ctx.PopArgument();
|
||||
return (messageId, channelId);
|
||||
}
|
||||
|
||||
public static async Task<List<PKMember>> ParseMemberList(this Context ctx, SystemId? restrictToSystem)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static async Task<List<PKGroup>> ParseGroupList(this Context ctx, SystemId? restrictToSystem)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public enum ReplyFormat
|
||||
|
|
|
|||
|
|
@ -36,6 +36,14 @@ public static class ContextParametersExt
|
|||
);
|
||||
}
|
||||
|
||||
public static async Task<List<PKGroup>> ParamResolveGroups(this Context ctx, string param_name)
|
||||
{
|
||||
return await ctx.Parameters.ResolveParameter(
|
||||
ctx, param_name,
|
||||
param => (param as Parameter.GroupRefs)?.groups
|
||||
);
|
||||
}
|
||||
|
||||
public static async Task<PKSystem?> ParamResolveSystem(this Context ctx, string param_name)
|
||||
{
|
||||
return await ctx.Parameters.ResolveParameter(
|
||||
|
|
@ -52,6 +60,14 @@ public static class ContextParametersExt
|
|||
);
|
||||
}
|
||||
|
||||
public static async Task<GroupPrivacySubject?> ParamResolveGroupPrivacyTarget(this Context ctx, string param_name)
|
||||
{
|
||||
return await ctx.Parameters.ResolveParameter(
|
||||
ctx, param_name,
|
||||
param => (param as Parameter.GroupPrivacyTarget)?.target
|
||||
);
|
||||
}
|
||||
|
||||
public static async Task<SystemPrivacySubject?> ParamResolveSystemPrivacyTarget(this Context ctx, string param_name)
|
||||
{
|
||||
return await ctx.Parameters.ResolveParameter(
|
||||
|
|
|
|||
|
|
@ -11,9 +11,11 @@ public abstract record Parameter()
|
|||
public record MemberRef(PKMember member): Parameter;
|
||||
public record MemberRefs(List<PKMember> members): Parameter;
|
||||
public record GroupRef(PKGroup group): Parameter;
|
||||
public record GroupRefs(List<PKGroup> groups): Parameter;
|
||||
public record SystemRef(PKSystem system): Parameter;
|
||||
public record GuildRef(Guild guild): Parameter;
|
||||
public record MemberPrivacyTarget(MemberPrivacySubject target): Parameter;
|
||||
public record GroupPrivacyTarget(GroupPrivacySubject target): Parameter;
|
||||
public record SystemPrivacyTarget(SystemPrivacySubject target): Parameter;
|
||||
public record PrivacyLevel(Core.PrivacyLevel level): Parameter;
|
||||
public record Toggle(bool value): Parameter;
|
||||
|
|
@ -79,17 +81,30 @@ public class Parameters
|
|||
await ctx.ParseGroup(groupRef.group, byId)
|
||||
?? throw new PKError(ctx.CreateNotFoundError("Group", groupRef.group))
|
||||
);
|
||||
case uniffi.commands.Parameter.GroupRefs groupRefs:
|
||||
return new Parameter.GroupRefs(
|
||||
await groupRefs.groups.ToAsyncEnumerable().SelectAwait(async g =>
|
||||
await ctx.ParseGroup(g, byId)
|
||||
?? throw new PKError(ctx.CreateNotFoundError("Group", g, byId))
|
||||
).ToListAsync()
|
||||
);
|
||||
case uniffi.commands.Parameter.SystemRef systemRef:
|
||||
// todo: do we need byId here?
|
||||
return new Parameter.SystemRef(
|
||||
await ctx.ParseSystem(systemRef.system)
|
||||
?? throw new PKError(ctx.CreateNotFoundError("System", systemRef.system))
|
||||
);
|
||||
// todo(dusk): ideally generate enums for these from rust code in the cs glue
|
||||
case uniffi.commands.Parameter.MemberPrivacyTarget memberPrivacyTarget:
|
||||
// this should never really fail...
|
||||
if (!MemberPrivacyUtils.TryParseMemberPrivacy(memberPrivacyTarget.target, out var memberPrivacy))
|
||||
throw new PKError($"Invalid member privacy target {memberPrivacyTarget.target}");
|
||||
return new Parameter.MemberPrivacyTarget(memberPrivacy);
|
||||
case uniffi.commands.Parameter.GroupPrivacyTarget groupPrivacyTarget:
|
||||
// this should never really fail...
|
||||
if (!GroupPrivacyUtils.TryParseGroupPrivacy(groupPrivacyTarget.target, out var groupPrivacy))
|
||||
throw new PKError($"Invalid group privacy target {groupPrivacyTarget.target}");
|
||||
return new Parameter.GroupPrivacyTarget(groupPrivacy);
|
||||
case uniffi.commands.Parameter.SystemPrivacyTarget systemPrivacyTarget:
|
||||
// this should never really fail...
|
||||
if (!SystemPrivacyUtils.TryParseSystemPrivacy(systemPrivacyTarget.target, out var systemPrivacy))
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ namespace PluralKit.Bot;
|
|||
|
||||
public class GroupMember
|
||||
{
|
||||
public async Task AddRemoveGroups(Context ctx, PKMember target, Groups.AddRemoveOperation op)
|
||||
public async Task AddRemoveGroups(Context ctx, PKMember target, List<PKGroup> _groups, Groups.AddRemoveOperation op)
|
||||
{
|
||||
ctx.CheckSystem().CheckOwnMember(target);
|
||||
|
||||
var groups = (await ctx.ParseGroupList(ctx.System.Id))
|
||||
var groups = _groups.FindAll(g => g.System == ctx.System.Id)
|
||||
.Select(g => g.Id)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
|
@ -83,12 +83,12 @@ public class GroupMember
|
|||
target.Color, opts);
|
||||
}
|
||||
|
||||
public async Task AddRemoveMembers(Context ctx, PKGroup target, Groups.AddRemoveOperation op)
|
||||
public async Task AddRemoveMembers(Context ctx, PKGroup target, List<PKMember> _members, Groups.AddRemoveOperation op, bool all)
|
||||
{
|
||||
ctx.CheckOwnGroup(target);
|
||||
|
||||
List<MemberId> members;
|
||||
if (ctx.MatchFlag("all", "a"))
|
||||
if (all)
|
||||
{
|
||||
members = (await ctx.Database.Execute(conn => conn.QueryMemberList(target.System,
|
||||
new DatabaseViewsExt.ListQueryOptions { })))
|
||||
|
|
@ -98,10 +98,11 @@ public class GroupMember
|
|||
}
|
||||
else
|
||||
{
|
||||
members = (await ctx.ParseMemberList(ctx.System.Id))
|
||||
.Select(m => m.Id)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
members = _members
|
||||
.FindAll(m => m.System == ctx.System.Id)
|
||||
.Select(m => m.Id)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
var existingMembersInGroup = (await ctx.Database.Execute(conn => conn.QueryMemberList(target.System,
|
||||
|
|
@ -125,7 +126,7 @@ public class GroupMember
|
|||
.Where(m => existingMembersInGroup.Contains(m.Value))
|
||||
.ToList();
|
||||
|
||||
if (ctx.MatchFlag("all", "a") && !await ctx.PromptYesNo($"Are you sure you want to remove all members from group {target.Reference(ctx)}?", "Empty Group")) throw Errors.GenericCancelled();
|
||||
if (all && !await ctx.PromptYesNo($"Are you sure you want to remove all members from group {target.Reference(ctx)}?", "Empty Group")) throw Errors.GenericCancelled();
|
||||
|
||||
await ctx.Repository.RemoveMembersFromGroup(target.Id, toAction);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,12 +32,11 @@ public class Groups
|
|||
_avatarHosting = avatarHosting;
|
||||
}
|
||||
|
||||
public async Task CreateGroup(Context ctx)
|
||||
public async Task CreateGroup(Context ctx, string groupName)
|
||||
{
|
||||
ctx.CheckSystem();
|
||||
|
||||
// Check group name length
|
||||
var groupName = ctx.RemainderOrNull() ?? throw new PKSyntaxError("You must pass a group name.");
|
||||
if (groupName.Length > Limits.MaxGroupNameLength)
|
||||
throw new PKError($"Group name too long ({groupName.Length}/{Limits.MaxGroupNameLength} characters).");
|
||||
|
||||
|
|
@ -99,12 +98,11 @@ public class Groups
|
|||
await ctx.Reply(replyStr, eb.Build());
|
||||
}
|
||||
|
||||
public async Task RenameGroup(Context ctx, PKGroup target)
|
||||
public async Task RenameGroup(Context ctx, PKGroup target, string newName)
|
||||
{
|
||||
ctx.CheckOwnGroup(target);
|
||||
|
||||
// Check group name length
|
||||
var newName = ctx.RemainderOrNull() ?? throw new PKSyntaxError("You must pass a new group name.");
|
||||
if (newName.Length > Limits.MaxGroupNameLength)
|
||||
throw new PKError(
|
||||
$"New group name too long ({newName.Length}/{Limits.MaxMemberNameLength} characters).");
|
||||
|
|
@ -124,7 +122,7 @@ public class Groups
|
|||
await ctx.Reply($"{Emojis.Success} Group name changed from **{target.Name}** to **{newName}** (using {newName.Length}/{Limits.MaxGroupNameLength} characters).");
|
||||
}
|
||||
|
||||
public async Task GroupDisplayName(Context ctx, PKGroup target)
|
||||
public async Task ShowGroupDisplayName(Context ctx, PKGroup target, ReplyFormat format)
|
||||
{
|
||||
var noDisplayNameSetMessage = "This group does not have a display name set" +
|
||||
(ctx.System?.Id == target.System
|
||||
|
|
@ -134,8 +132,6 @@ public class Groups
|
|||
// Whether displayname is shown or not should depend on if group name privacy is set.
|
||||
// If name privacy is on then displayname should look like name.
|
||||
|
||||
var format = ctx.MatchFormat();
|
||||
|
||||
// if we're doing a raw or plaintext query check for null
|
||||
if (format != ReplyFormat.Standard)
|
||||
if (target.DisplayName == null || !target.NamePrivacy.CanAccess(ctx.DirectLookupContextFor(target.System)))
|
||||
|
|
@ -157,69 +153,62 @@ public class Groups
|
|||
return;
|
||||
}
|
||||
|
||||
if (!ctx.HasNext(false))
|
||||
{
|
||||
var showDisplayName = target.NamePrivacy.CanAccess(ctx.LookupContextFor(target.System)) && target.DisplayName != null;
|
||||
var showDisplayName = target.NamePrivacy.CanAccess(ctx.LookupContextFor(target.System)) && target.DisplayName != null;
|
||||
|
||||
var eb = new EmbedBuilder()
|
||||
.Title("Group names")
|
||||
.Field(new Embed.Field("Name", target.NameFor(ctx)))
|
||||
.Field(new Embed.Field("Display Name", showDisplayName ? target.DisplayName : "*(no displayname set or name is private)*"));
|
||||
var eb2 = new EmbedBuilder()
|
||||
.Title("Group names")
|
||||
.Field(new Embed.Field("Name", target.NameFor(ctx)))
|
||||
.Field(new Embed.Field("Display Name", showDisplayName ? target.DisplayName : "*(no displayname set or name is private)*"));
|
||||
|
||||
var reference = target.Reference(ctx);
|
||||
var reference = target.Reference(ctx);
|
||||
|
||||
if (ctx.System?.Id == target.System)
|
||||
eb.Description(
|
||||
$"To change display name, type `{ctx.DefaultPrefix}group {reference} displayname <display name>`.\n"
|
||||
+ $"To clear it, type `{ctx.DefaultPrefix}group {reference} displayname -clear`.\n"
|
||||
+ $"To print the raw display name, type `{ctx.DefaultPrefix}group {reference} displayname -raw`.");
|
||||
if (ctx.System?.Id == target.System)
|
||||
eb2.Description(
|
||||
$"To change display name, type `{ctx.DefaultPrefix}group {reference} displayname <display name>`.\n"
|
||||
+ $"To clear it, type `{ctx.DefaultPrefix}group {reference} displayname -clear`.\n"
|
||||
+ $"To print the raw display name, type `{ctx.DefaultPrefix}group {reference} displayname -raw`.");
|
||||
|
||||
if (ctx.System?.Id == target.System && showDisplayName)
|
||||
eb.Footer(new Embed.EmbedFooter($"Using {target.DisplayName.Length}/{Limits.MaxGroupNameLength} characters."));
|
||||
if (ctx.System?.Id == target.System && showDisplayName)
|
||||
eb2.Footer(new Embed.EmbedFooter($"Using {target.DisplayName.Length}/{Limits.MaxGroupNameLength} characters."));
|
||||
|
||||
await ctx.Reply(embed: eb.Build());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.CheckOwnGroup(target);
|
||||
|
||||
if (ctx.MatchClear() && await ctx.ConfirmClear("this group's display name"))
|
||||
{
|
||||
var patch = new GroupPatch { DisplayName = Partial<string>.Null() };
|
||||
await ctx.Repository.UpdateGroup(target.Id, patch);
|
||||
|
||||
var replyStr = $"{Emojis.Success} Group display name cleared.";
|
||||
if (target.NamePrivacy == PrivacyLevel.Private)
|
||||
replyStr += $"\n{Emojis.Warn} Since this group no longer has a display name set, their name privacy **can no longer take effect**.";
|
||||
await ctx.Reply(replyStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
var newDisplayName = ctx.RemainderOrNull(false).NormalizeLineEndSpacing();
|
||||
if (newDisplayName.Length > Limits.MaxGroupNameLength)
|
||||
throw new PKError($"Group name too long ({newDisplayName.Length}/{Limits.MaxGroupNameLength} characters).");
|
||||
|
||||
var patch = new GroupPatch { DisplayName = Partial<string>.Present(newDisplayName) };
|
||||
await ctx.Repository.UpdateGroup(target.Id, patch);
|
||||
|
||||
await ctx.Reply($"{Emojis.Success} Group display name changed (using {newDisplayName.Length}/{Limits.MaxGroupNameLength} characters).");
|
||||
}
|
||||
await ctx.Reply(embed: eb2.Build());
|
||||
}
|
||||
|
||||
public async Task GroupDescription(Context ctx, PKGroup target)
|
||||
public async Task ClearGroupDisplayName(Context ctx, PKGroup target)
|
||||
{
|
||||
ctx.CheckSystemPrivacy(target.System, target.DescriptionPrivacy);
|
||||
ctx.CheckOwnGroup(target);
|
||||
|
||||
var noDescriptionSetMessage = "This group does not have a description set.";
|
||||
if (ctx.System?.Id == target.System)
|
||||
noDescriptionSetMessage +=
|
||||
$" To set one, type `{ctx.DefaultPrefix}group {target.Reference(ctx)} description <description>`.";
|
||||
var patch = new GroupPatch { DisplayName = Partial<string>.Null() };
|
||||
await ctx.Repository.UpdateGroup(target.Id, patch);
|
||||
|
||||
var format = ctx.MatchFormat();
|
||||
var replyStr = $"{Emojis.Success} Group display name cleared.";
|
||||
if (target.NamePrivacy == PrivacyLevel.Private)
|
||||
replyStr += $"\n{Emojis.Warn} Since this group no longer has a display name set, their name privacy **can no longer take effect**.";
|
||||
await ctx.Reply(replyStr);
|
||||
}
|
||||
|
||||
// if there's nothing next or what's next is "raw"/"plaintext" we're doing a query, so check for null
|
||||
if (!ctx.HasNext(false) || format != ReplyFormat.Standard)
|
||||
public async Task ChangeGroupDisplayName(Context ctx, PKGroup target, string newDisplayName)
|
||||
{
|
||||
ctx.CheckOwnGroup(target);
|
||||
|
||||
if (newDisplayName.Length > Limits.MaxGroupNameLength)
|
||||
throw new PKError($"Group name too long ({newDisplayName.Length}/{Limits.MaxGroupNameLength} characters).");
|
||||
|
||||
var patch = new GroupPatch { DisplayName = Partial<string>.Present(newDisplayName) };
|
||||
await ctx.Repository.UpdateGroup(target.Id, patch);
|
||||
|
||||
await ctx.Reply($"{Emojis.Success} Group display name changed (using {newDisplayName.Length}/{Limits.MaxGroupNameLength} characters).");
|
||||
}
|
||||
|
||||
public async Task ShowGroupDescription(Context ctx, PKGroup target, ReplyFormat format)
|
||||
{
|
||||
var noDescriptionSetMessage = "This group does not have a description set" +
|
||||
(ctx.System?.Id == target.System
|
||||
? $". To set one, type `{ctx.DefaultPrefix}group {target.Reference(ctx)} description <description>`."
|
||||
: ".");
|
||||
|
||||
// if we're doing a raw or plaintext query check for null
|
||||
if (format != ReplyFormat.Standard)
|
||||
if (target.Description == null)
|
||||
{
|
||||
await ctx.Reply(noDescriptionSetMessage);
|
||||
|
|
@ -239,243 +228,282 @@ public class Groups
|
|||
return;
|
||||
}
|
||||
|
||||
if (!ctx.HasNext(false))
|
||||
if (target.Description == null)
|
||||
{
|
||||
await ctx.Reply(embed: new EmbedBuilder()
|
||||
.Title("Group description")
|
||||
.Description(target.Description)
|
||||
.Field(new Embed.Field("\u200B",
|
||||
$"To print the description with formatting, type `{ctx.DefaultPrefix}group {target.Reference(ctx)} description -raw`."
|
||||
+ (ctx.System?.Id == target.System
|
||||
? $" To clear it, type `{ctx.DefaultPrefix}group {target.Reference(ctx)} description -clear`."
|
||||
: "")
|
||||
+ $" Using {target.Description.Length}/{Limits.MaxDescriptionLength} characters."))
|
||||
.Build());
|
||||
await ctx.Reply(noDescriptionSetMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
var eb2 = new EmbedBuilder()
|
||||
.Title("Group description")
|
||||
.Description(target.Description);
|
||||
|
||||
var reference = target.Reference(ctx);
|
||||
|
||||
if (ctx.System?.Id == target.System)
|
||||
eb2.Field(new Embed.Field("\u200B",
|
||||
$"To print the description with formatting, type `{ctx.DefaultPrefix}group {reference} description -raw`."
|
||||
+ $" To clear it, type `{ctx.DefaultPrefix}group {reference} description -clear`."
|
||||
+ $" Using {target.Description.Length}/{Limits.MaxDescriptionLength} characters."));
|
||||
else
|
||||
eb2.Field(new Embed.Field("\u200B",
|
||||
$"To print the description with formatting, type `{ctx.DefaultPrefix}group {reference} description -raw`."
|
||||
+ $" Using {target.Description.Length}/{Limits.MaxDescriptionLength} characters."));
|
||||
|
||||
await ctx.Reply(embed: eb2.Build());
|
||||
}
|
||||
|
||||
public async Task ClearGroupDescription(Context ctx, PKGroup target)
|
||||
{
|
||||
ctx.CheckOwnGroup(target);
|
||||
|
||||
if (ctx.MatchClear() && await ctx.ConfirmClear("this group's description"))
|
||||
{
|
||||
var patch = new GroupPatch { Description = Partial<string>.Null() };
|
||||
await ctx.Repository.UpdateGroup(target.Id, patch);
|
||||
await ctx.Reply($"{Emojis.Success} Group description cleared.");
|
||||
}
|
||||
else
|
||||
{
|
||||
var description = ctx.RemainderOrNull(false).NormalizeLineEndSpacing();
|
||||
if (description.IsLongerThan(Limits.MaxDescriptionLength))
|
||||
throw Errors.StringTooLongError("Description", description.Length, Limits.MaxDescriptionLength);
|
||||
var patch = new GroupPatch { Description = Partial<string>.Null() };
|
||||
await ctx.Repository.UpdateGroup(target.Id, patch);
|
||||
|
||||
var patch = new GroupPatch { Description = Partial<string>.Present(description) };
|
||||
await ctx.Repository.UpdateGroup(target.Id, patch);
|
||||
|
||||
await ctx.Reply($"{Emojis.Success} Group description changed (using {description.Length}/{Limits.MaxDescriptionLength} characters).");
|
||||
}
|
||||
await ctx.Reply($"{Emojis.Success} Group description cleared.");
|
||||
}
|
||||
|
||||
public async Task GroupIcon(Context ctx, PKGroup target)
|
||||
public async Task ChangeGroupDescription(Context ctx, PKGroup target, string newDescription)
|
||||
{
|
||||
async Task ClearIcon()
|
||||
{
|
||||
await ctx.ConfirmClear("this group's icon");
|
||||
ctx.CheckOwnGroup(target);
|
||||
ctx.CheckOwnGroup(target);
|
||||
|
||||
await ctx.Repository.UpdateGroup(target.Id, new GroupPatch { Icon = null });
|
||||
await ctx.Reply($"{Emojis.Success} Group icon cleared.");
|
||||
}
|
||||
if (newDescription.IsLongerThan(Limits.MaxDescriptionLength))
|
||||
throw Errors.StringTooLongError("Description", newDescription.Length, Limits.MaxDescriptionLength);
|
||||
|
||||
async Task SetIcon(ParsedImage img)
|
||||
{
|
||||
ctx.CheckOwnGroup(target);
|
||||
var patch = new GroupPatch { Description = Partial<string>.Present(newDescription) };
|
||||
await ctx.Repository.UpdateGroup(target.Id, patch);
|
||||
|
||||
img = await _avatarHosting.TryRehostImage(img, AvatarHostingService.RehostedImageType.Avatar, ctx.Author.Id, ctx.System);
|
||||
await _avatarHosting.VerifyAvatarOrThrow(img.Url);
|
||||
await ctx.Reply($"{Emojis.Success} Group description changed (using {newDescription.Length}/{Limits.MaxDescriptionLength} characters).");
|
||||
}
|
||||
|
||||
await ctx.Repository.UpdateGroup(target.Id, new GroupPatch { Icon = img.CleanUrl ?? img.Url });
|
||||
public async Task ShowGroupIcon(Context ctx, PKGroup target, ReplyFormat format)
|
||||
{
|
||||
var noIconSetMessage = "This group does not have an avatar set" +
|
||||
(ctx.System?.Id == target.System
|
||||
? ". Set one by attaching an image to this command, or by passing an image URL or @mention."
|
||||
: ".");
|
||||
|
||||
var msg = img.Source switch
|
||||
ctx.CheckSystemPrivacy(target.System, target.IconPrivacy);
|
||||
|
||||
// if we're doing a raw or plaintext query check for null
|
||||
if (format != ReplyFormat.Standard)
|
||||
if ((target.Icon?.Trim() ?? "").Length == 0)
|
||||
{
|
||||
AvatarSource.User =>
|
||||
$"{Emojis.Success} Group icon changed to {img.SourceUser?.Username}'s avatar!\n{Emojis.Warn} If {img.SourceUser?.Username} changes their avatar, the group icon will need to be re-set.",
|
||||
AvatarSource.Url => $"{Emojis.Success} Group icon changed to the image at the given URL.",
|
||||
AvatarSource.HostedCdn => $"{Emojis.Success} Group icon changed to attached image.",
|
||||
AvatarSource.Attachment =>
|
||||
$"{Emojis.Success} Group icon changed to attached image.\n{Emojis.Warn} If you delete the message containing the attachment, the group icon will stop working.",
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
await ctx.Reply(noIconSetMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
// The attachment's already right there, no need to preview it.
|
||||
var hasEmbed = img.Source != AvatarSource.Attachment && img.Source != AvatarSource.HostedCdn;
|
||||
await (hasEmbed
|
||||
? ctx.Reply(msg, new EmbedBuilder().Image(new Embed.EmbedImage(img.Url)).Build())
|
||||
: ctx.Reply(msg));
|
||||
}
|
||||
|
||||
async Task ShowIcon()
|
||||
if (format == ReplyFormat.Raw)
|
||||
{
|
||||
ctx.CheckSystemPrivacy(target.System, target.IconPrivacy);
|
||||
|
||||
if ((target.Icon?.Trim() ?? "").Length > 0)
|
||||
switch (ctx.MatchFormat())
|
||||
{
|
||||
case ReplyFormat.Raw:
|
||||
await ctx.Reply($"`{target.Icon.TryGetCleanCdnUrl()}`");
|
||||
break;
|
||||
case ReplyFormat.Plaintext:
|
||||
var ebP = new EmbedBuilder()
|
||||
.Description($"Showing avatar for group {target.NameFor(ctx)} (`{target.DisplayHid(ctx.Config)}`)");
|
||||
await ctx.Reply(text: $"<{target.Icon.TryGetCleanCdnUrl()}>", embed: ebP.Build());
|
||||
break;
|
||||
default:
|
||||
var ebS = new EmbedBuilder()
|
||||
.Title("Group icon")
|
||||
.Image(new Embed.EmbedImage(target.Icon.TryGetCleanCdnUrl()));
|
||||
if (target.System == ctx.System?.Id)
|
||||
ebS.Description($"To clear, use `{ctx.DefaultPrefix}group {target.Reference(ctx)} icon -clear`.");
|
||||
await ctx.Reply(embed: ebS.Build());
|
||||
break;
|
||||
}
|
||||
else
|
||||
throw new PKSyntaxError(
|
||||
"This group does not have an avatar set. Set one by attaching an image to this command, or by passing an image URL or @mention.");
|
||||
await ctx.Reply($"`{target.Icon.TryGetCleanCdnUrl()}`");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx.MatchClear())
|
||||
await ClearIcon();
|
||||
else if (await ctx.MatchImage() is { } img)
|
||||
await SetIcon(img);
|
||||
else
|
||||
await ShowIcon();
|
||||
}
|
||||
|
||||
public async Task GroupBannerImage(Context ctx, PKGroup target)
|
||||
{
|
||||
async Task ClearBannerImage()
|
||||
if (format == ReplyFormat.Plaintext)
|
||||
{
|
||||
ctx.CheckOwnGroup(target);
|
||||
await ctx.ConfirmClear("this group's banner image");
|
||||
|
||||
await ctx.Repository.UpdateGroup(target.Id, new GroupPatch { BannerImage = null });
|
||||
await ctx.Reply($"{Emojis.Success} Group banner image cleared.");
|
||||
}
|
||||
|
||||
async Task SetBannerImage(ParsedImage img)
|
||||
{
|
||||
ctx.CheckOwnGroup(target);
|
||||
|
||||
img = await _avatarHosting.TryRehostImage(img, AvatarHostingService.RehostedImageType.Banner, ctx.Author.Id, ctx.System);
|
||||
await _avatarHosting.VerifyAvatarOrThrow(img.Url, true);
|
||||
|
||||
await ctx.Repository.UpdateGroup(target.Id, new GroupPatch { BannerImage = img.CleanUrl ?? img.Url });
|
||||
|
||||
var msg = img.Source switch
|
||||
{
|
||||
AvatarSource.Url => $"{Emojis.Success} Group banner image changed to the image at the given URL.",
|
||||
AvatarSource.HostedCdn => $"{Emojis.Success} Group banner image changed to attached image.",
|
||||
AvatarSource.Attachment =>
|
||||
$"{Emojis.Success} Group banner image changed to attached image.\n{Emojis.Warn} If you delete the message containing the attachment, the banner image will stop working.",
|
||||
AvatarSource.User => throw new PKError("Cannot set a banner image to an user's avatar."),
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
|
||||
// The attachment's already right there, no need to preview it.
|
||||
var hasEmbed = img.Source != AvatarSource.Attachment && img.Source != AvatarSource.HostedCdn;
|
||||
await (hasEmbed
|
||||
? ctx.Reply(msg, new EmbedBuilder().Image(new Embed.EmbedImage(img.Url)).Build())
|
||||
: ctx.Reply(msg));
|
||||
}
|
||||
|
||||
async Task ShowBannerImage()
|
||||
{
|
||||
ctx.CheckSystemPrivacy(target.System, target.BannerPrivacy);
|
||||
|
||||
if ((target.BannerImage?.Trim() ?? "").Length > 0)
|
||||
switch (ctx.MatchFormat())
|
||||
{
|
||||
case ReplyFormat.Raw:
|
||||
await ctx.Reply($"`{target.BannerImage.TryGetCleanCdnUrl()}`");
|
||||
break;
|
||||
case ReplyFormat.Plaintext:
|
||||
var ebP = new EmbedBuilder()
|
||||
.Description($"Showing banner for group {target.NameFor(ctx)} (`{target.DisplayHid(ctx.Config)}`)");
|
||||
await ctx.Reply(text: $"<{target.BannerImage.TryGetCleanCdnUrl()}>", embed: ebP.Build());
|
||||
break;
|
||||
default:
|
||||
var ebS = new EmbedBuilder()
|
||||
.Title("Group banner image")
|
||||
.Image(new Embed.EmbedImage(target.BannerImage.TryGetCleanCdnUrl()));
|
||||
if (target.System == ctx.System?.Id)
|
||||
ebS.Description($"To clear, use `{ctx.DefaultPrefix}group {target.Reference(ctx)} banner clear`.");
|
||||
await ctx.Reply(embed: ebS.Build());
|
||||
break;
|
||||
}
|
||||
else
|
||||
throw new PKSyntaxError(
|
||||
"This group does not have a banner image set. Set one by attaching an image to this command, or by passing an image URL or @mention.");
|
||||
}
|
||||
|
||||
if (ctx.MatchClear())
|
||||
await ClearBannerImage();
|
||||
else if (await ctx.MatchImage() is { } img)
|
||||
await SetBannerImage(img);
|
||||
else
|
||||
await ShowBannerImage();
|
||||
}
|
||||
|
||||
public async Task GroupColor(Context ctx, PKGroup target)
|
||||
{
|
||||
var isOwnSystem = ctx.System?.Id == target.System;
|
||||
var matchedFormat = ctx.MatchFormat();
|
||||
var matchedClear = ctx.MatchClear();
|
||||
|
||||
if (!isOwnSystem || !(ctx.HasNext() || matchedClear))
|
||||
{
|
||||
if (target.Color == null)
|
||||
await ctx.Reply(
|
||||
"This group does not have a color set." + (isOwnSystem ? $" To set one, type `{ctx.DefaultPrefix}group {target.Reference(ctx)} color <color>`." : ""));
|
||||
else if (matchedFormat == ReplyFormat.Raw)
|
||||
await ctx.Reply("```\n#" + target.Color + "\n```");
|
||||
else if (matchedFormat == ReplyFormat.Plaintext)
|
||||
await ctx.Reply(target.Color);
|
||||
else
|
||||
await ctx.Reply(embed: new EmbedBuilder()
|
||||
.Title("Group color")
|
||||
.Color(target.Color.ToDiscordColor())
|
||||
.Thumbnail(new Embed.EmbedThumbnail($"attachment://color.gif"))
|
||||
.Description($"This group's color is **#{target.Color}**."
|
||||
+ (isOwnSystem ? $" To clear it, type `{ctx.DefaultPrefix}group {target.Reference(ctx)} color -clear`." : ""))
|
||||
.Build(),
|
||||
files: [MiscUtils.GenerateColorPreview(target.Color)]);
|
||||
var ebP = new EmbedBuilder()
|
||||
.Description($"Showing avatar for group {target.NameFor(ctx)} (`{target.DisplayHid(ctx.Config)}`)");
|
||||
await ctx.Reply(text: $"<{target.Icon.TryGetCleanCdnUrl()}>", embed: ebP.Build());
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.CheckSystem().CheckOwnGroup(target);
|
||||
|
||||
if (matchedClear)
|
||||
if ((target.Icon?.Trim() ?? "").Length == 0)
|
||||
{
|
||||
await ctx.Repository.UpdateGroup(target.Id, new() { Color = Partial<string>.Null() });
|
||||
|
||||
await ctx.Reply($"{Emojis.Success} Group color cleared.");
|
||||
await ctx.Reply(noIconSetMessage);
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
||||
var ebS = new EmbedBuilder()
|
||||
.Title("Group icon")
|
||||
.Image(new Embed.EmbedImage(target.Icon.TryGetCleanCdnUrl()));
|
||||
if (target.System == ctx.System?.Id)
|
||||
ebS.Description($"To clear, use `{ctx.DefaultPrefix}group {target.Reference(ctx)} icon -clear`.");
|
||||
await ctx.Reply(embed: ebS.Build());
|
||||
}
|
||||
|
||||
public async Task ClearGroupIcon(Context ctx, PKGroup target)
|
||||
{
|
||||
ctx.CheckOwnGroup(target);
|
||||
await ctx.ConfirmClear("this group's icon");
|
||||
|
||||
await ctx.Repository.UpdateGroup(target.Id, new GroupPatch { Icon = null });
|
||||
await ctx.Reply($"{Emojis.Success} Group icon cleared.");
|
||||
}
|
||||
|
||||
public async Task ChangeGroupIcon(Context ctx, PKGroup target, ParsedImage img)
|
||||
{
|
||||
ctx.CheckOwnGroup(target);
|
||||
|
||||
img = await _avatarHosting.TryRehostImage(img, AvatarHostingService.RehostedImageType.Avatar, ctx.Author.Id, ctx.System);
|
||||
await _avatarHosting.VerifyAvatarOrThrow(img.Url);
|
||||
|
||||
await ctx.Repository.UpdateGroup(target.Id, new GroupPatch { Icon = img.CleanUrl ?? img.Url });
|
||||
|
||||
var msg = img.Source switch
|
||||
{
|
||||
var color = ctx.RemainderOrNull();
|
||||
AvatarSource.User =>
|
||||
$"{Emojis.Success} Group icon changed to {img.SourceUser?.Username}'s avatar!\n{Emojis.Warn} If {img.SourceUser?.Username} changes their avatar, the group icon will need to be re-set.",
|
||||
AvatarSource.Url => $"{Emojis.Success} Group icon changed to the image at the given URL.",
|
||||
AvatarSource.HostedCdn => $"{Emojis.Success} Group icon changed to attached image.",
|
||||
AvatarSource.Attachment =>
|
||||
$"{Emojis.Success} Group icon changed to attached image.\n{Emojis.Warn} If you delete the message containing the attachment, the group icon will stop working.",
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
|
||||
if (color.StartsWith("#")) color = color.Substring(1);
|
||||
if (!Regex.IsMatch(color, "^[0-9a-fA-F]{6}$")) throw Errors.InvalidColorError(color);
|
||||
// The attachment's already right there, no need to preview it.
|
||||
var hasEmbed = img.Source != AvatarSource.Attachment && img.Source != AvatarSource.HostedCdn;
|
||||
await (hasEmbed
|
||||
? ctx.Reply(msg, new EmbedBuilder().Image(new Embed.EmbedImage(img.Url)).Build())
|
||||
: ctx.Reply(msg));
|
||||
}
|
||||
|
||||
var patch = new GroupPatch { Color = Partial<string>.Present(color.ToLowerInvariant()) };
|
||||
await ctx.Repository.UpdateGroup(target.Id, patch);
|
||||
public async Task ShowGroupBanner(Context ctx, PKGroup target, ReplyFormat format)
|
||||
{
|
||||
var noBannerSetMessage = "This group does not have a banner image set" +
|
||||
(ctx.System?.Id == target.System
|
||||
? ". Set one by attaching an image to this command, or by passing an image URL or @mention."
|
||||
: ".");
|
||||
|
||||
await ctx.Reply(embed: new EmbedBuilder()
|
||||
.Title($"{Emojis.Success} Group color changed.")
|
||||
.Color(color.ToDiscordColor())
|
||||
.Thumbnail(new Embed.EmbedThumbnail($"attachment://color.gif"))
|
||||
.Build(),
|
||||
files: [MiscUtils.GenerateColorPreview(color)]);
|
||||
ctx.CheckSystemPrivacy(target.System, target.BannerPrivacy);
|
||||
|
||||
// if we're doing a raw or plaintext query check for null
|
||||
if (format != ReplyFormat.Standard)
|
||||
if ((target.BannerImage?.Trim() ?? "").Length == 0)
|
||||
{
|
||||
await ctx.Reply(noBannerSetMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
if (format == ReplyFormat.Raw)
|
||||
{
|
||||
await ctx.Reply($"`{target.BannerImage.TryGetCleanCdnUrl()}`");
|
||||
return;
|
||||
}
|
||||
if (format == ReplyFormat.Plaintext)
|
||||
{
|
||||
var ebP = new EmbedBuilder()
|
||||
.Description($"Showing banner for group {target.NameFor(ctx)} (`{target.DisplayHid(ctx.Config)}`)");
|
||||
await ctx.Reply(text: $"<{target.BannerImage.TryGetCleanCdnUrl()}>", embed: ebP.Build());
|
||||
return;
|
||||
}
|
||||
|
||||
if ((target.BannerImage?.Trim() ?? "").Length == 0)
|
||||
{
|
||||
await ctx.Reply(noBannerSetMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
var ebS = new EmbedBuilder()
|
||||
.Title("Group banner image")
|
||||
.Image(new Embed.EmbedImage(target.BannerImage.TryGetCleanCdnUrl()));
|
||||
if (target.System == ctx.System?.Id)
|
||||
ebS.Description($"To clear, use `{ctx.DefaultPrefix}group {target.Reference(ctx)} banner clear`.");
|
||||
await ctx.Reply(embed: ebS.Build());
|
||||
}
|
||||
|
||||
public async Task ClearGroupBanner(Context ctx, PKGroup target)
|
||||
{
|
||||
ctx.CheckOwnGroup(target);
|
||||
await ctx.ConfirmClear("this group's banner image");
|
||||
|
||||
await ctx.Repository.UpdateGroup(target.Id, new GroupPatch { BannerImage = null });
|
||||
await ctx.Reply($"{Emojis.Success} Group banner image cleared.");
|
||||
}
|
||||
|
||||
public async Task ChangeGroupBanner(Context ctx, PKGroup target, ParsedImage img)
|
||||
{
|
||||
ctx.CheckOwnGroup(target);
|
||||
|
||||
img = await _avatarHosting.TryRehostImage(img, AvatarHostingService.RehostedImageType.Banner, ctx.Author.Id, ctx.System);
|
||||
await _avatarHosting.VerifyAvatarOrThrow(img.Url, true);
|
||||
|
||||
await ctx.Repository.UpdateGroup(target.Id, new GroupPatch { BannerImage = img.CleanUrl ?? img.Url });
|
||||
|
||||
var msg = img.Source switch
|
||||
{
|
||||
AvatarSource.Url => $"{Emojis.Success} Group banner image changed to the image at the given URL.",
|
||||
AvatarSource.HostedCdn => $"{Emojis.Success} Group banner image changed to attached image.",
|
||||
AvatarSource.Attachment =>
|
||||
$"{Emojis.Success} Group banner image changed to attached image.\n{Emojis.Warn} If you delete the message containing the attachment, the banner image will stop working.",
|
||||
AvatarSource.User => throw new PKError("Cannot set a banner image to an user's avatar."),
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
|
||||
// The attachment's already right there, no need to preview it.
|
||||
var hasEmbed = img.Source != AvatarSource.Attachment && img.Source != AvatarSource.HostedCdn;
|
||||
await (hasEmbed
|
||||
? ctx.Reply(msg, new EmbedBuilder().Image(new Embed.EmbedImage(img.Url)).Build())
|
||||
: ctx.Reply(msg));
|
||||
}
|
||||
|
||||
public async Task ShowGroupColor(Context ctx, PKGroup target, ReplyFormat format)
|
||||
{
|
||||
var noColorSetMessage = "This group does not have a color set" +
|
||||
(ctx.System?.Id == target.System
|
||||
? $". To set one, type `{ctx.DefaultPrefix}group {target.Reference(ctx)} color <color>`."
|
||||
: ".");
|
||||
|
||||
// if we're doing a raw or plaintext query check for null
|
||||
if (format != ReplyFormat.Standard)
|
||||
if (target.Color == null)
|
||||
{
|
||||
await ctx.Reply(noColorSetMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
if (format == ReplyFormat.Raw)
|
||||
{
|
||||
await ctx.Reply("```\n#" + target.Color + "\n```");
|
||||
return;
|
||||
}
|
||||
if (format == ReplyFormat.Plaintext)
|
||||
{
|
||||
await ctx.Reply(target.Color);
|
||||
return;
|
||||
}
|
||||
|
||||
if (target.Color == null)
|
||||
{
|
||||
await ctx.Reply(noColorSetMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
var eb = new EmbedBuilder()
|
||||
.Title("Group color")
|
||||
.Color(target.Color.ToDiscordColor())
|
||||
.Thumbnail(new Embed.EmbedThumbnail($"attachment://color.gif"))
|
||||
.Description($"This group's color is **#{target.Color}**.");
|
||||
|
||||
if (ctx.System?.Id == target.System)
|
||||
eb.Description(eb.Build().Description + $" To clear it, type `{ctx.DefaultPrefix}group {target.Reference(ctx)} color -clear`.");
|
||||
|
||||
await ctx.Reply(embed: eb.Build(), files: [MiscUtils.GenerateColorPreview(target.Color)]);
|
||||
}
|
||||
|
||||
public async Task ClearGroupColor(Context ctx, PKGroup target)
|
||||
{
|
||||
ctx.CheckOwnGroup(target);
|
||||
|
||||
await ctx.Repository.UpdateGroup(target.Id, new GroupPatch { Color = Partial<string>.Null() });
|
||||
|
||||
await ctx.Reply($"{Emojis.Success} Group color cleared.");
|
||||
}
|
||||
|
||||
public async Task ChangeGroupColor(Context ctx, PKGroup target, string color)
|
||||
{
|
||||
ctx.CheckOwnGroup(target);
|
||||
|
||||
if (color.StartsWith("#")) color = color.Substring(1);
|
||||
if (!Regex.IsMatch(color, "^[0-9a-fA-F]{6}$")) throw Errors.InvalidColorError(color);
|
||||
|
||||
var patch = new GroupPatch { Color = Partial<string>.Present(color.ToLowerInvariant()) };
|
||||
await ctx.Repository.UpdateGroup(target.Id, patch);
|
||||
|
||||
await ctx.Reply(embed: new EmbedBuilder()
|
||||
.Title($"{Emojis.Success} Group color changed.")
|
||||
.Color(color.ToDiscordColor())
|
||||
.Thumbnail(new Embed.EmbedThumbnail($"attachment://color.gif"))
|
||||
.Build(),
|
||||
files: [MiscUtils.GenerateColorPreview(color)]);
|
||||
}
|
||||
|
||||
public async Task ListSystemGroups(Context ctx, PKSystem system, string? query, IHasListOptions flags)
|
||||
|
|
@ -531,102 +559,97 @@ public class Groups
|
|||
await ctx.Reply(components: await _embeds.CreateGroupMessageComponents(ctx, system, target));
|
||||
}
|
||||
|
||||
public async Task GroupPrivacy(Context ctx, PKGroup target, PrivacyLevel? newValueFromCommand)
|
||||
public async Task ShowGroupPrivacy(Context ctx, PKGroup target)
|
||||
{
|
||||
ctx.CheckSystem().CheckOwnGroup(target);
|
||||
// Display privacy settings
|
||||
if (!ctx.HasNext() && newValueFromCommand == null)
|
||||
{
|
||||
await ctx.Reply(embed: new EmbedBuilder()
|
||||
.Title($"Current privacy settings for {target.Name}")
|
||||
.Field(new Embed.Field("Name", target.NamePrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Description", target.DescriptionPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Banner", target.BannerPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Icon", target.IconPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Member list", target.ListPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Metadata (creation date)", target.MetadataPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Visibility", target.Visibility.Explanation()))
|
||||
.Description(
|
||||
$"To edit privacy settings, use the command:\n> {ctx.DefaultPrefix}group **{target.Reference(ctx)}** privacy **<subject>** **<level>**\n\n- `subject` is one of `name`, `description`, `banner`, `icon`, `members`, `metadata`, `visibility`, or `all`\n- `level` is either `public` or `private`.")
|
||||
.Build());
|
||||
return;
|
||||
}
|
||||
|
||||
async Task SetAll(PrivacyLevel level)
|
||||
{
|
||||
await ctx.Repository.UpdateGroup(target.Id, new GroupPatch().WithAllPrivacy(level));
|
||||
await ctx.Reply(embed: new EmbedBuilder()
|
||||
.Title($"Current privacy settings for {target.Name}")
|
||||
.Field(new Embed.Field("Name", target.NamePrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Description", target.DescriptionPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Banner", target.BannerPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Icon", target.IconPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Member list", target.ListPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Metadata (creation date)", target.MetadataPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Visibility", target.Visibility.Explanation()))
|
||||
.Description(
|
||||
$"To edit privacy settings, use the command:\n> {ctx.DefaultPrefix}group **{target.Reference(ctx)}** privacy **<subject>** **<level>**\n\n- `subject` is one of `name`, `description`, `banner`, `icon`, `members`, `metadata`, `visibility`, or `all`\n- `level` is either `public` or `private`.")
|
||||
.Build());
|
||||
}
|
||||
|
||||
if (level == PrivacyLevel.Private)
|
||||
await ctx.Reply(
|
||||
$"{Emojis.Success} All {target.Name}'s privacy settings have been set to **{level.LevelName()}**. Other accounts will now see nothing on the group card.");
|
||||
else
|
||||
await ctx.Reply(
|
||||
$"{Emojis.Success} All {target.Name}'s privacy settings have been set to **{level.LevelName()}**. Other accounts will now see everything on the group card.");
|
||||
}
|
||||
public async Task SetAllGroupPrivacy(Context ctx, PKGroup target, PrivacyLevel level)
|
||||
{
|
||||
ctx.CheckOwnGroup(target);
|
||||
|
||||
async Task SetLevel(GroupPrivacySubject subject, PrivacyLevel level)
|
||||
{
|
||||
await ctx.Repository.UpdateGroup(target.Id, new GroupPatch().WithPrivacy(subject, level));
|
||||
await ctx.Repository.UpdateGroup(target.Id, new GroupPatch().WithAllPrivacy(level));
|
||||
|
||||
var subjectName = subject switch
|
||||
{
|
||||
GroupPrivacySubject.Name => "name privacy",
|
||||
GroupPrivacySubject.Description => "description privacy",
|
||||
GroupPrivacySubject.Banner => "banner privacy",
|
||||
GroupPrivacySubject.Icon => "icon privacy",
|
||||
GroupPrivacySubject.List => "member list",
|
||||
GroupPrivacySubject.Metadata => "metadata",
|
||||
GroupPrivacySubject.Visibility => "visibility",
|
||||
_ => throw new ArgumentOutOfRangeException($"Unknown privacy subject {subject}")
|
||||
};
|
||||
|
||||
var explanation = (subject, level) switch
|
||||
{
|
||||
(GroupPrivacySubject.Name, PrivacyLevel.Private) =>
|
||||
"This group's name is now hidden from other systems, and will be replaced by the group's display name.",
|
||||
(GroupPrivacySubject.Description, PrivacyLevel.Private) =>
|
||||
"This group's description is now hidden from other systems.",
|
||||
(GroupPrivacySubject.Banner, PrivacyLevel.Private) =>
|
||||
"This group's banner is now hidden from other systems.",
|
||||
(GroupPrivacySubject.Icon, PrivacyLevel.Private) =>
|
||||
"This group's icon is now hidden from other systems.",
|
||||
(GroupPrivacySubject.Visibility, PrivacyLevel.Private) =>
|
||||
"This group is now hidden from group lists and member cards.",
|
||||
(GroupPrivacySubject.Metadata, PrivacyLevel.Private) =>
|
||||
"This group's metadata (eg. creation date) is now hidden from other systems.",
|
||||
(GroupPrivacySubject.List, PrivacyLevel.Private) =>
|
||||
"This group's member list is now hidden from other systems.",
|
||||
|
||||
(GroupPrivacySubject.Name, PrivacyLevel.Public) =>
|
||||
"This group's name is no longer hidden from other systems.",
|
||||
(GroupPrivacySubject.Description, PrivacyLevel.Public) =>
|
||||
"This group's description is no longer hidden from other systems.",
|
||||
(GroupPrivacySubject.Banner, PrivacyLevel.Public) =>
|
||||
"This group's banner is no longer hidden from other systems.",
|
||||
(GroupPrivacySubject.Icon, PrivacyLevel.Public) =>
|
||||
"This group's icon is no longer hidden from other systems.",
|
||||
(GroupPrivacySubject.Visibility, PrivacyLevel.Public) =>
|
||||
"This group is no longer hidden from group lists and member cards.",
|
||||
(GroupPrivacySubject.Metadata, PrivacyLevel.Public) =>
|
||||
"This group's metadata (eg. creation date) is no longer hidden from other systems.",
|
||||
(GroupPrivacySubject.List, PrivacyLevel.Public) =>
|
||||
"This group's member list is no longer hidden from other systems.",
|
||||
|
||||
_ => throw new InvalidOperationException($"Invalid subject/level tuple ({subject}, {level})")
|
||||
};
|
||||
|
||||
var replyStr = $"{Emojis.Success} {target.Name}'s **{subjectName}** has been set to **{level.LevelName()}**. {explanation}";
|
||||
|
||||
if (subject == GroupPrivacySubject.Name && level == PrivacyLevel.Private && target.DisplayName == null)
|
||||
replyStr += $"\n{Emojis.Warn} This group does not have a display name set, and name privacy **will not take effect**.";
|
||||
|
||||
await ctx.Reply(replyStr);
|
||||
}
|
||||
|
||||
if (ctx.Match("all") || newValueFromCommand != null)
|
||||
await SetAll(newValueFromCommand ?? ctx.PopPrivacyLevel());
|
||||
if (level == PrivacyLevel.Private)
|
||||
await ctx.Reply(
|
||||
$"{Emojis.Success} All {target.Name}'s privacy settings have been set to **{level.LevelName()}**. Other accounts will now see nothing on the group card.");
|
||||
else
|
||||
await SetLevel(ctx.PopGroupPrivacySubject(), ctx.PopPrivacyLevel());
|
||||
await ctx.Reply(
|
||||
$"{Emojis.Success} All {target.Name}'s privacy settings have been set to **{level.LevelName()}**. Other accounts will now see everything on the group card.");
|
||||
}
|
||||
|
||||
public async Task SetGroupPrivacy(Context ctx, PKGroup target, GroupPrivacySubject subject, PrivacyLevel level)
|
||||
{
|
||||
ctx.CheckOwnGroup(target);
|
||||
|
||||
await ctx.Repository.UpdateGroup(target.Id, new GroupPatch().WithPrivacy(subject, level));
|
||||
|
||||
var subjectName = subject switch
|
||||
{
|
||||
GroupPrivacySubject.Name => "name privacy",
|
||||
GroupPrivacySubject.Description => "description privacy",
|
||||
GroupPrivacySubject.Banner => "banner privacy",
|
||||
GroupPrivacySubject.Icon => "icon privacy",
|
||||
GroupPrivacySubject.List => "member list",
|
||||
GroupPrivacySubject.Metadata => "metadata",
|
||||
GroupPrivacySubject.Visibility => "visibility",
|
||||
_ => throw new ArgumentOutOfRangeException($"Unknown privacy subject {subject}")
|
||||
};
|
||||
|
||||
var explanation = (subject, level) switch
|
||||
{
|
||||
(GroupPrivacySubject.Name, PrivacyLevel.Private) =>
|
||||
"This group's name is now hidden from other systems, and will be replaced by the group's display name.",
|
||||
(GroupPrivacySubject.Description, PrivacyLevel.Private) =>
|
||||
"This group's description is now hidden from other systems.",
|
||||
(GroupPrivacySubject.Banner, PrivacyLevel.Private) =>
|
||||
"This group's banner is now hidden from other systems.",
|
||||
(GroupPrivacySubject.Icon, PrivacyLevel.Private) =>
|
||||
"This group's icon is now hidden from other systems.",
|
||||
(GroupPrivacySubject.Visibility, PrivacyLevel.Private) =>
|
||||
"This group is now hidden from group lists and member cards.",
|
||||
(GroupPrivacySubject.Metadata, PrivacyLevel.Private) =>
|
||||
"This group's metadata (eg. creation date) is now hidden from other systems.",
|
||||
(GroupPrivacySubject.List, PrivacyLevel.Private) =>
|
||||
"This group's member list is now hidden from other systems.",
|
||||
|
||||
(GroupPrivacySubject.Name, PrivacyLevel.Public) =>
|
||||
"This group's name is no longer hidden from other systems.",
|
||||
(GroupPrivacySubject.Description, PrivacyLevel.Public) =>
|
||||
"This group's description is no longer hidden from other systems.",
|
||||
(GroupPrivacySubject.Banner, PrivacyLevel.Public) =>
|
||||
"This group's banner is no longer hidden from other systems.",
|
||||
(GroupPrivacySubject.Icon, PrivacyLevel.Public) =>
|
||||
"This group's icon is no longer hidden from other systems.",
|
||||
(GroupPrivacySubject.Visibility, PrivacyLevel.Public) =>
|
||||
"This group is no longer hidden from group lists and member cards.",
|
||||
(GroupPrivacySubject.Metadata, PrivacyLevel.Public) =>
|
||||
"This group's metadata (eg. creation date) is no longer hidden from other systems.",
|
||||
(GroupPrivacySubject.List, PrivacyLevel.Public) =>
|
||||
"This group's member list is no longer hidden from other systems.",
|
||||
|
||||
_ => throw new InvalidOperationException($"Invalid subject/level tuple ({subject}, {level})")
|
||||
};
|
||||
|
||||
var replyStr = $"{Emojis.Success} {target.Name}'s **{subjectName}** has been set to **{level.LevelName()}**. {explanation}";
|
||||
|
||||
if (subject == GroupPrivacySubject.Name && level == PrivacyLevel.Private && target.DisplayName == null)
|
||||
replyStr += $"\n{Emojis.Warn} This group does not have a display name set, and name privacy **will not take effect**.";
|
||||
|
||||
await ctx.Reply(replyStr);
|
||||
}
|
||||
|
||||
public async Task DeleteGroup(Context ctx, PKGroup target)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,136 @@ pub fn cmds() -> impl Iterator<Item = Command> {
|
|||
let group = group();
|
||||
let group_target = targeted();
|
||||
|
||||
let group_new = tokens!(group, ("new", ["n"]));
|
||||
let group_new_cmd =
|
||||
[command!(group_new, ("name", OpaqueString) => "group_new").help("Creates a new group")]
|
||||
.into_iter();
|
||||
|
||||
let group_info_cmd =
|
||||
[command!(group_target => "group_info").help("Shows information about a group")]
|
||||
.into_iter();
|
||||
|
||||
let group_name = tokens!(
|
||||
group_target,
|
||||
("name", ["rename", "changename", "setname", "rn"])
|
||||
);
|
||||
let group_name_cmd = [
|
||||
command!(group_name => "group_show_name").help("Shows the group's name"),
|
||||
command!(group_name, ("clear", ["c"]) => "group_clear_name")
|
||||
.flag(("yes", ["y"]))
|
||||
.help("Clears the group's name"),
|
||||
command!(group_name, ("name", OpaqueString) => "group_rename").help("Renames the group"),
|
||||
]
|
||||
.into_iter();
|
||||
|
||||
let group_display_name = tokens!(group_target, ("displayname", ["dn", "nick", "nickname"]));
|
||||
let group_display_name_cmd = [
|
||||
command!(group_display_name => "group_show_display_name")
|
||||
.help("Shows the group's display name"),
|
||||
command!(group_display_name, ("clear", ["c"]) => "group_clear_display_name")
|
||||
.flag(("yes", ["y"]))
|
||||
.help("Clears the group's display name"),
|
||||
command!(group_display_name, ("name", OpaqueString) => "group_change_display_name")
|
||||
.help("Changes the group's display name"),
|
||||
]
|
||||
.into_iter();
|
||||
|
||||
let group_description = tokens!(
|
||||
group_target,
|
||||
(
|
||||
"description",
|
||||
["desc", "describe", "d", "bio", "info", "text", "intro"]
|
||||
)
|
||||
);
|
||||
let group_description_cmd = [
|
||||
command!(group_description => "group_show_description")
|
||||
.help("Shows the group's description"),
|
||||
command!(group_description, ("clear", ["c"]) => "group_clear_description")
|
||||
.flag(("yes", ["y"]))
|
||||
.help("Clears the group's description"),
|
||||
command!(group_description, ("description", OpaqueString) => "group_change_description")
|
||||
.help("Changes the group's description"),
|
||||
]
|
||||
.into_iter();
|
||||
|
||||
let group_icon = tokens!(
|
||||
group_target,
|
||||
("icon", ["avatar", "picture", "image", "pic", "pfp"])
|
||||
);
|
||||
let group_icon_cmd = [
|
||||
command!(group_icon => "group_show_icon").help("Shows the group's icon"),
|
||||
command!(group_icon, ("clear", ["c"]) => "group_clear_icon")
|
||||
.flag(("yes", ["y"]))
|
||||
.help("Clears the group's icon"),
|
||||
command!(group_icon, ("icon", Avatar) => "group_change_icon")
|
||||
.help("Changes the group's icon"),
|
||||
]
|
||||
.into_iter();
|
||||
|
||||
let group_banner = tokens!(group_target, ("banner", ["splash", "cover"]));
|
||||
let group_banner_cmd = [
|
||||
command!(group_banner => "group_show_banner").help("Shows the group's banner"),
|
||||
command!(group_banner, ("clear", ["c"]) => "group_clear_banner")
|
||||
.flag(("yes", ["y"]))
|
||||
.help("Clears the group's banner"),
|
||||
command!(group_banner, ("banner", Avatar) => "group_change_banner")
|
||||
.help("Changes the group's banner"),
|
||||
]
|
||||
.into_iter();
|
||||
|
||||
let group_color = tokens!(group_target, ("color", ["colour"]));
|
||||
let group_color_cmd = [
|
||||
command!(group_color => "group_show_color").help("Shows the group's color"),
|
||||
command!(group_color, ("clear", ["c"]) => "group_clear_color")
|
||||
.flag(("yes", ["y"]))
|
||||
.help("Clears the group's color"),
|
||||
command!(group_color, ("color", OpaqueString) => "group_change_color")
|
||||
.help("Changes the group's color"),
|
||||
]
|
||||
.into_iter();
|
||||
|
||||
let group_privacy = tokens!(group_target, ("privacy", ["priv"]));
|
||||
let group_privacy_cmd = [
|
||||
command!(group_privacy => "group_show_privacy")
|
||||
.help("Shows the group's privacy settings"),
|
||||
command!(group_privacy, ("all", ["a"]), ("level", PrivacyLevel) => "group_change_privacy_all")
|
||||
.help("Changes all privacy settings for the group"),
|
||||
command!(group_privacy, ("privacy", GroupPrivacyTarget), ("level", PrivacyLevel) => "group_change_privacy")
|
||||
.help("Changes a specific privacy setting for the group"),
|
||||
]
|
||||
.into_iter();
|
||||
|
||||
let group_public_cmd = [
|
||||
command!(group_target, ("public", ["pub"]) => "group_set_public")
|
||||
.help("Sets the group to public"),
|
||||
]
|
||||
.into_iter();
|
||||
|
||||
let group_private_cmd = [
|
||||
command!(group_target, ("private", ["priv"]) => "group_set_private")
|
||||
.help("Sets the group to private"),
|
||||
]
|
||||
.into_iter();
|
||||
|
||||
let group_delete_cmd = [
|
||||
command!(group_target, ("delete", ["destroy", "erase", "yeet"]) => "group_delete")
|
||||
.flag(("yes", ["y"]))
|
||||
.help("Deletes the group"),
|
||||
]
|
||||
.into_iter();
|
||||
|
||||
let group_id_cmd =
|
||||
[command!(group_target, "id" => "group_id").help("Shows the group's ID")].into_iter();
|
||||
|
||||
let group_front = tokens!(group_target, ("front", ["fronter", "fronters", "f"]));
|
||||
let group_front_cmd = [
|
||||
command!(group_front, ("percent", ["p", "%"]) => "group_fronter_percent")
|
||||
.flag(("duration", OpaqueString))
|
||||
.flag(("fronters-only", ["fo"]))
|
||||
.flag("flat"),
|
||||
]
|
||||
.into_iter();
|
||||
|
||||
let apply_list_opts = |cmd: Command| cmd.flags(get_list_flags());
|
||||
|
||||
let group_list_members = tokens!(group_target, ("members", ["list", "ls"]));
|
||||
|
|
@ -27,6 +157,14 @@ pub fn cmds() -> impl Iterator<Item = Command> {
|
|||
.into_iter()
|
||||
.map(apply_list_opts);
|
||||
|
||||
let group_modify_members_cmd = [
|
||||
command!(group_target, "add", MemberRefs => "group_add_member")
|
||||
.flag(("all", ["a"])),
|
||||
command!(group_target, ("remove", ["delete", "del", "rem"]), MemberRefs => "group_remove_member")
|
||||
.flag(("all", ["a"])),
|
||||
]
|
||||
.into_iter();
|
||||
|
||||
let system_groups_cmd = [
|
||||
command!(group, ("list", ["ls"]) => "group_list_groups"),
|
||||
command!(group, ("search", ["find", "query"]), ("query", OpaqueStringRemainder) => "group_search_groups"),
|
||||
|
|
@ -34,5 +172,21 @@ pub fn cmds() -> impl Iterator<Item = Command> {
|
|||
.into_iter()
|
||||
.map(apply_list_opts);
|
||||
|
||||
system_groups_cmd.chain(group_list_members_cmd)
|
||||
group_new_cmd
|
||||
.chain(group_info_cmd)
|
||||
.chain(group_name_cmd)
|
||||
.chain(group_display_name_cmd)
|
||||
.chain(group_description_cmd)
|
||||
.chain(group_icon_cmd)
|
||||
.chain(group_banner_cmd)
|
||||
.chain(group_color_cmd)
|
||||
.chain(group_privacy_cmd)
|
||||
.chain(group_public_cmd)
|
||||
.chain(group_private_cmd)
|
||||
.chain(group_front_cmd)
|
||||
.chain(group_modify_members_cmd)
|
||||
.chain(group_delete_cmd)
|
||||
.chain(group_id_cmd)
|
||||
.chain(group_list_members_cmd)
|
||||
.chain(system_groups_cmd)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -301,7 +301,17 @@ pub fn cmds() -> impl Iterator<Item = Command> {
|
|||
]
|
||||
.into_iter()
|
||||
.map(|cmd| cmd.flags(get_list_flags()));
|
||||
let member_group_cmds = member_list_group_cmds;
|
||||
|
||||
let member_add_remove_group_cmds = [
|
||||
command!(member_group, "add", ("groups", GroupRefs) => "member_group_add")
|
||||
.help("Adds a member to one or more groups"),
|
||||
command!(member_group, ("remove", ["rem"]), ("groups", GroupRefs) => "member_group_remove")
|
||||
.help("Removes a member from one or more groups"),
|
||||
]
|
||||
.into_iter();
|
||||
|
||||
let member_display_id_cmd =
|
||||
[command!(member_target, "id" => "member_id").help("Displays a member's ID")].into_iter();
|
||||
|
||||
let member_delete_cmd =
|
||||
[command!(member_target, delete => "member_delete").help("Deletes a member")].into_iter();
|
||||
|
|
@ -325,7 +335,9 @@ pub fn cmds() -> impl Iterator<Item = Command> {
|
|||
.chain(member_avatar_cmds)
|
||||
.chain(member_proxy_settings_cmd)
|
||||
.chain(member_message_settings_cmd)
|
||||
.chain(member_display_id_cmd)
|
||||
.chain(member_delete_cmd)
|
||||
.chain(member_easter_eggs)
|
||||
.chain(member_group_cmds)
|
||||
.chain(member_list_group_cmds)
|
||||
.chain(member_add_remove_group_cmds)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,9 +13,11 @@ pub enum ParameterValue {
|
|||
MemberRef(String),
|
||||
MemberRefs(Vec<String>),
|
||||
GroupRef(String),
|
||||
GroupRefs(Vec<String>),
|
||||
SystemRef(String),
|
||||
GuildRef(String),
|
||||
MemberPrivacyTarget(String),
|
||||
GroupPrivacyTarget(String),
|
||||
SystemPrivacyTarget(String),
|
||||
PrivacyLevel(String),
|
||||
Toggle(bool),
|
||||
|
|
@ -50,9 +52,11 @@ impl Display for Parameter {
|
|||
ParameterKind::MemberRef => write!(f, "<target member>"),
|
||||
ParameterKind::MemberRefs => write!(f, "<member 1> <member 2> <member 3>..."),
|
||||
ParameterKind::GroupRef => write!(f, "<target group>"),
|
||||
ParameterKind::GroupRefs => write!(f, "<group 1> <group 2> <group 3>..."),
|
||||
ParameterKind::SystemRef => write!(f, "<target system>"),
|
||||
ParameterKind::GuildRef => write!(f, "<target guild>"),
|
||||
ParameterKind::MemberPrivacyTarget => write!(f, "<privacy target>"),
|
||||
ParameterKind::GroupPrivacyTarget => write!(f, "<privacy target>"),
|
||||
ParameterKind::SystemPrivacyTarget => write!(f, "<privacy target>"),
|
||||
ParameterKind::PrivacyLevel => write!(f, "[privacy level]"),
|
||||
ParameterKind::Toggle => write!(f, "on/off"),
|
||||
|
|
@ -86,9 +90,11 @@ pub enum ParameterKind {
|
|||
MemberRef,
|
||||
MemberRefs,
|
||||
GroupRef,
|
||||
GroupRefs,
|
||||
SystemRef,
|
||||
GuildRef,
|
||||
MemberPrivacyTarget,
|
||||
GroupPrivacyTarget,
|
||||
SystemPrivacyTarget,
|
||||
PrivacyLevel,
|
||||
Toggle,
|
||||
|
|
@ -103,9 +109,11 @@ impl ParameterKind {
|
|||
ParameterKind::MemberRef => "target",
|
||||
ParameterKind::MemberRefs => "targets",
|
||||
ParameterKind::GroupRef => "target",
|
||||
ParameterKind::GroupRefs => "targets",
|
||||
ParameterKind::SystemRef => "target",
|
||||
ParameterKind::GuildRef => "target",
|
||||
ParameterKind::MemberPrivacyTarget => "member_privacy_target",
|
||||
ParameterKind::GroupPrivacyTarget => "group_privacy_target",
|
||||
ParameterKind::SystemPrivacyTarget => "system_privacy_target",
|
||||
ParameterKind::PrivacyLevel => "privacy_level",
|
||||
ParameterKind::Toggle => "toggle",
|
||||
|
|
@ -116,7 +124,9 @@ impl ParameterKind {
|
|||
pub(crate) fn remainder(&self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
ParameterKind::OpaqueStringRemainder | ParameterKind::MemberRefs
|
||||
ParameterKind::OpaqueStringRemainder
|
||||
| ParameterKind::MemberRefs
|
||||
| ParameterKind::GroupRefs
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -127,6 +137,9 @@ impl ParameterKind {
|
|||
Ok(ParameterValue::OpaqueString(input.into()))
|
||||
}
|
||||
ParameterKind::GroupRef => Ok(ParameterValue::GroupRef(input.into())),
|
||||
ParameterKind::GroupRefs => Ok(ParameterValue::GroupRefs(
|
||||
input.split(' ').map(|s| s.trim().to_string()).collect(),
|
||||
)),
|
||||
ParameterKind::MemberRef => Ok(ParameterValue::MemberRef(input.into())),
|
||||
ParameterKind::MemberRefs => Ok(ParameterValue::MemberRefs(
|
||||
input.split(' ').map(|s| s.trim().to_string()).collect(),
|
||||
|
|
@ -134,6 +147,8 @@ impl ParameterKind {
|
|||
ParameterKind::SystemRef => Ok(ParameterValue::SystemRef(input.into())),
|
||||
ParameterKind::MemberPrivacyTarget => MemberPrivacyTargetKind::from_str(input)
|
||||
.map(|target| ParameterValue::MemberPrivacyTarget(target.as_ref().into())),
|
||||
ParameterKind::GroupPrivacyTarget => GroupPrivacyTargetKind::from_str(input)
|
||||
.map(|target| ParameterValue::GroupPrivacyTarget(target.as_ref().into())),
|
||||
ParameterKind::SystemPrivacyTarget => SystemPrivacyTargetKind::from_str(input)
|
||||
.map(|target| ParameterValue::SystemPrivacyTarget(target.as_ref().into())),
|
||||
ParameterKind::PrivacyLevel => PrivacyLevelKind::from_str(input)
|
||||
|
|
@ -146,8 +161,13 @@ impl ParameterKind {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn skip_if_cant_match(&self) -> bool {
|
||||
matches!(self, ParameterKind::Toggle)
|
||||
pub(crate) fn skip_if_cant_match(&self) -> Option<Option<ParameterValue>> {
|
||||
match self {
|
||||
ParameterKind::Toggle => Some(None),
|
||||
ParameterKind::MemberRefs => Some(Some(ParameterValue::MemberRefs(Vec::new()))),
|
||||
ParameterKind::GroupRefs => Some(Some(ParameterValue::GroupRefs(Vec::new()))),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -200,6 +220,48 @@ impl FromStr for MemberPrivacyTargetKind {
|
|||
}
|
||||
}
|
||||
|
||||
pub enum GroupPrivacyTargetKind {
|
||||
Name,
|
||||
Icon,
|
||||
Description,
|
||||
Banner,
|
||||
List,
|
||||
Metadata,
|
||||
Visibility,
|
||||
}
|
||||
|
||||
impl AsRef<str> for GroupPrivacyTargetKind {
|
||||
fn as_ref(&self) -> &str {
|
||||
match self {
|
||||
Self::Name => "name",
|
||||
Self::Icon => "icon",
|
||||
Self::Description => "description",
|
||||
Self::Banner => "banner",
|
||||
Self::List => "list",
|
||||
Self::Metadata => "metadata",
|
||||
Self::Visibility => "visibility",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for GroupPrivacyTargetKind {
|
||||
type Err = SmolStr;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
// todo: this doesnt parse all the possible ways
|
||||
match s.to_lowercase().as_str() {
|
||||
"name" => Ok(Self::Name),
|
||||
"avatar" | "icon" => Ok(Self::Icon),
|
||||
"description" => Ok(Self::Description),
|
||||
"banner" => Ok(Self::Banner),
|
||||
"list" => Ok(Self::List),
|
||||
"metadata" => Ok(Self::Metadata),
|
||||
"visibility" => Ok(Self::Visibility),
|
||||
_ => Err("invalid group privacy target".into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum SystemPrivacyTargetKind {
|
||||
Name,
|
||||
Avatar,
|
||||
|
|
|
|||
|
|
@ -68,8 +68,14 @@ impl Token {
|
|||
value: matched,
|
||||
},
|
||||
Err(err) => {
|
||||
if param.kind().skip_if_cant_match() {
|
||||
return None;
|
||||
if let Some(maybe_empty) = param.kind().skip_if_cant_match() {
|
||||
match maybe_empty {
|
||||
Some(matched) => TokenMatchResult::MatchedParameter {
|
||||
name: param.name().into(),
|
||||
value: matched,
|
||||
},
|
||||
None => return None,
|
||||
}
|
||||
} else {
|
||||
TokenMatchResult::ParameterMatchError {
|
||||
input: input.into(),
|
||||
|
|
|
|||
|
|
@ -258,8 +258,10 @@ fn get_param_ty(kind: ParameterKind) -> &'static str {
|
|||
ParameterKind::MemberRef => "PKMember",
|
||||
ParameterKind::MemberRefs => "List<PKMember>",
|
||||
ParameterKind::GroupRef => "PKGroup",
|
||||
ParameterKind::GroupRefs => "List<PKGroup>",
|
||||
ParameterKind::SystemRef => "PKSystem",
|
||||
ParameterKind::MemberPrivacyTarget => "MemberPrivacySubject",
|
||||
ParameterKind::GroupPrivacyTarget => "GroupPrivacySubject",
|
||||
ParameterKind::SystemPrivacyTarget => "SystemPrivacySubject",
|
||||
ParameterKind::PrivacyLevel => "PrivacyLevel",
|
||||
ParameterKind::Toggle => "bool",
|
||||
|
|
@ -274,8 +276,10 @@ fn get_param_param_ty(kind: ParameterKind) -> &'static str {
|
|||
ParameterKind::MemberRef => "Member",
|
||||
ParameterKind::MemberRefs => "Members",
|
||||
ParameterKind::GroupRef => "Group",
|
||||
ParameterKind::GroupRefs => "Groups",
|
||||
ParameterKind::SystemRef => "System",
|
||||
ParameterKind::MemberPrivacyTarget => "MemberPrivacyTarget",
|
||||
ParameterKind::GroupPrivacyTarget => "GroupPrivacyTarget",
|
||||
ParameterKind::SystemPrivacyTarget => "SystemPrivacyTarget",
|
||||
ParameterKind::PrivacyLevel => "PrivacyLevel",
|
||||
ParameterKind::Toggle => "Toggle",
|
||||
|
|
|
|||
|
|
@ -11,9 +11,11 @@ interface Parameter {
|
|||
MemberRef(string member);
|
||||
MemberRefs(sequence<string> members);
|
||||
GroupRef(string group);
|
||||
GroupRefs(sequence<string> groups);
|
||||
SystemRef(string system);
|
||||
GuildRef(string guild);
|
||||
MemberPrivacyTarget(string target);
|
||||
GroupPrivacyTarget(string target);
|
||||
SystemPrivacyTarget(string target);
|
||||
PrivacyLevel(string level);
|
||||
OpaqueString(string raw);
|
||||
|
|
|
|||
|
|
@ -25,9 +25,11 @@ pub enum Parameter {
|
|||
MemberRef { member: String },
|
||||
MemberRefs { members: Vec<String> },
|
||||
GroupRef { group: String },
|
||||
GroupRefs { groups: Vec<String> },
|
||||
SystemRef { system: String },
|
||||
GuildRef { guild: String },
|
||||
MemberPrivacyTarget { target: String },
|
||||
GroupPrivacyTarget { target: String },
|
||||
SystemPrivacyTarget { target: String },
|
||||
PrivacyLevel { level: String },
|
||||
OpaqueString { raw: String },
|
||||
|
|
@ -41,8 +43,10 @@ impl From<ParameterValue> for Parameter {
|
|||
ParameterValue::MemberRef(member) => Self::MemberRef { member },
|
||||
ParameterValue::MemberRefs(members) => Self::MemberRefs { members },
|
||||
ParameterValue::GroupRef(group) => Self::GroupRef { group },
|
||||
ParameterValue::GroupRefs(groups) => Self::GroupRefs { groups },
|
||||
ParameterValue::SystemRef(system) => Self::SystemRef { system },
|
||||
ParameterValue::MemberPrivacyTarget(target) => Self::MemberPrivacyTarget { target },
|
||||
ParameterValue::GroupPrivacyTarget(target) => Self::GroupPrivacyTarget { target },
|
||||
ParameterValue::SystemPrivacyTarget(target) => Self::SystemPrivacyTarget { target },
|
||||
ParameterValue::PrivacyLevel(level) => Self::PrivacyLevel { level },
|
||||
ParameterValue::OpaqueString(raw) => Self::OpaqueString { raw },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue