コード例 #1
0
        public async Task ExecutePythonString([Remainder] string pythonStr = null)
        {
            List <string> pythonOut = new List <string>();

            //check for python files in the current message
            if (pythonStr == null &&
                Context.Message.Attachments != null &&
                Context.Message.Attachments.Count > 0 &&
                AttachmentHelper.AttachmentsAreValid(Context.Message.Attachments, AttachmentFilter.Plaintext))
            {
                pythonOut = _pythonService.ExecutePythonFiles(Context.Message.Attachments);
            }

            //otherwise, use the given text
            else
            {
                pythonOut = _pythonService.ExecutePythonString(pythonStr);
            }

            //sent output as monospaced text
            foreach (string outPage in pythonOut)
            {
                await ReplyAsync($"```\n{outPage}\n```");
            }
        }