mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-12 08:40:11 +00:00
feat: premium ID changes
Some checks failed
Build and push Docker image / .net docker build (push) Has been cancelled
.net checks / run .net tests (push) Has been cancelled
.net checks / dotnet-format (push) Has been cancelled
Build and push Rust service Docker images / rust docker build (push) Has been cancelled
rust checks / cargo fmt (push) Has been cancelled
Some checks failed
Build and push Docker image / .net docker build (push) Has been cancelled
.net checks / run .net tests (push) Has been cancelled
.net checks / dotnet-format (push) Has been cancelled
Build and push Rust service Docker images / rust docker build (push) Has been cancelled
rust checks / cargo fmt (push) Has been cancelled
This commit is contained in:
parent
84e98450e0
commit
def9285250
19 changed files with 364 additions and 5 deletions
|
|
@ -4,6 +4,8 @@ using System.Text.RegularExpressions;
|
|||
using Myriad.Builders;
|
||||
using Myriad.Types;
|
||||
|
||||
using NodaTime;
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
using PluralKit.Core;
|
||||
|
|
@ -99,6 +101,39 @@ public class Groups
|
|||
await ctx.Reply(replyStr, eb.Build());
|
||||
}
|
||||
|
||||
public async Task ChangeId(Context ctx, PKGroup target)
|
||||
{
|
||||
ctx.CheckSystem().CheckOwnGroup(target);
|
||||
if (!ctx.Premium)
|
||||
throw Errors.PremiumExclusiveCommand();
|
||||
|
||||
var input = ctx.PopArgument();
|
||||
if (!input.TryParseHid(out var newHid))
|
||||
throw new PKError($"Invalid new member ID `{input}`.");
|
||||
|
||||
var existingGroup = await ctx.Repository.GetGroupByHid(newHid);
|
||||
if (existingGroup != null)
|
||||
throw new PKError($"Another group already exists with ID `{newHid.DisplayHid(ctx.Config)}`.");
|
||||
|
||||
var allowance = await ctx.Repository.GetPremiumAllowance(ctx.System.Id)!;
|
||||
if (allowance.IdChangesRemaining < 1)
|
||||
throw new PKError("You do not have enough available ID changes to do this.");
|
||||
if ((await ctx.Repository.GetHidChangelogCountForDate(ctx.System.Id, SystemClock.Instance.GetCurrentInstant().InUtc().Date)) >= Limits.PremiumDailyHidChanges)
|
||||
throw new PKError($"You have already changed {Limits.PremiumDailyHidChanges} IDs today. Please try again tomorrow.");
|
||||
|
||||
if (!await ctx.PromptYesNo($"Change ID for group **{target.NameFor(ctx)}** (`{target.DisplayHid(ctx.Config)}`) to `{newHid.DisplayHid(ctx.Config)}`?", "Change"))
|
||||
throw new PKError("ID change cancelled.");
|
||||
|
||||
if (!await ctx.Repository.UpdatePremiumAllowanceForIdChange(ctx.System.Id))
|
||||
throw new PKError("You do not have enough available ID changes to do this.");
|
||||
|
||||
await ctx.Repository.CreateHidChangelog(ctx.System.Id, ctx.Message.Author.Id, "group", target.Hid, newHid);
|
||||
await ctx.Repository.UpdateGroup(target.Id, new GroupPatch { Hid = newHid });
|
||||
|
||||
var newAllowance = await ctx.Repository.GetPremiumAllowance(ctx.System.Id)!;
|
||||
await ctx.Reply($"{Emojis.Success} Group ID changed to `{newHid.DisplayHid(ctx.Config)}`. You have **{newAllowance.IdChangesRemaining}** ID changes remaining.");
|
||||
}
|
||||
|
||||
public async Task RenameGroup(Context ctx, PKGroup target)
|
||||
{
|
||||
ctx.CheckOwnGroup(target);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue