feat(bot): allow 'pk;logclean' in DMs
This commit is contained in:
parent
cfd9dff6c5
commit
b04b6e38d2
@ -103,6 +103,13 @@ public static class ContextArgumentsExt
|
|||||||
ctx.Match("r", "raw") || ctx.MatchFlag("r", "raw");
|
ctx.Match("r", "raw") || ctx.MatchFlag("r", "raw");
|
||||||
|
|
||||||
public static bool MatchToggle(this Context ctx, bool? defaultValue = null)
|
public static bool MatchToggle(this Context ctx, bool? defaultValue = null)
|
||||||
|
{
|
||||||
|
var value = ctx.MatchToggleOrNull(defaultValue);
|
||||||
|
if (value == null) throw new PKError("You must pass either \"on\" or \"off\" to this command.");
|
||||||
|
return value.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool? MatchToggleOrNull(this Context ctx, bool? defaultValue = null)
|
||||||
{
|
{
|
||||||
if (defaultValue != null && ctx.MatchClearInner())
|
if (defaultValue != null && ctx.MatchClearInner())
|
||||||
return defaultValue.Value;
|
return defaultValue.Value;
|
||||||
@ -114,8 +121,7 @@ public static class ContextArgumentsExt
|
|||||||
return true;
|
return true;
|
||||||
else if (ctx.Match(noToggles) || ctx.MatchFlag(noToggles))
|
else if (ctx.Match(noToggles) || ctx.MatchFlag(noToggles))
|
||||||
return false;
|
return false;
|
||||||
else
|
else return null;
|
||||||
throw new PKError("You must pass either \"on\" or \"off\" to this command.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static (ulong? messageId, ulong? channelId) MatchMessage(this Context ctx, bool parseRawMessageId)
|
public static (ulong? messageId, ulong? channelId) MatchMessage(this Context ctx, bool parseRawMessageId)
|
||||||
|
@ -231,27 +231,26 @@ public class ServerConfig
|
|||||||
|
|
||||||
public async Task SetLogCleanup(Context ctx)
|
public async Task SetLogCleanup(Context ctx)
|
||||||
{
|
{
|
||||||
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
|
||||||
|
|
||||||
var botList = string.Join(", ", LoggerCleanService.Bots.Select(b => b.Name).OrderBy(x => x.ToLowerInvariant()));
|
var botList = string.Join(", ", LoggerCleanService.Bots.Select(b => b.Name).OrderBy(x => x.ToLowerInvariant()));
|
||||||
|
|
||||||
var guild = await ctx.Repository.GetGuild(ctx.Guild.Id);
|
|
||||||
|
|
||||||
bool newValue;
|
|
||||||
if (ctx.Match("enable", "on", "yes"))
|
|
||||||
{
|
|
||||||
newValue = true;
|
|
||||||
}
|
|
||||||
else if (ctx.Match("disable", "off", "no"))
|
|
||||||
{
|
|
||||||
newValue = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var eb = new EmbedBuilder()
|
var eb = new EmbedBuilder()
|
||||||
.Title("Log cleanup settings")
|
.Title("Log cleanup settings")
|
||||||
.Field(new Embed.Field("Supported bots", botList));
|
.Field(new Embed.Field("Supported bots", botList));
|
||||||
|
|
||||||
|
if (ctx.Guild == null)
|
||||||
|
{
|
||||||
|
eb.Description("Run this command in a server to enable/disable log cleanup.");
|
||||||
|
await ctx.Reply(embed: eb.Build());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
||||||
|
|
||||||
|
var guild = await ctx.Repository.GetGuild(ctx.Guild.Id);
|
||||||
|
|
||||||
|
bool? newValue = ctx.MatchToggleOrNull();
|
||||||
|
|
||||||
|
if (newValue == null)
|
||||||
|
{
|
||||||
var guildCfg = await ctx.Repository.GetGuild(ctx.Guild.Id);
|
var guildCfg = await ctx.Repository.GetGuild(ctx.Guild.Id);
|
||||||
if (guildCfg.LogCleanupEnabled)
|
if (guildCfg.LogCleanupEnabled)
|
||||||
eb.Description(
|
eb.Description(
|
||||||
@ -263,9 +262,9 @@ public class ServerConfig
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await ctx.Repository.UpdateGuild(ctx.Guild.Id, new GuildPatch { LogCleanupEnabled = newValue });
|
await ctx.Repository.UpdateGuild(ctx.Guild.Id, new GuildPatch { LogCleanupEnabled = newValue.Value });
|
||||||
|
|
||||||
if (newValue)
|
if (newValue.Value)
|
||||||
await ctx.Reply(
|
await ctx.Reply(
|
||||||
$"{Emojis.Success} Log cleanup has been **enabled** for this server. Messages deleted by PluralKit will now be cleaned up from logging channels managed by the following bots:\n- **{botList}**\n\n{Emojis.Note} Make sure PluralKit has the **Manage Messages** permission in the channels in question.\n{Emojis.Note} Also, make sure to blacklist the logging channel itself from the bots in question to prevent conflicts.");
|
$"{Emojis.Success} Log cleanup has been **enabled** for this server. Messages deleted by PluralKit will now be cleaned up from logging channels managed by the following bots:\n- **{botList}**\n\n{Emojis.Note} Make sure PluralKit has the **Manage Messages** permission in the channels in question.\n{Emojis.Note} Also, make sure to blacklist the logging channel itself from the bots in question to prevent conflicts.");
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user