feat(bot): add utility admin command

This commit is contained in:
asleepyskye 2025-09-09 10:43:00 -04:00
parent 4293f26b8a
commit 8bca02032f
2 changed files with 32 additions and 0 deletions

View file

@ -181,6 +181,8 @@ public partial class CommandTree
await ctx.Execute<Admin>(Admin, a => a.SystemRecover(ctx)); await ctx.Execute<Admin>(Admin, a => a.SystemRecover(ctx));
else if (ctx.Match("sd", "systemdelete")) else if (ctx.Match("sd", "systemdelete"))
await ctx.Execute<Admin>(Admin, a => a.SystemDelete(ctx)); await ctx.Execute<Admin>(Admin, a => a.SystemDelete(ctx));
else if (ctx.Match("sendmsg", "sendmessage"))
await ctx.Execute<Admin>(Admin, a => a.SendAdminMessage(ctx));
else if (ctx.Match("al", "abuselog")) else if (ctx.Match("al", "abuselog"))
await HandleAdminAbuseLogCommand(ctx); await HandleAdminAbuseLogCommand(ctx);
else else

View file

@ -9,6 +9,7 @@ using Myriad.Extensions;
using Myriad.Cache; using Myriad.Cache;
using Myriad.Rest; using Myriad.Rest;
using Myriad.Types; using Myriad.Types;
using Myriad.Rest.Types.Requests;
using PluralKit.Core; using PluralKit.Core;
@ -496,4 +497,33 @@ public class Admin
await ctx.Repository.DeleteAbuseLog(abuseLog.Id); await ctx.Repository.DeleteAbuseLog(abuseLog.Id);
await ctx.Reply($"{Emojis.Success} Successfully deleted abuse log entry."); await ctx.Reply($"{Emojis.Success} Successfully deleted abuse log entry.");
} }
public async Task SendAdminMessage(Context ctx)
{
ctx.AssertBotAdmin();
var account = await ctx.MatchUser();
if (account == null)
throw new PKError("You must pass an account to send an admin message to (either ID or @mention).");
if (!ctx.HasNext())
throw new PKError("You must provide a message to send.");
var content = ctx.RemainderOrNull(false).NormalizeLineEndSpacing();
var messageContent = $"## [Admin Message]\n\n{content}\n\nWe cannot read replies sent to this DM. If you wish to contact the staff team, please join the support server (<https://discord.gg/PczBt78>) or send us an email at <legal@pluralkit.me>.";
try
{
var dm = await _rest.CreateDm(account.Id);
var msg = await ctx.Rest.CreateMessage(dm.Id,
new MessageRequest { Content = messageContent }
);
}
catch (Exception)
{
await ctx.Reply(
$"{Emojis.Error} Error while sending DM.");
}
await ctx.Reply($"{Emojis.Success} Successfully sent message.");
}
} }