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

This commit is contained in:
Iris System 2025-12-28 00:06:51 +13:00
parent 41f8beb2aa
commit 24b6b0d455
16 changed files with 306 additions and 3 deletions

View file

@ -21,6 +21,38 @@ public class MemberEdit
_avatarHosting = avatarHosting;
}
public async Task ChangeId(Context ctx, PKMember target)
{
ctx.CheckSystem().CheckOwnMember(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 existingMember = await ctx.Repository.GetMemberByHid(newHid);
if (existingMember != null)
throw new PKError($"Another member already exists with ID `{newHid.DisplayHid(ctx.Config)}`.");
if (ctx.Config.PremiumIdChangesRemaining < 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 member **{target.NameFor(ctx)}** (`{target.DisplayHid(ctx.Config)}`) to `{newHid.DisplayHid(ctx.Config)}`?", "Change"))
throw new PKError("ID change cancelled.");
if (!await ctx.Repository.TryUpdateSystemConfigForIdChange(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, "member", target.Hid, newHid);
await ctx.Repository.UpdateMember(target.Id, new MemberPatch { Hid = newHid });
var newConfig = await ctx.Repository.GetSystemConfig(ctx.System.Id);
await ctx.Reply($"{Emojis.Success} Member ID changed to `{newHid.DisplayHid(ctx.Config)}`. You have **{newConfig.PremiumIdChangesRemaining}** ID changes remaining.");
}
public async Task Name(Context ctx, PKMember target)
{
var format = ctx.MatchFormat();