refactor: don't DI IDatabase and ModelRepository into bot command classes
This commit is contained in:
@@ -13,11 +13,9 @@ namespace PluralKit.Bot;
|
||||
public class MemberEdit
|
||||
{
|
||||
private readonly HttpClient _client;
|
||||
private readonly ModelRepository _repo;
|
||||
|
||||
public MemberEdit(ModelRepository repo, HttpClient client)
|
||||
public MemberEdit(HttpClient client)
|
||||
{
|
||||
_repo = repo;
|
||||
_client = client;
|
||||
}
|
||||
|
||||
@@ -32,7 +30,7 @@ public class MemberEdit
|
||||
throw Errors.StringTooLongError("Member name", newName.Length, Limits.MaxMemberNameLength);
|
||||
|
||||
// Warn if there's already a member by this name
|
||||
var existingMember = await _repo.GetMemberByName(ctx.System.Id, newName);
|
||||
var existingMember = await ctx.Repository.GetMemberByName(ctx.System.Id, newName);
|
||||
if (existingMember != null && existingMember.Id != target.Id)
|
||||
{
|
||||
var msg =
|
||||
@@ -42,7 +40,7 @@ public class MemberEdit
|
||||
|
||||
// Rename the member
|
||||
var patch = new MemberPatch { Name = Partial<string>.Present(newName) };
|
||||
await _repo.UpdateMember(target.Id, patch);
|
||||
await ctx.Repository.UpdateMember(target.Id, patch);
|
||||
|
||||
await ctx.Reply($"{Emojis.Success} Member renamed.");
|
||||
if (newName.Contains(" "))
|
||||
@@ -54,7 +52,7 @@ public class MemberEdit
|
||||
|
||||
if (ctx.Guild != null)
|
||||
{
|
||||
var memberGuildConfig = await _repo.GetMemberGuild(ctx.Guild.Id, target.Id);
|
||||
var memberGuildConfig = await ctx.Repository.GetMemberGuild(ctx.Guild.Id, target.Id);
|
||||
if (memberGuildConfig.DisplayName != null)
|
||||
await ctx.Reply(
|
||||
$"{Emojis.Note} Note that this member has a server name set ({memberGuildConfig.DisplayName}) in this server ({ctx.Guild.Name}), and will be proxied using that name here.");
|
||||
@@ -101,7 +99,7 @@ public class MemberEdit
|
||||
if (await ctx.MatchClear("this member's description"))
|
||||
{
|
||||
var patch = new MemberPatch { Description = Partial<string>.Null() };
|
||||
await _repo.UpdateMember(target.Id, patch);
|
||||
await ctx.Repository.UpdateMember(target.Id, patch);
|
||||
await ctx.Reply($"{Emojis.Success} Member description cleared.");
|
||||
}
|
||||
else
|
||||
@@ -111,7 +109,7 @@ public class MemberEdit
|
||||
throw Errors.StringTooLongError("Description", description.Length, Limits.MaxDescriptionLength);
|
||||
|
||||
var patch = new MemberPatch { Description = Partial<string>.Present(description) };
|
||||
await _repo.UpdateMember(target.Id, patch);
|
||||
await ctx.Repository.UpdateMember(target.Id, patch);
|
||||
|
||||
await ctx.Reply($"{Emojis.Success} Member description changed.");
|
||||
}
|
||||
@@ -152,7 +150,7 @@ public class MemberEdit
|
||||
if (await ctx.MatchClear("this member's pronouns"))
|
||||
{
|
||||
var patch = new MemberPatch { Pronouns = Partial<string>.Null() };
|
||||
await _repo.UpdateMember(target.Id, patch);
|
||||
await ctx.Repository.UpdateMember(target.Id, patch);
|
||||
await ctx.Reply($"{Emojis.Success} Member pronouns cleared.");
|
||||
}
|
||||
else
|
||||
@@ -162,7 +160,7 @@ public class MemberEdit
|
||||
throw Errors.StringTooLongError("Pronouns", pronouns.Length, Limits.MaxPronounsLength);
|
||||
|
||||
var patch = new MemberPatch { Pronouns = Partial<string>.Present(pronouns) };
|
||||
await _repo.UpdateMember(target.Id, patch);
|
||||
await ctx.Repository.UpdateMember(target.Id, patch);
|
||||
|
||||
await ctx.Reply($"{Emojis.Success} Member pronouns changed.");
|
||||
}
|
||||
@@ -174,7 +172,7 @@ public class MemberEdit
|
||||
|
||||
async Task ClearBannerImage()
|
||||
{
|
||||
await _repo.UpdateMember(target.Id, new MemberPatch { BannerImage = null });
|
||||
await ctx.Repository.UpdateMember(target.Id, new MemberPatch { BannerImage = null });
|
||||
await ctx.Reply($"{Emojis.Success} Member banner image cleared.");
|
||||
}
|
||||
|
||||
@@ -182,7 +180,7 @@ public class MemberEdit
|
||||
{
|
||||
await AvatarUtils.VerifyAvatarOrThrow(_client, img.Url, true);
|
||||
|
||||
await _repo.UpdateMember(target.Id, new MemberPatch { BannerImage = img.Url });
|
||||
await ctx.Repository.UpdateMember(target.Id, new MemberPatch { BannerImage = img.Url });
|
||||
|
||||
var msg = img.Source switch
|
||||
{
|
||||
@@ -233,7 +231,7 @@ public class MemberEdit
|
||||
ctx.CheckOwnMember(target);
|
||||
|
||||
var patch = new MemberPatch { Color = Partial<string>.Null() };
|
||||
await _repo.UpdateMember(target.Id, patch);
|
||||
await ctx.Repository.UpdateMember(target.Id, patch);
|
||||
|
||||
await ctx.Reply($"{Emojis.Success} Member color cleared.");
|
||||
}
|
||||
@@ -267,7 +265,7 @@ public class MemberEdit
|
||||
if (!Regex.IsMatch(color, "^[0-9a-fA-F]{6}$")) throw Errors.InvalidColorError(color);
|
||||
|
||||
var patch = new MemberPatch { Color = Partial<string>.Present(color.ToLowerInvariant()) };
|
||||
await _repo.UpdateMember(target.Id, patch);
|
||||
await ctx.Repository.UpdateMember(target.Id, patch);
|
||||
|
||||
await ctx.Reply(embed: new EmbedBuilder()
|
||||
.Title($"{Emojis.Success} Member color changed.")
|
||||
@@ -284,7 +282,7 @@ public class MemberEdit
|
||||
ctx.CheckOwnMember(target);
|
||||
|
||||
var patch = new MemberPatch { Birthday = Partial<LocalDate?>.Null() };
|
||||
await _repo.UpdateMember(target.Id, patch);
|
||||
await ctx.Repository.UpdateMember(target.Id, patch);
|
||||
|
||||
await ctx.Reply($"{Emojis.Success} Member birthdate cleared.");
|
||||
}
|
||||
@@ -318,7 +316,7 @@ public class MemberEdit
|
||||
if (birthday == null) throw Errors.BirthdayParseError(birthdayStr);
|
||||
|
||||
var patch = new MemberPatch { Birthday = Partial<LocalDate?>.Present(birthday) };
|
||||
await _repo.UpdateMember(target.Id, patch);
|
||||
await ctx.Repository.UpdateMember(target.Id, patch);
|
||||
|
||||
await ctx.Reply($"{Emojis.Success} Member birthdate changed.");
|
||||
}
|
||||
@@ -330,7 +328,7 @@ public class MemberEdit
|
||||
|
||||
MemberGuildSettings memberGuildConfig = null;
|
||||
if (ctx.Guild != null)
|
||||
memberGuildConfig = await _repo.GetMemberGuild(ctx.Guild.Id, target.Id);
|
||||
memberGuildConfig = await ctx.Repository.GetMemberGuild(ctx.Guild.Id, target.Id);
|
||||
|
||||
var eb = new EmbedBuilder()
|
||||
.Title("Member names")
|
||||
@@ -370,7 +368,7 @@ public class MemberEdit
|
||||
var successStr = text;
|
||||
if (ctx.Guild != null)
|
||||
{
|
||||
var memberGuildConfig = await _repo.GetMemberGuild(ctx.Guild.Id, target.Id);
|
||||
var memberGuildConfig = await ctx.Repository.GetMemberGuild(ctx.Guild.Id, target.Id);
|
||||
if (memberGuildConfig.DisplayName != null)
|
||||
successStr +=
|
||||
$" However, this member has a server name set in this server ({ctx.Guild.Name}), and will be proxied using that name, \"{memberGuildConfig.DisplayName}\", here.";
|
||||
@@ -412,7 +410,7 @@ public class MemberEdit
|
||||
if (await ctx.MatchClear("this member's display name"))
|
||||
{
|
||||
var patch = new MemberPatch { DisplayName = Partial<string>.Null() };
|
||||
await _repo.UpdateMember(target.Id, patch);
|
||||
await ctx.Repository.UpdateMember(target.Id, patch);
|
||||
|
||||
await PrintSuccess(
|
||||
$"{Emojis.Success} Member display name cleared. This member will now be proxied using their member name \"{target.Name}\".");
|
||||
@@ -425,7 +423,7 @@ public class MemberEdit
|
||||
var newDisplayName = ctx.RemainderOrNull(false).NormalizeLineEndSpacing();
|
||||
|
||||
var patch = new MemberPatch { DisplayName = Partial<string>.Present(newDisplayName) };
|
||||
await _repo.UpdateMember(target.Id, patch);
|
||||
await ctx.Repository.UpdateMember(target.Id, patch);
|
||||
|
||||
await PrintSuccess(
|
||||
$"{Emojis.Success} Member display name changed. This member will now be proxied using the name \"{newDisplayName}\".");
|
||||
@@ -442,7 +440,7 @@ public class MemberEdit
|
||||
$" To set one, type `pk;member {target.Reference()} servername <server name>`.";
|
||||
|
||||
// No perms check, display name isn't covered by member privacy
|
||||
var memberGuildConfig = await _repo.GetMemberGuild(ctx.Guild.Id, target.Id);
|
||||
var memberGuildConfig = await ctx.Repository.GetMemberGuild(ctx.Guild.Id, target.Id);
|
||||
|
||||
if (ctx.MatchRaw())
|
||||
{
|
||||
@@ -467,7 +465,7 @@ public class MemberEdit
|
||||
|
||||
if (await ctx.MatchClear("this member's server name"))
|
||||
{
|
||||
await _repo.UpdateMemberGuild(target.Id, ctx.Guild.Id, new MemberGuildPatch { DisplayName = null });
|
||||
await ctx.Repository.UpdateMemberGuild(target.Id, ctx.Guild.Id, new MemberGuildPatch { DisplayName = null });
|
||||
|
||||
if (target.DisplayName != null)
|
||||
await ctx.Reply(
|
||||
@@ -480,7 +478,7 @@ public class MemberEdit
|
||||
{
|
||||
var newServerName = ctx.RemainderOrNull(false).NormalizeLineEndSpacing();
|
||||
|
||||
await _repo.UpdateMemberGuild(target.Id, ctx.Guild.Id,
|
||||
await ctx.Repository.UpdateMemberGuild(target.Id, ctx.Guild.Id,
|
||||
new MemberGuildPatch { DisplayName = newServerName });
|
||||
|
||||
await ctx.Reply(
|
||||
@@ -519,7 +517,7 @@ public class MemberEdit
|
||||
;
|
||||
|
||||
var patch = new MemberPatch { KeepProxy = Partial<bool>.Present(newValue) };
|
||||
await _repo.UpdateMember(target.Id, patch);
|
||||
await ctx.Repository.UpdateMember(target.Id, patch);
|
||||
|
||||
if (newValue)
|
||||
await ctx.Reply(
|
||||
@@ -548,7 +546,7 @@ public class MemberEdit
|
||||
var newValue = ctx.MatchToggle();
|
||||
|
||||
var patch = new MemberPatch { AllowAutoproxy = Partial<bool>.Present(newValue) };
|
||||
await _repo.UpdateMember(target.Id, patch);
|
||||
await ctx.Repository.UpdateMember(target.Id, patch);
|
||||
|
||||
if (newValue)
|
||||
await ctx.Reply($"{Emojis.Success} Latch / front autoproxy have been **enabled** for this member.");
|
||||
@@ -583,11 +581,11 @@ public class MemberEdit
|
||||
// Get guild settings (mostly for warnings and such)
|
||||
MemberGuildSettings guildSettings = null;
|
||||
if (ctx.Guild != null)
|
||||
guildSettings = await _repo.GetMemberGuild(ctx.Guild.Id, target.Id);
|
||||
guildSettings = await ctx.Repository.GetMemberGuild(ctx.Guild.Id, target.Id);
|
||||
|
||||
async Task SetAll(PrivacyLevel level)
|
||||
{
|
||||
await _repo.UpdateMember(target.Id, new MemberPatch().WithAllPrivacy(level));
|
||||
await ctx.Repository.UpdateMember(target.Id, new MemberPatch().WithAllPrivacy(level));
|
||||
|
||||
if (level == PrivacyLevel.Private)
|
||||
await ctx.Reply(
|
||||
@@ -599,7 +597,7 @@ public class MemberEdit
|
||||
|
||||
async Task SetLevel(MemberPrivacySubject subject, PrivacyLevel level)
|
||||
{
|
||||
await _repo.UpdateMember(target.Id, new MemberPatch().WithPrivacy(subject, level));
|
||||
await ctx.Repository.UpdateMember(target.Id, new MemberPatch().WithPrivacy(subject, level));
|
||||
|
||||
var subjectName = subject switch
|
||||
{
|
||||
@@ -677,7 +675,7 @@ public class MemberEdit
|
||||
$"{Emojis.Warn} Are you sure you want to delete \"{target.NameFor(ctx)}\"? If so, reply to this message with the member's ID (`{target.Hid}`). __***This cannot be undone!***__");
|
||||
if (!await ctx.ConfirmWithReply(target.Hid)) throw Errors.MemberDeleteCancelled;
|
||||
|
||||
await _repo.DeleteMember(target.Id);
|
||||
await ctx.Repository.DeleteMember(target.Id);
|
||||
|
||||
await ctx.Reply($"{Emojis.Success} Member deleted.");
|
||||
}
|
||||
|
Reference in New Issue
Block a user