Add super basic group model/command
This commit is contained in:
@@ -45,6 +45,8 @@ namespace PluralKit.Bot
|
||||
public static Command MemberKeepProxy = new Command("member keepproxy", "member <member> keepproxy [on|off]", "Sets whether to include a member's proxy tags when proxying");
|
||||
public static Command MemberRandom = new Command("random", "random", "Looks up a random member from your system");
|
||||
public static Command MemberPrivacy = new Command("member privacy", "member <member> privacy <name|description|birthday|pronouns|metadata|visibility|all> <public|private>", "Changes a members's privacy settings");
|
||||
public static Command GroupInfo = new Command("group", "group <name>", "Looks up information about a group");
|
||||
public static Command GroupNew = new Command("group new", "group new <name>", "Creates a new group");
|
||||
public static Command Switch = new Command("switch", "switch <member> [member 2] [member 3...]", "Registers a switch");
|
||||
public static Command SwitchOut = new Command("switch out", "switch out", "Registers a switch with no members");
|
||||
public static Command SwitchMove = new Command("switch move", "switch move <date/time>", "Moves the latest switch in time");
|
||||
@@ -97,6 +99,8 @@ namespace PluralKit.Bot
|
||||
return HandleSystemCommand(ctx);
|
||||
if (ctx.Match("member", "m"))
|
||||
return HandleMemberCommand(ctx);
|
||||
if (ctx.Match("group", "g"))
|
||||
return HandleGroupCommand(ctx);
|
||||
if (ctx.Match("switch", "sw"))
|
||||
return HandleSwitchCommand(ctx);
|
||||
if (ctx.Match("ap", "autoproxy", "auto"))
|
||||
@@ -312,6 +316,19 @@ namespace PluralKit.Bot
|
||||
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));
|
||||
|
||||
if (await ctx.MatchGroup() is {} group)
|
||||
{
|
||||
// Commands with group argument
|
||||
await ctx.Execute<Groups>(GroupInfo, g => g.ShowGroupCard(ctx, group));
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleSwitchCommand(Context ctx)
|
||||
{
|
||||
if (ctx.Match("out"))
|
||||
|
58
PluralKit.Bot/Commands/Groups.cs
Normal file
58
PluralKit.Bot/Commands/Groups.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using DSharpPlus.Entities;
|
||||
|
||||
using PluralKit.Core;
|
||||
|
||||
namespace PluralKit.Bot
|
||||
{
|
||||
public class Groups
|
||||
{
|
||||
private readonly IDatabase _db;
|
||||
|
||||
public Groups(IDatabase db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public async Task CreateGroup(Context ctx)
|
||||
{
|
||||
ctx.CheckSystem();
|
||||
|
||||
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.MaxMemberNameLength} characters).");
|
||||
|
||||
await using var conn = await _db.Obtain();
|
||||
var newGroup = await conn.CreateGroup(ctx.System.Id, groupName);
|
||||
|
||||
await ctx.Reply($"{Emojis.Success} Group \"**{groupName}**\" (`{newGroup.Hid}`) registered!\nYou can now start adding members to the group:\n- **pk;group {newGroup.Hid} add <members...>**");
|
||||
}
|
||||
|
||||
public async Task ShowGroupCard(Context ctx, PKGroup target)
|
||||
{
|
||||
await using var conn = await _db.Obtain();
|
||||
|
||||
var system = await GetGroupSystem(ctx, target, conn);
|
||||
|
||||
var nameField = target.Name;
|
||||
if (system.Name != null)
|
||||
nameField = $"{nameField} ({system.Name})";
|
||||
|
||||
var eb = new DiscordEmbedBuilder()
|
||||
.WithAuthor(nameField)
|
||||
.WithDescription(target.Description)
|
||||
.WithFooter($"System ID: {system.Hid} | Group ID: {target.Hid} | Created on {target.Created.FormatZoned(system)}");
|
||||
|
||||
await ctx.Reply(embed: eb.Build());
|
||||
}
|
||||
|
||||
private static async Task<PKSystem> GetGroupSystem(Context ctx, PKGroup target, IPKConnection conn)
|
||||
{
|
||||
var system = ctx.System;
|
||||
if (system?.Id == target.System)
|
||||
return system;
|
||||
return await conn.QuerySystem(target.System)!;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user