示例#1
0
        public async Task GetCardAsync(bool trim, CardDeny deny, BorderAllow border,
                                       Casing casing, FontType font, PaletteType palette, Gamma usernameGamma = Gamma.Max,
                                       Gamma activityGamma = Gamma.Max, Gamma borderGamma = Gamma.Max, ImageScale scale = ImageScale.Medium, int padding = 2)
        {
            SocketUser user = Context.User;

            if (!Context.Container.TryGetUser(user.Id, out User account))
            {
                await Context.Channel.ThrowAsync("The specified user does not have an existing account.");

                return;
            }

            try
            {
                using var graphics = new GraphicsService();
                var d = new CardDetails(account, user);

                var p = new CardProperties
                {
                    Trim    = trim,
                    Deny    = deny,
                    Border  = border,
                    Casing  = casing,
                    Font    = font,
                    Palette = palette,
                    Gamma   = new Dictionary <CardComponentType, Gamma?>
                    {
                        [CardComponentType.Username]   = usernameGamma,
                        [CardComponentType.Activity]   = activityGamma,
                        [CardComponentType.Border]     = borderGamma,
                        [CardComponentType.Background] = null,
                        [CardComponentType.Avatar]     = Gamma.Max
                    },
                    Padding = new Padding(padding),
                    Scale   = scale
                };

                Bitmap card = graphics.DrawCard(d, p);

                Logger.Debug("Drawing card...");
                await Context.Channel.SendImageAsync(card, $"../tmp/{Context.User.Id}_card.png");
            }
            catch (Exception ex)
            {
                await Context.Channel.CatchAsync(ex);
            }
        }
示例#2
0
        public async Task DrawBorderAsync(int width = 32, int height = 32, int thickness = 2, PaletteType palette = PaletteType.GammaGreen, Gamma background = Gamma.StandardDim, Gamma border = Gamma.Max, BorderEdge edge = BorderEdge.Outside, BorderAllow allow = BorderAllow.All)
        {
            /*
             * var width = Context.GetOptionOrDefault("width", 32);
             * var height = Context.GetOptionOrDefault("height", 32);
             * var thickness = Context.GetOptionOrDefault("thickness", 2);
             * var color = Context.GetOptionOrDefault("color", ImmutableColor.GammaGreen);
             * var edge = Context.GetOptionOrDefault("edge", BorderEdge.Outside);
             * var allow = Context.GetOptionOrDefault("allow", BorderAllow.All);
             */

            using (var tmp = ImageHelper.CreateSolid(GraphicsService.GetPalette(palette)[background], width, height))
                using (Bitmap b = ImageHelper.SetBorder(tmp, GraphicsService.GetPalette(palette)[border], thickness, edge, allow))
                    await Context.Channel.SendImageAsync(b, "../tmp/border.png");
        }