react command added
This commit is contained in:
parent
29de185cba
commit
8274a22f1b
8 changed files with 180 additions and 76 deletions
48
helpers/emojiextractor.cs
Normal file
48
helpers/emojiextractor.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
using DSharpPlus;
|
||||
using DSharpPlus.Entities;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace T3k3rg0.Helpers
|
||||
{
|
||||
public static class EmojiExtractor
|
||||
{
|
||||
public static async Task<DiscordEmoji?> ExtractAsync(string emojInput, DiscordClient client)
|
||||
{
|
||||
try
|
||||
{
|
||||
var unicodeEmoji = DiscordEmoji.FromUnicode(emojInput);
|
||||
return unicodeEmoji;
|
||||
}
|
||||
catch { }
|
||||
|
||||
try
|
||||
{
|
||||
var namedEmoji = DiscordEmoji.FromName(client, emojInput);
|
||||
return namedEmoji;
|
||||
}
|
||||
catch { }
|
||||
|
||||
try
|
||||
{
|
||||
ulong emojiId;
|
||||
|
||||
// Ha teljes emojiformátumban van (pl. <:nev:123456789012345678>)
|
||||
var match = System.Text.RegularExpressions.Regex.Match(emojInput, @"<a?:\w+:(\d{17,20})>");
|
||||
if (match.Success && ulong.TryParse(match.Groups[1].Value, out emojiId))
|
||||
{
|
||||
return DiscordEmoji.FromGuildEmote(client, emojiId);
|
||||
}
|
||||
|
||||
// Ha csak simán az ID-t írta be
|
||||
if (ulong.TryParse(emojInput, out emojiId))
|
||||
{
|
||||
return DiscordEmoji.FromGuildEmote(client, emojiId);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
22
helpers/logger.cs
Normal file
22
helpers/logger.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace T3k3rg0
|
||||
{
|
||||
public static class Logger
|
||||
{
|
||||
public static ILoggerFactory CreateLoggerFactory()
|
||||
{
|
||||
return LoggerFactory.Create(builder =>
|
||||
{
|
||||
builder
|
||||
.AddSimpleConsole(options =>
|
||||
{
|
||||
options.TimestampFormat = "[yyyy-MM-dd HH:mm:ss] ";
|
||||
options.SingleLine = true;
|
||||
options.ColorBehavior = Microsoft.Extensions.Logging.Console.LoggerColorBehavior.Enabled;
|
||||
})
|
||||
.SetMinimumLevel(LogLevel.Debug);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue