Exemple #1
0
 static DiscordEmoji GetReactionEmoji(BaseDiscordClient cl)
 => EmojiConverter.GetEmoji(cl, Program.Settings.RimboardEmoticon);
Exemple #2
0
        internal static async Task RoleEmbedRemoveRole(CommandContext ctx,
                                                       DiscordChannel channel,
                                                       ulong messageId,
                                                       DiscordEmoji emoji)
        {
            var a = channel.GetMessageAsync(messageId);
            var b = CheckEmoteMessageExists(messageId, emoji);

            await Task.WhenAll(a, b);

            DiscordMessage message         = a.Result;
            bool           messageHasEmote = b.Result;

            // Check if the message actually has that emote.
            if (messageHasEmote)
            {   // It does, so let's query the database for everything that should be in the message.
                EmojiData  emojiRemove = new EmojiData(emoji);
                RoleInfo[] roleInfos   = await GetMessageEmotes(messageId);

                string botComments = String.Empty;

                var c = RemoveRow(messageId, emojiRemove.Value);
                await Task.WhenAll(c);

                // Let's check if this is the message's only react.
                if (roleInfos.Length == 1)
                {   // It is, so let's delete the message as well.
                    await message.DeleteAsync();

                    botComments = @"Additionally, the message was deleted because you deleted its only react.";
                }
                else
                {   // It's not the only react, so let's rebuild the message string.
                    // Get the first line of the content.
                    var stringBuilder = new StringBuilder(
                        new string(message.Content.TakeWhile(a => a != '\n').ToArray()));

                    stringBuilder.Append('\n');

                    foreach (var roleInfo in roleInfos)
                    {
                        // Check if this is the emoji we want to remove.
                        if (!roleInfo.EmojiData.Equals(emojiRemove))
                        {   // It's not the emoji we want to remove, so let's add it to the stringbuilder.
                            DiscordRole role = ctx.Guild.GetRole(roleInfo.RoleId);

                            string emojiString = EmojiConverter.GetEmojiString(
                                emoji: EmojiConverter.GetEmoji(
                                    cl: ctx.Client,
                                    data: roleInfo.EmojiData));

                            stringBuilder.AppendLine($"{role.Mention} {emojiString}");
                        } // end if
                    }     // end foreach

                    var d = message.ModifyAsync(stringBuilder.ToString());
                    var e = message.DeleteReactionsEmojiAsync(emoji);

                    await Task.WhenAll(d, e);

                    await ctx.RespondAsync(
                        embed : Generics.GenericEmbedTemplate(
                            color: Generics.NeutralColor,
                            description: $"Tasks:\nMessage Edit Success: {d.IsCompletedSuccessfully || e.IsCompletedSuccessfully}\n" +
                            $"Database Check Success: {b.IsCompletedSuccessfully}\n" +
                            $"Database Delete Success: {c.IsCompletedSuccessfully}" +
                            (botComments.Length > 0 ? $"\n{botComments}" : String.Empty),
                            title: @"Add new roles onto embed"));
                } // end else
            }     // end if
            else
            {   // It doesn't have the emote we want to remove, so let's notify the user.
                await ctx.RespondAsync(
                    embed : Generics.GenericEmbedTemplate(
                        color: Generics.NegativeColor,
                        description: Generics.NegativeDirectResponseTemplate(
                            mention: ctx.Member.Mention,
                            body: $"that message doesn't have emote {EmojiConverter.GetEmojiString(emoji)} on it...")));
            }
        }