added sendmsg command
This commit is contained in:
parent
e97a4e7a66
commit
29de185cba
4 changed files with 94 additions and 3 deletions
|
|
@ -2,7 +2,7 @@ using DSharpPlus.CommandsNext;
|
|||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Commands
|
||||
namespace T3k3rg0.Commands
|
||||
{
|
||||
public class Hello : BaseCommandModule
|
||||
{
|
||||
|
|
|
|||
28
commands/send.cs
Normal file
28
commands/send.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace T3k3rg0.Commands
|
||||
{
|
||||
public class Send : BaseCommandModule
|
||||
{
|
||||
[Command("sendmsg")]
|
||||
[Description("Üzenetet küld ! sendmsg <csatorna> <üzenet>")]
|
||||
[HasAdminRole]
|
||||
public async Task SendAsync(CommandContext ctx, string channelParam, [RemainingText] string message)
|
||||
{
|
||||
// Használjuk a ChannelHelper-t a csatorna kezeléséhez
|
||||
var channel = await IdExtractor.GetChannelAsync(ctx, channelParam);
|
||||
|
||||
if (channel == null)
|
||||
{
|
||||
// Ha a csatorna érvénytelen, a ChannelHelper már válaszolt, itt nem kell további kód.
|
||||
return;
|
||||
}
|
||||
|
||||
// Üzenet küldése a megtalált csatornára
|
||||
await channel.SendMessageAsync(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@ namespace T3k3rg0
|
|||
{
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
Env.Load(); // .env fájl betöltése
|
||||
Env.Load();
|
||||
|
||||
var loggerFactory = Logger.CreateLoggerFactory();
|
||||
|
||||
|
|
@ -30,7 +30,8 @@ namespace T3k3rg0
|
|||
EnableMentionPrefix = true
|
||||
});
|
||||
|
||||
commands.RegisterCommands<Commands.Hello>();
|
||||
commands.RegisterCommands<T3k3rg0.Commands.Hello>();
|
||||
commands.RegisterCommands<T3k3rg0.Commands.Send>();
|
||||
ReactionRoleHandler.Register(discord);
|
||||
|
||||
await discord.ConnectAsync();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue