react command added
This commit is contained in:
parent
29de185cba
commit
8274a22f1b
8 changed files with 180 additions and 76 deletions
81
helpers/idextractor.cs
Normal file
81
helpers/idextractor.cs
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
using System.Threading.Tasks;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.Entities;
|
||||
|
||||
namespace T3k3rg0.Helpers
|
||||
{
|
||||
public static class IdExtractor
|
||||
{
|
||||
public static ulong? ExtractChannel(string channelInput)
|
||||
{
|
||||
if (channelInput.StartsWith("https://discord.com/channels/"))
|
||||
{
|
||||
var parts = channelInput.Split('/');
|
||||
if (parts.Length >= 6 && ulong.TryParse(parts[5], out ulong parsedChannelLinkId))
|
||||
return parsedChannelLinkId;
|
||||
}
|
||||
|
||||
else if (channelInput.StartsWith("<#") && channelInput.EndsWith(">"))
|
||||
{
|
||||
var trimmed = channelInput.Trim('<', '#', '>');
|
||||
if (ulong.TryParse(trimmed, out ulong parsedChannelMentionId))
|
||||
return parsedChannelMentionId;
|
||||
}
|
||||
else if (ulong.TryParse(channelInput, out ulong parsedRawCannelId))
|
||||
{
|
||||
return parsedRawCannelId;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static async Task<DiscordChannel?> ExtractChannelId(string channelInput, DiscordClient client)
|
||||
{
|
||||
var channelId = ExtractChannel(channelInput);
|
||||
if (channelId is null)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
var channel = await client.GetChannelAsync(channelId.Value);
|
||||
return channel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static ulong? ExtractMessage(string messageInput)
|
||||
{
|
||||
|
||||
if (messageInput.StartsWith("https://discord.com/channels/"))
|
||||
{
|
||||
var parts = messageInput.Split('/');
|
||||
if (parts.Length >= 7 && ulong.TryParse(parts[6], out ulong parsedMessageLinkId))
|
||||
return parsedMessageLinkId;
|
||||
}
|
||||
|
||||
else if (ulong.TryParse(messageInput, out ulong parsedRawMessageId))
|
||||
{
|
||||
return parsedRawMessageId;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static async Task<DiscordMessage?> ExtractMessageId(string messageInput, DiscordChannel channel)
|
||||
{
|
||||
var messageId = ExtractMessage(messageInput);
|
||||
if (messageId is null)
|
||||
return null;
|
||||
try
|
||||
{
|
||||
var message = await channel.GetMessageAsync(messageId.Value);
|
||||
return message;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue