Exemplo n.º 1
0
        public async Task <string> PasteMessage(IMessage msg)
        {
            string code = msg.Content;
            string lang = "Autodetect";

            if (HasCodeblockFormat(code))
            {
                code = ExtractCodeblockContent(code, out lang);
            }

            var langRes = await PasteMystLanguage.IdentifyByNameAsync(lang);

            if (langRes == null)
            {
                lang = "Autodetect";
            }

            var paste = new PasteMystPasteForm
            {
                Title          = $"paste by {msg.Author.Username}#{msg.Author.Discriminator} [BrackeysBot]",
                ExpireDuration = PasteMystExpiration.Never,
                Pasties        = new[]
                {
                    new PasteMystPastyForm
                    {
                        Title = "(untitled)",
                        // remove trailing newline
                        Code     = code.TrimEnd(Environment.NewLine.ToCharArray()),
                        Language = lang,
                    },
                },
            };

            try
            {
                var res = await paste.PostPasteAsync();

                return($"https://paste.myst.rs/{res.Id}");
            }
            catch (Exception e)
            {
                await _logger.LogMessageAsync(new LogMessage(LogSeverity.Warning, "Paste", $"failed to paste: {e}"));


                return(null);
            }
        }
Exemplo n.º 2
0
        public static async Task TestLanguageIdentifier()
        {
            _ = await PasteMystLanguage.IdentifyByExtensionAsync("cs");

            _ = await PasteMystLanguage.IdentifyByNameAsync("C#");
        }