/// <summary> /// Creates the embed corresponding to the currently displayed page of the target <paramref name="ReactionMenu"/>. /// </summary> /// <param name="ReactionMenu">A specific instance of a ReactionMenu to obtain the active embed from.</param> /// <returns>An Embed object, which can be sent or replace a different message via editing.</returns> public Embed CreateMenuEmbed(ReactionMenu ReactionMenu) { EmbedBuilder[] Menus = JsonConvert.DeserializeObject <EmbedBuilder[]> (ReactionMenuDB.EmbedMenus.Find(ReactionMenu.EmbedMenuIndex).EmbedMenuJSON); uint[] Colors = JsonConvert.DeserializeObject <uint[]> (ReactionMenuDB.ColorMenus.Find(ReactionMenu.ColorMenuIndex).ColorMenuJSON); int CurrentPage = ReactionMenu.CurrentPage - 1; return(Menus[CurrentPage] .WithColor(new Color(Colors[CurrentPage])) .WithFooter($"Page {ReactionMenu.CurrentPage}/{Menus.Length}") .WithCurrentTimestamp().Build()); }
/// <summary> /// Performs navigation of a specific ReactionMenu when a <paramref name="Reaction"/> is added onto any message, if the target <paramref name="CachedMessage"/> corresponds to a ReactionMenu. /// </summary> /// <param name="CachedMessage">The Chached Message entity for the message the <paramref name="Reaction"/> was added to.</param> /// <param name="Channel">The Channel entity the caches message is in.</param> /// <param name="Reaction">The reaction data attached to the new reaction added to the <paramref name="CachedMessage"/>.</param> /// <returns>A <c>Task</c> object, which can be awaited until this method completes successfully.</returns> public async Task ReactionMenu(Cacheable <IUserMessage, ulong> CachedMessage, ISocketMessageChannel Channel, SocketReaction Reaction) { ReactionMenu ReactionMenu = ReactionMenuDB.ReactionMenus.Find(CachedMessage.Id); if (ReactionMenu == null || Reaction.User.Value.IsBot) { return; } IUserMessage Message = await CachedMessage.GetOrDownloadAsync(); EmbedBuilder[] Menus = JsonConvert.DeserializeObject <EmbedBuilder[]> (ReactionMenuDB.EmbedMenus.Find(ReactionMenu.EmbedMenuIndex).EmbedMenuJSON); if (Reaction.Emote.Name.Equals("⬅️")) { ReactionMenu.CurrentPage--; if (ReactionMenu.CurrentPage < 1) { ReactionMenu.CurrentPage = Menus.Length; } } else if (Reaction.Emote.Name.Equals("➡️")) { ReactionMenu.CurrentPage++; if (ReactionMenu.CurrentPage > Menus.Length) { ReactionMenu.CurrentPage = 1; } } await Message.ModifyAsync(MessageP => MessageP.Embed = CreateMenuEmbed(ReactionMenu)); try { await Message.RemoveReactionAsync(Reaction.Emote, Reaction.User.Value); } catch (HttpException) { } }