allow pk;system proxy to take a server ID

So people can disable proxying in a server without outing themselves :)
This commit is contained in:
Mikaela Szekely 2021-04-05 22:25:13 -06:00
parent 3d624b39e4
commit 6395872f2d
4 changed files with 39 additions and 10 deletions

View File

@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using Myriad.Extensions;
using Myriad.Types;
@ -168,5 +169,22 @@ namespace PluralKit.Bot
ctx.PopArgument();
return channel;
}
public static Guild MatchGuild(this Context ctx)
{
try
{
var id = ulong.Parse(ctx.PeekArgument());
ctx.Cache.TryGetGuild(id, out var guild);
if (guild != null)
ctx.PopArgument();
return guild;
}
catch (FormatException)
{
return null;
}
}
}
}

View File

@ -18,7 +18,7 @@ namespace PluralKit.Bot
public static Command SystemAvatar = new Command("system icon", "system icon [url|@mention]", "Changes your system's icon");
public static Command SystemDelete = new Command("system delete", "system delete", "Deletes your system");
public static Command SystemTimezone = new Command("system timezone", "system timezone [timezone]", "Changes your system's time zone");
public static Command SystemProxy = new Command("system proxy", "system proxy [on|off]", "Enables or disables message proxying in a specific server");
public static Command SystemProxy = new Command("system proxy", "system proxy [server id] [on|off]", "Enables or disables message proxying in a specific server");
public static Command SystemList = new Command("system list", "system [system] list [full]", "Lists a system's members");
public static Command SystemFind = new Command("system find", "system [system] find [full] <search term>", "Searches a system's members given a search term");
public static Command SystemFronter = new Command("system fronter", "system [system] fronter", "Shows a system's fronter(s)");

View File

@ -4,6 +4,7 @@ using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Myriad.Builders;
using Myriad.Types;
using NodaTime;
using NodaTime.Text;
@ -232,8 +233,18 @@ namespace PluralKit.Bot
public async Task SystemProxy(Context ctx)
{
ctx.CheckSystem().CheckGuildContext();
var gs = await _db.Execute(c => _repo.GetSystemGuild(c, ctx.Guild.Id, ctx.System.Id));
ctx.CheckSystem();
var guild = ctx.MatchGuild() ?? ctx.Guild ??
throw new PKError("You must run this command in a server or pass a server ID.");
var gs = await _db.Execute(c => _repo.GetSystemGuild(c, guild.Id, ctx.System.Id));
string serverText;
if (guild.Id == ctx.Guild?.Id)
serverText = $"this server ({guild.Name.EscapeMarkdown()})";
else
serverText = $"the server {guild.Name.EscapeMarkdown()}";
bool newValue;
if (ctx.Match("on", "enabled", "true", "yes")) newValue = true;
@ -242,19 +253,19 @@ namespace PluralKit.Bot
else
{
if (gs.ProxyEnabled)
await ctx.Reply("Proxying in this server is currently **enabled** for your system. To disable it, type `pk;system proxy off`.");
await ctx.Reply($"Proxying in {serverText} is currently **enabled** for your system. To disable it, type `pk;system proxy off`.");
else
await ctx.Reply("Proxying in this server is currently **disabled** for your system. To enable it, type `pk;system proxy on`.");
await ctx.Reply($"Proxying in {serverText} is currently **disabled** for your system. To enable it, type `pk;system proxy on`.");
return;
}
var patch = new SystemGuildPatch {ProxyEnabled = newValue};
await _db.Execute(conn => _repo.UpsertSystemGuild(conn, ctx.System.Id, ctx.Guild.Id, patch));
await _db.Execute(conn => _repo.UpsertSystemGuild(conn, ctx.System.Id, guild.Id, patch));
if (newValue)
await ctx.Reply($"Message proxying in this server ({ctx.Guild.Name.EscapeMarkdown()}) is now **enabled** for your system.");
await ctx.Reply($"Message proxying in {serverText} is now **enabled** for your system.");
else
await ctx.Reply($"Message proxying in this server ({ctx.Guild.Name.EscapeMarkdown()}) is now **disabled** for your system.");
await ctx.Reply($"Message proxying in {serverText} is now **disabled** for your system.");
}
public async Task SystemTimezone(Context ctx)

View File

@ -21,7 +21,7 @@ Words in **\<angle brackets>** or **[square brackets]** mean fill-in-the-blank.
- `pk;system privacy <subject> <public|private>` - Changes your systems privacy settings.
- `pk;system tag [tag]` - Changes the system tag of your system.
- `pk;system timezone [location]` - Changes the time zone of your system.
- `pk;system proxy [on|off]` - Toggles message proxying for a specific server.
- `pk;system proxy [server id] [on|off]` - Toggles message proxying for a specific server.
- `pk;system delete` - Deletes your system.
- `pk;system [system] fronter` - Shows the current fronter of a system.
- `pk;system [system] fronthistory` - Shows the last 10 fronters of a system.