Exemple #1
0
        public async Task ThemesList(CommandContext ctx)
        {
            string[] lightThemes = CarbonHandler.GetLightThemes();
            string[] darkThemes  = CarbonHandler.GetDarkThemes();

            var themesEmbed = new DiscordEmbedBuilder()
                              .WithTitle("Available themes")
                              .WithDescription("You can use these themes with the code command")
                              .AddField("Dark themes", $"> {string.Join("\n> ", darkThemes)}")
                              .AddField("Light Themes", $"> {string.Join("\n> ", lightThemes)}")
                              .WithColor(DisarisCosmetics.DisarisColor)
                              .Build();

            await ctx.Channel.SendMessageAsync(embed : themesEmbed);
        }
Exemple #2
0
        public async Task CarbonCode(CommandContext ctx, string theme, [RemainingText] string code)
        {
            if (theme != null && code == null)
            {
                await ctx.Channel.SendMessageAsync("Using this command requires you to specify a theme, use `ds carbon-themes` to get a list of all available themes");

                return;
            }

            if (code == null)
            {
                await ctx.Channel.SendMessageAsync("You need to give a code block");

                return;
            }

            var cs1 = code.IndexOf("```") + 3;

            cs1 = code.IndexOf('\n', cs1) + 1;
            var cs2 = code.LastIndexOf("```");

            if (cs1 == -1 || cs2 == -1)
            {
                await ctx.Channel.SendErrorAsync("Error!", "You need to wrap the code into a code block.");

                return;
            }

            var cs = code.Substring(cs1, cs2 - cs1);

            cs = cs.Remove(cs.LastIndexOf("\n"));
            var csUrl = WebUtility.UrlEncode(cs);

            string validTheme = CarbonHandler.ThemeMatcher(theme);

            var baseUrl = "https://carbon.now.sh/";
            var url     = @$ "{baseUrl}?l=auto&t={validTheme}&code={csUrl}";

            string title = $"Code Snippet by {ctx.Member.Username}";

            await ctx.Channel.SendCarbonCodeAsync(title, url);
        }
Exemple #3
0
        public async Task Theme(CommandContext ctx, string theme)
        {
            string[] themes = CarbonHandler.GetThemes();

            if (!Array.Exists(themes, x => x == theme))
            {
                await ctx.Channel.SendErrorAsync("The theme provided does not match any themes", "use `ds carbon-themes` to get a list of available themes");

                return;
            }

            await ctx.TriggerTypingAsync();

            string path = $"./Images/Snippets/{theme}-theme.png";

            var msg = await new DiscordMessageBuilder()
                      .WithContent($"Theme snippet for {theme}")
                      .WithFile(path, File.OpenRead(path))
                      .SendAsync(ctx.Channel);
        }