Ejemplo n.º 1
0
        public static void GenEmbedUnchecked <UserT, ChannelT>(UserT User, ChannelT Channel, EmbedMenu <UserT, ChannelT> .EmbedMenuDel EMDel)
            where UserT : IUser
            where ChannelT : ITextChannel
        {
            //Allocate arrays!

            var EMHistory = new InsideList <EmbedMenu <UserT, ChannelT> >(5);

            var Acts = new InsideList <EmbedMenu <UserT, ChannelT> .EmbedMenuAct>(5);

            var EM = new EmbedMenu <UserT, ChannelT>(EMDel, User, Channel, ref EMHistory, ref Acts);

            ref var EMRef = ref EM;
Ejemplo n.º 2
0
        public static void GenEmbed <UserT, ChannelT>(UserT User, ChannelT Channel, EmbedMenu <UserT, ChannelT> .EmbedMenuDel EMDel)
            where UserT : IUser
            where ChannelT : ITextChannel
        {
            //TODO: Find out if Unsafe.SkipInit() would cause performance regression

            Unsafe.SkipInit(out byte Trash);

            if (!ActiveUsers.TryAdd(User.Id, Trash))
            {
                ssss

                return;
            }

            GenEmbedUnchecked(User, Channel, EMDel);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a reaction menu from an array of template embeds and sets up all required database fields, then sends the embed to the target <paramref name="Channel"/>.
        /// </summary>
        /// <param name="EmbedBuilders">The template for the set of pages the ReactionMenu may display.</param>
        /// <param name="Channel">The channel to send the ReactionMenu into.</param>
        /// <returns>A <c>Task</c> object, which can be awaited until this method completes successfully.</returns>

        public async Task CreateReactionMenu(EmbedBuilder[] EmbedBuilders, ISocketMessageChannel Channel)
        {
            RestUserMessage Message = await Channel.SendMessageAsync(
                embed : BuildEmbed(EmojiEnum.Unknown).WithTitle("Setting up reaction menu-").Build()
                );

            List <uint> Colors = new ();

            foreach (EmbedBuilder Builder in EmbedBuilders)
            {
                Colors.Add(Builder.Color.HasValue ? Builder.Color.Value.RawValue : Color.Blue.RawValue);
            }

            int    EmbedMenuID;
            string EmbedMenuJSON = JsonConvert.SerializeObject(EmbedBuilders);

            EmbedMenu EmbedMenu = ReactionMenuDB.EmbedMenus.AsQueryable()
                                  .Where(Menu => Menu.EmbedMenuJSON.Equals(EmbedMenuJSON)).FirstOrDefault();

            if (EmbedMenu != null)
            {
                EmbedMenuID = EmbedMenu.EmbedIndex;
            }
            else
            {
                EmbedMenuID = ReactionMenuDB.EmbedMenus.AsQueryable().Count() + 1;

                ReactionMenuDB.EmbedMenus.Add(
                    new EmbedMenu()
                {
                    EmbedIndex    = EmbedMenuID,
                    EmbedMenuJSON = EmbedMenuJSON
                }
                    );
            }

            int    ColorMenuID;
            string ColorMenuJSON = JsonConvert.SerializeObject(Colors.ToArray());

            ColorMenu ColorMenu = ReactionMenuDB.ColorMenus.AsQueryable()
                                  .Where(Menu => Menu.ColorMenuJSON.Equals(ColorMenuJSON)).FirstOrDefault();

            if (ColorMenu != null)
            {
                ColorMenuID = ColorMenu.ColorIndex;
            }
            else
            {
                ColorMenuID = ReactionMenuDB.ColorMenus.AsQueryable().Count() + 1;

                ReactionMenuDB.ColorMenus.Add(new ColorMenu()
                {
                    ColorIndex    = ColorMenuID,
                    ColorMenuJSON = ColorMenuJSON
                });
            }

            ReactionMenu ReactionMenu = new() {
                CurrentPage    = 1,
                MessageID      = Message.Id,
                ColorMenuIndex = ColorMenuID,
                EmbedMenuIndex = EmbedMenuID
            };

            ReactionMenuDB.ReactionMenus.Add(ReactionMenu);

            ReactionMenuDB.SaveChanges();

            await Message.ModifyAsync(MessageP => MessageP.Embed = CreateMenuEmbed(ReactionMenu));

            await Message.AddReactionAsync(new Emoji("⬅️"));

            await Message.AddReactionAsync(new Emoji("➡️"));
        }