67 lines
2.2 KiB
C#
67 lines
2.2 KiB
C#
using DSharpPlus.CommandsNext;
|
|
using DSharpPlus.CommandsNext.Attributes;
|
|
using DSharpPlus.Entities;
|
|
using System.Threading.Tasks;
|
|
using T3k3rg0.Helpers;
|
|
|
|
namespace T3k3rg0.Commands
|
|
{
|
|
public class ReactionRoleManager : BaseCommandModule
|
|
{
|
|
[Command("addreactionrole")]
|
|
[Description("Hozzáad egy új reaction role-t ! reactionrole <csatorna> <üzenet> <emoji> <@szerep>")]
|
|
[HasAdminRole]
|
|
public async Task AddReactionRole(CommandContext ctx, string channelInput, string messageInput, string emojiInput, DiscordRole role)
|
|
{
|
|
var channel = await IdExtractor.ExtractChannelId(channelInput, ctx.Client);
|
|
if (channel == null)
|
|
return;
|
|
|
|
var message = await IdExtractor.ExtractMessageId(messageInput, channel);
|
|
if (message == null)
|
|
return;
|
|
|
|
var emoji = await EmojiExtractor.ExtractAsync(emojiInput, ctx.Client);
|
|
if (emoji == null)
|
|
return;
|
|
|
|
bool inserted = ReactionRoleStorage.TryAddReactionRole(message.Id, emoji.ToString(), role.Id);
|
|
if (!inserted)
|
|
return;
|
|
|
|
await message.CreateReactionAsync(emoji);
|
|
}
|
|
[Command("removereactionrole")]
|
|
[Description("Eltávolít egy meglévő reaction role-t ! removereactionrole <csatorna> <üzenet> <emoji>")]
|
|
[HasAdminRole]
|
|
public async Task RemoveReactionRole(CommandContext ctx, string channelInput, string messageInput, string emojiInput)
|
|
{
|
|
var channel = await IdExtractor.ExtractChannelId(channelInput, ctx.Client);
|
|
if (channel == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var message = await IdExtractor.ExtractMessageId(messageInput, channel);
|
|
if (message == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var emoji = await EmojiExtractor.ExtractAsync(emojiInput, ctx.Client);
|
|
if (emoji == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
bool removed = ReactionRoleStorage.TryRemoveReactionRole(message.Id, emoji.ToString());
|
|
if (!removed)
|
|
{
|
|
return;
|
|
}
|
|
|
|
await message.DeleteOwnReactionAsync(emoji);
|
|
}
|
|
}
|
|
}
|
|
|