mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-08 23:07:54 +00:00
feat: upgrade to .NET 6, refactor everything
This commit is contained in:
parent
d28e99ba43
commit
1918c56937
314 changed files with 27954 additions and 27966 deletions
|
|
@ -1,60 +1,56 @@
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Myriad.Extensions;
|
||||
using Myriad.Rest.Types;
|
||||
|
||||
using PluralKit.Core;
|
||||
|
||||
namespace PluralKit.Bot
|
||||
namespace PluralKit.Bot;
|
||||
|
||||
public class SystemLink
|
||||
{
|
||||
public class SystemLink
|
||||
private readonly IDatabase _db;
|
||||
private readonly ModelRepository _repo;
|
||||
|
||||
public SystemLink(IDatabase db, ModelRepository repo)
|
||||
{
|
||||
private readonly IDatabase _db;
|
||||
private readonly ModelRepository _repo;
|
||||
_db = db;
|
||||
_repo = repo;
|
||||
}
|
||||
|
||||
public SystemLink(IDatabase db, ModelRepository repo)
|
||||
{
|
||||
_db = db;
|
||||
_repo = repo;
|
||||
}
|
||||
public async Task LinkSystem(Context ctx)
|
||||
{
|
||||
ctx.CheckSystem();
|
||||
|
||||
public async Task LinkSystem(Context ctx)
|
||||
{
|
||||
ctx.CheckSystem();
|
||||
var account = await ctx.MatchUser() ??
|
||||
throw new PKSyntaxError("You must pass an account to link with (either ID or @mention).");
|
||||
var accountIds = await _repo.GetSystemAccounts(ctx.System.Id);
|
||||
if (accountIds.Contains(account.Id))
|
||||
throw Errors.AccountAlreadyLinked;
|
||||
|
||||
var account = await ctx.MatchUser() ?? throw new PKSyntaxError("You must pass an account to link with (either ID or @mention).");
|
||||
var accountIds = await _repo.GetSystemAccounts(ctx.System.Id);
|
||||
if (accountIds.Contains(account.Id))
|
||||
throw Errors.AccountAlreadyLinked;
|
||||
var existingAccount = await _repo.GetSystemByAccount(account.Id);
|
||||
if (existingAccount != null)
|
||||
throw Errors.AccountInOtherSystem(existingAccount);
|
||||
|
||||
var existingAccount = await _repo.GetSystemByAccount(account.Id);
|
||||
if (existingAccount != null)
|
||||
throw Errors.AccountInOtherSystem(existingAccount);
|
||||
var msg = $"{account.Mention()}, please confirm the link.";
|
||||
if (!await ctx.PromptYesNo(msg, "Confirm", account, false)) throw Errors.MemberLinkCancelled;
|
||||
await _repo.AddAccount(ctx.System.Id, account.Id);
|
||||
await ctx.Reply($"{Emojis.Success} Account linked to system.");
|
||||
}
|
||||
|
||||
var msg = $"{account.Mention()}, please confirm the link.";
|
||||
if (!await ctx.PromptYesNo(msg, "Confirm", user: account, matchFlag: false)) throw Errors.MemberLinkCancelled;
|
||||
await _repo.AddAccount(ctx.System.Id, account.Id);
|
||||
await ctx.Reply($"{Emojis.Success} Account linked to system.");
|
||||
}
|
||||
public async Task UnlinkAccount(Context ctx)
|
||||
{
|
||||
ctx.CheckSystem();
|
||||
|
||||
public async Task UnlinkAccount(Context ctx)
|
||||
{
|
||||
ctx.CheckSystem();
|
||||
ulong id;
|
||||
if (!ctx.MatchUserRaw(out id))
|
||||
throw new PKSyntaxError("You must pass an account to link with (either ID or @mention).");
|
||||
|
||||
ulong id;
|
||||
if (!ctx.MatchUserRaw(out id))
|
||||
throw new PKSyntaxError("You must pass an account to link with (either ID or @mention).");
|
||||
var accountIds = (await _repo.GetSystemAccounts(ctx.System.Id)).ToList();
|
||||
if (!accountIds.Contains(id)) throw Errors.AccountNotLinked;
|
||||
if (accountIds.Count == 1) throw Errors.UnlinkingLastAccount;
|
||||
|
||||
var accountIds = (await _repo.GetSystemAccounts(ctx.System.Id)).ToList();
|
||||
if (!accountIds.Contains(id)) throw Errors.AccountNotLinked;
|
||||
if (accountIds.Count == 1) throw Errors.UnlinkingLastAccount;
|
||||
var msg = $"Are you sure you want to unlink <@{id}> from your system?";
|
||||
if (!await ctx.PromptYesNo(msg, "Unlink")) throw Errors.MemberUnlinkCancelled;
|
||||
|
||||
var msg = $"Are you sure you want to unlink <@{id}> from your system?";
|
||||
if (!await ctx.PromptYesNo(msg, "Unlink")) throw Errors.MemberUnlinkCancelled;
|
||||
|
||||
await _repo.RemoveAccount(ctx.System.Id, id);
|
||||
await ctx.Reply($"{Emojis.Success} Account unlinked.");
|
||||
}
|
||||
await _repo.RemoveAccount(ctx.System.Id, id);
|
||||
await ctx.Reply($"{Emojis.Success} Account unlinked.");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue