2021-05-03 12:33:30 +02:00
|
|
|
using System.Text.RegularExpressions;
|
2020-07-07 19:51:19 +02:00
|
|
|
|
2021-05-03 12:33:30 +02:00
|
|
|
using Myriad.Types;
|
|
|
|
|
|
2021-11-26 21:10:56 -05:00
|
|
|
namespace PluralKit.Bot;
|
|
|
|
|
|
|
|
|
|
public static class ContextArgumentsExt
|
2020-07-01 18:27:26 +02:00
|
|
|
{
|
2026-01-20 00:04:22 +03:00
|
|
|
public static Message.Reference? GetRepliedTo(this Context ctx)
|
2021-11-26 21:10:56 -05:00
|
|
|
{
|
|
|
|
|
if (ctx.Message.Type == Message.MessageType.Reply && ctx.Message.MessageReference?.MessageId != null)
|
2026-01-20 00:04:22 +03:00
|
|
|
return ctx.Message.MessageReference;
|
|
|
|
|
return null;
|
2025-10-03 02:21:12 +00:00
|
|
|
}
|
2021-05-03 12:33:30 +02:00
|
|
|
|
2025-10-03 02:21:12 +00:00
|
|
|
public static (ulong? messageId, ulong? channelId) ParseMessage(this Context ctx, string maybeMessageRef, bool parseRawMessageId)
|
|
|
|
|
{
|
|
|
|
|
if (parseRawMessageId && ulong.TryParse(maybeMessageRef, out var mid))
|
2021-11-26 21:10:56 -05:00
|
|
|
return (mid, null);
|
2021-08-27 11:03:47 -04:00
|
|
|
|
2025-10-03 02:21:12 +00:00
|
|
|
var match = Regex.Match(maybeMessageRef, "https://(?:\\w+.)?discord(?:app)?.com/channels/\\d+/(\\d+)/(\\d+)");
|
2021-11-26 21:10:56 -05:00
|
|
|
if (!match.Success)
|
|
|
|
|
return (null, null);
|
2021-05-03 12:33:30 +02:00
|
|
|
|
2021-11-26 21:10:56 -05:00
|
|
|
var channelId = ulong.Parse(match.Groups[1].Value);
|
|
|
|
|
var messageId = ulong.Parse(match.Groups[2].Value);
|
|
|
|
|
return (messageId, channelId);
|
|
|
|
|
}
|
2024-10-03 02:23:33 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum ReplyFormat
|
|
|
|
|
{
|
|
|
|
|
Standard,
|
|
|
|
|
Raw,
|
|
|
|
|
Plaintext
|
2021-08-27 11:03:47 -04:00
|
|
|
}
|