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 void PasteCodeblock(string discordMessage)
        {
            var paste = new PasteMystPasteForm
            {
                ExpireDuration = PasteMystExpiration.OneYear,
                Pasties        = new[]
                {
                    new PasteMystPastyForm
                    {
                        Language = "Autodetect",
                        Code     = ExtractCodeblockContent(discordMessage)
                    }
                }
            };

            paste.PostPasteAsync();
        }
Exemplo n.º 3
0
 public static void SetupTests()
 {
     TemplateForm = new PasteMystPasteForm
     {
         Title          = "PasteMyst.NET",
         ExpireDuration = PasteMystExpiration.OneHour,
         Pasties        = new List <PasteMystPastyForm>
         {
             new()
             {
                 Language = "Plain Text",
                 Code     = "Hello World!"
             },
             new()
             {
                 Title = "test.py",
                 Code  = "def main():" + "\n" +
                         "    print('Hello World')" + "\n" +
                         "\n" +
                         "main()"
             }
         },
     };
 }