fix(bot): make pk;import handle <> wrapped URLs

This commit is contained in:
Iris System 2023-01-09 04:32:41 +13:00
parent 10287d0146
commit 683b616a1b
2 changed files with 6 additions and 3 deletions

View File

@ -33,10 +33,10 @@ public class ImportExport
public async Task Import(Context ctx)
{
var url = ctx.RemainderOrNull() ?? ctx.Message.Attachments.FirstOrDefault()?.Url;
if (url == null) throw Errors.NoImportFilePassed;
var inputUrl = ctx.RemainderOrNull() ?? ctx.Message.Attachments.FirstOrDefault()?.Url;
if (inputUrl == null) throw Errors.NoImportFilePassed;
if (!Core.MiscUtils.TryMatchUri(url, out var _))
if (!Core.MiscUtils.TryMatchUri(inputUrl, out var url))
throw Errors.InvalidUrl;
await ctx.BusyIndicator(async () =>

View File

@ -13,6 +13,9 @@ public static class MiscUtils
public static bool TryMatchUri(string input, out Uri uri)
{
if (input.StartsWith('<') && input.EndsWith('>'))
input = input[1..^1];
try
{
uri = new Uri(input);