Migrate guild objects to the patch system
This commit is contained in:
16
PluralKit.Core/Models/Patch/GuildPatch.cs
Normal file
16
PluralKit.Core/Models/Patch/GuildPatch.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace PluralKit.Core
|
||||
{
|
||||
public class GuildPatch: PatchObject
|
||||
{
|
||||
public Partial<ulong?> LogChannel { get; set; }
|
||||
public Partial<ulong[]> LogBlacklist { get; set; }
|
||||
public Partial<ulong[]> Blacklist { get; set; }
|
||||
public Partial<bool> LogCleanupEnabled { get; set; }
|
||||
|
||||
public override UpdateQueryBuilder Apply(UpdateQueryBuilder b) => b
|
||||
.With("log_channel", LogChannel)
|
||||
.With("log_blacklist", LogBlacklist)
|
||||
.With("blacklist", Blacklist)
|
||||
.With("log_cleanup_enabled", LogCleanupEnabled);
|
||||
}
|
||||
}
|
13
PluralKit.Core/Models/Patch/MemberGuildPatch.cs
Normal file
13
PluralKit.Core/Models/Patch/MemberGuildPatch.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
#nullable enable
|
||||
namespace PluralKit.Core
|
||||
{
|
||||
public class MemberGuildPatch: PatchObject
|
||||
{
|
||||
public Partial<string?> DisplayName { get; set; }
|
||||
public Partial<string?> AvatarUrl { get; set; }
|
||||
|
||||
public override UpdateQueryBuilder Apply(UpdateQueryBuilder b) => b
|
||||
.With("display_name", DisplayName)
|
||||
.With("avatar_url", AvatarUrl);
|
||||
}
|
||||
}
|
@@ -8,7 +8,7 @@ namespace PluralKit.Core
|
||||
{
|
||||
public static Task<PKSystem> UpdateSystem(this IPKConnection conn, SystemId id, SystemPatch patch)
|
||||
{
|
||||
var (query, pms) = patch.Apply(new UpdateQueryBuilder("systems", "id = @id"))
|
||||
var (query, pms) = patch.Apply(UpdateQueryBuilder.Update("systems", "id = @id"))
|
||||
.WithConstant("id", id)
|
||||
.Build("returning *");
|
||||
return conn.QueryFirstAsync<PKSystem>(query, pms);
|
||||
@@ -24,7 +24,7 @@ namespace PluralKit.Core
|
||||
|
||||
public static Task<PKMember> UpdateMember(this IPKConnection conn, MemberId id, MemberPatch patch)
|
||||
{
|
||||
var (query, pms) = patch.Apply(new UpdateQueryBuilder("members", "id = @id"))
|
||||
var (query, pms) = patch.Apply(UpdateQueryBuilder.Update("members", "id = @id"))
|
||||
.WithConstant("id", id)
|
||||
.Build("returning *");
|
||||
return conn.QueryFirstAsync<PKMember>(query, pms);
|
||||
@@ -32,5 +32,33 @@ namespace PluralKit.Core
|
||||
|
||||
public static Task DeleteMember(this IPKConnection conn, MemberId id) =>
|
||||
conn.ExecuteAsync("delete from members where id = @Id", new {Id = id});
|
||||
|
||||
public static Task UpsertSystemGuild(this IPKConnection conn, SystemId system, ulong guild,
|
||||
SystemGuildPatch patch)
|
||||
{
|
||||
var (query, pms) = patch.Apply(UpdateQueryBuilder.Upsert("system_guild", "system, guild"))
|
||||
.WithConstant("system", system)
|
||||
.WithConstant("guild", guild)
|
||||
.Build();
|
||||
return conn.ExecuteAsync(query, pms);
|
||||
}
|
||||
|
||||
public static Task UpsertMemberGuild(this IPKConnection conn, MemberId member, ulong guild,
|
||||
MemberGuildPatch patch)
|
||||
{
|
||||
var (query, pms) = patch.Apply(UpdateQueryBuilder.Upsert("member_guild", "member, guild"))
|
||||
.WithConstant("member", member)
|
||||
.WithConstant("guild", guild)
|
||||
.Build();
|
||||
return conn.ExecuteAsync(query, pms);
|
||||
}
|
||||
|
||||
public static Task UpsertGuild(this IPKConnection conn, ulong guild, GuildPatch patch)
|
||||
{
|
||||
var (query, pms) = patch.Apply(UpdateQueryBuilder.Upsert("servers", "id"))
|
||||
.WithConstant("id", guild)
|
||||
.Build();
|
||||
return conn.ExecuteAsync(query, pms);
|
||||
}
|
||||
}
|
||||
}
|
15
PluralKit.Core/Models/Patch/SystemGuildPatch.cs
Normal file
15
PluralKit.Core/Models/Patch/SystemGuildPatch.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
#nullable enable
|
||||
namespace PluralKit.Core
|
||||
{
|
||||
public class SystemGuildPatch: PatchObject
|
||||
{
|
||||
public Partial<bool> ProxyEnabled { get; set; }
|
||||
public Partial<AutoproxyMode> AutoproxyMode { get; set; }
|
||||
public Partial<MemberId?> AutoproxyMember { get; set; }
|
||||
|
||||
public override UpdateQueryBuilder Apply(UpdateQueryBuilder b) => b
|
||||
.With("proxy_enabled", ProxyEnabled)
|
||||
.With("autoproxy_mode", AutoproxyMode)
|
||||
.With("autoproxy_member", AutoproxyMember);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user