Merge pull request #305 from Qyriad/features/pk-proxy-dm

allow pk;system proxy to take a server ID
This commit is contained in:
Astrid 2021-05-07 10:35:55 +02:00 committed by GitHub
commit 550aa09618
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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.Extensions;
using Myriad.Types; using Myriad.Types;
@ -168,5 +169,22 @@ namespace PluralKit.Bot
ctx.PopArgument(); ctx.PopArgument();
return channel; 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 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 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 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 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 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)"); 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 System.Threading.Tasks;
using Myriad.Builders; using Myriad.Builders;
using Myriad.Types;
using NodaTime; using NodaTime;
using NodaTime.Text; using NodaTime.Text;
@ -232,8 +233,18 @@ namespace PluralKit.Bot
public async Task SystemProxy(Context ctx) public async Task SystemProxy(Context ctx)
{ {
ctx.CheckSystem().CheckGuildContext(); ctx.CheckSystem();
var gs = await _db.Execute(c => _repo.GetSystemGuild(c, ctx.Guild.Id, ctx.System.Id));
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; bool newValue;
if (ctx.Match("on", "enabled", "true", "yes")) newValue = true; if (ctx.Match("on", "enabled", "true", "yes")) newValue = true;
@ -242,19 +253,19 @@ namespace PluralKit.Bot
else else
{ {
if (gs.ProxyEnabled) 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 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; return;
} }
var patch = new SystemGuildPatch {ProxyEnabled = newValue}; 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) 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 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) 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 privacy <subject> <public|private>` - Changes your systems privacy settings.
- `pk;system tag [tag]` - Changes the system tag of your system. - `pk;system tag [tag]` - Changes the system tag of your system.
- `pk;system timezone [location]` - Changes the time zone 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 delete` - Deletes your system.
- `pk;system [system] fronter` - Shows the current fronter of a system. - `pk;system [system] fronter` - Shows the current fronter of a system.
- `pk;system [system] fronthistory` - Shows the last 10 fronters of a system. - `pk;system [system] fronthistory` - Shows the last 10 fronters of a system.