Example #1
0
        public async ValueTask <CommandResult> HandleAsync(ICommandContext context)
        {
            var message = await DiscordMessageHelper.FromLinkAsync(context.Guild, MessageLink);

            if (message is null)
            {
                return(CommandResult.InvalidParameter("Invalid message link."));
            }

            var emoji = DiscordEmojiHelper.Parse(context.Client, EmojiText);

            if (emoji is null)
            {
                return(CommandResult.InvalidParameter("Invalid emoji."));
            }

            // TODO: Check if there will be collision in db and show the user nice error message.
            var reactionRole = new ReactionRole(message, emoji, Role);
            await _unitOfWork.ReactionRoles.AddAsync(reactionRole);

            await message.CreateReactionAsync(emoji);

            await _unitOfWork.CompleteAsync();

            var messageLink = Markdown.Link("message", message.JumpLink.ToString());

            return(CommandResult.Success($"Added self-assignable role {Role.Mention} with emoji {emoji} to {messageLink}."));
        }
Example #2
0
        public async ValueTask <CommandResult> HandleAsync(ICommandContext context)
        {
            var message = await DiscordMessageHelper.FromLinkAsync(context.Guild, MessageLink);

            if (message is null)
            {
                return(CommandResult.InvalidParameter("Invalid message link."));
            }

            var emoji = await _unitOfWork.ReactionRoles.GetEmojiAsync(context.Client, message, Role);

            var messageLink = Markdown.Link("message", message.JumpLink.ToString());

            if (emoji == null)
            {
                return(CommandResult.InvalidOperation($"This {messageLink} does not have self-assignable role {Role.Mention}."));
            }

            await message.DeleteReactionsEmojiAsync(emoji);

            var reactionRole = new ReactionRole(message, emoji, Role);

            _unitOfWork.ReactionRoles.Remove(reactionRole);
            await _unitOfWork.CompleteAsync();

            return(CommandResult.Success($"Removed self-assignable role {Role.Mention} from {messageLink}."));
        }