mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
- .gvc should now properly detect multiple activities - Rewrote repeat raw query bitshift to linqtodb query with division (thx kotz)
54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
#nullable disable
|
|
using Newtonsoft.Json;
|
|
|
|
namespace NadekoBot;
|
|
|
|
public abstract record SmartText
|
|
{
|
|
public bool IsEmbed
|
|
=> this is SmartEmbedText;
|
|
|
|
public bool IsPlainText
|
|
=> this is SmartPlainText;
|
|
|
|
public static SmartText operator +(SmartText text, string input)
|
|
=> text switch
|
|
{
|
|
SmartEmbedText set => set with { PlainText = set.PlainText + input },
|
|
SmartPlainText spt => new SmartPlainText(spt.Text + input),
|
|
_ => throw new ArgumentOutOfRangeException(nameof(text))
|
|
};
|
|
|
|
public static SmartText operator +(string input, SmartText text)
|
|
=> text switch
|
|
{
|
|
SmartEmbedText set => set with { PlainText = input + set.PlainText },
|
|
SmartPlainText spt => new SmartPlainText(input + spt.Text),
|
|
_ => throw new ArgumentOutOfRangeException(nameof(text))
|
|
};
|
|
|
|
public static SmartText CreateFrom(string input)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(input) || !input.TrimStart().StartsWith("{"))
|
|
return new SmartPlainText(input);
|
|
|
|
try
|
|
{
|
|
var smartEmbedText = JsonConvert.DeserializeObject<SmartEmbedText>(input);
|
|
|
|
if (smartEmbedText is null)
|
|
throw new();
|
|
|
|
smartEmbedText.NormalizeFields();
|
|
|
|
if (!smartEmbedText.IsValid)
|
|
return new SmartPlainText(input);
|
|
|
|
return smartEmbedText;
|
|
}
|
|
catch
|
|
{
|
|
return new SmartPlainText(input);
|
|
}
|
|
}
|
|
} |