added sendmsg command
This commit is contained in:
parent
e97a4e7a66
commit
29de185cba
4 changed files with 94 additions and 3 deletions
62
idextractor.cs
Normal file
62
idextractor.cs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.Entities;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace T3k3rg0
|
||||
{
|
||||
class IdExtractor
|
||||
{
|
||||
public static async Task<DiscordChannel> GetChannelAsync(CommandContext ctx, string channelParam)
|
||||
{
|
||||
ulong channelId;
|
||||
|
||||
if (channelParam.StartsWith("https://discord.com/channels/"))
|
||||
{
|
||||
// Linkből szedjük ki
|
||||
var parts = channelParam.Split('/');
|
||||
if (parts.Length >= 4 && ulong.TryParse(parts[4], out ulong parsedChannelId))
|
||||
{
|
||||
channelId = parsedChannelId;
|
||||
}
|
||||
else
|
||||
{
|
||||
await ctx.RespondAsync("Érvénytelen csatorna link.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (channelParam.StartsWith("<#") && channelParam.EndsWith(">"))
|
||||
{
|
||||
// Mentionből szedjük ki
|
||||
var idPart = channelParam.Trim('<', '#', '>');
|
||||
if (ulong.TryParse(idPart, out ulong parsedMentionId))
|
||||
{
|
||||
channelId = parsedMentionId;
|
||||
}
|
||||
else
|
||||
{
|
||||
await ctx.RespondAsync("Érvénytelen csatorna mention.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (ulong.TryParse(channelParam, out ulong parsedId))
|
||||
{
|
||||
// Simán ID
|
||||
channelId = parsedId;
|
||||
}
|
||||
else
|
||||
{
|
||||
await ctx.RespondAsync("Érvénytelen csatorna azonosító, mention vagy link.");
|
||||
return null;
|
||||
}
|
||||
|
||||
var channel = await ctx.Client.GetChannelAsync(channelId);
|
||||
if (channel == null)
|
||||
{
|
||||
await ctx.RespondAsync("Nem találom a csatornát.");
|
||||
return null;
|
||||
}
|
||||
|
||||
return channel;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue