コード例 #1
0
ファイル: Owner.cs プロジェクト: binn/Lykos
            public async Task Shell(CommandContext ctx, [RemainingText] string command)
            {
                var msg = await ctx.RespondAsync("executing..");

                string fileName;
                string arguments;

                string escapedArgs = command.Replace("\"", "\\\"");

                if (GetOSPlatform() == OSPlatform.Windows)
                {
                    // doesnt function correctly
                    // TODO: make it function correctly
                    fileName  = "C:/Windows/system32/cmd.exe";
                    arguments = $"/C {escapedArgs} 2>&1";
                }
                else
                {
                    // if you dont have bash i apologise
                    fileName  = "/bin/bash";
                    arguments = $"-c \"{escapedArgs} 2>&1\"";
                }


                var proc = new Process
                {
                    StartInfo = new ProcessStartInfo
                    {
                        FileName               = fileName,
                        Arguments              = arguments,
                        UseShellExecute        = false,
                        RedirectStandardOutput = true,
                        RedirectStandardError  = true,
                        RedirectStandardInput  = true
                    }
                };

                proc.Start();
                string result = proc.StandardOutput.ReadToEnd();

                proc.WaitForExit();
                result = result.Replace(Program.cfgjson.Token, "[Prod Token]");
                if (result.Length > 1947)
                {
                    HasteBinResult hasteURL = await Program.hasteUploader.Post(result);

                    if (hasteURL.IsSuccess)
                    {
                        await msg.ModifyAsync($"Done, but output exceeded character limit! (`{result.Length}`/`1947`)\nFull output can be viewed here: https://paste.erisa.moe/raw/{hasteURL.Key}\nProcess exited with code `{proc.ExitCode}`.");
                    }
                    else
                    {
                        await msg.ModifyAsync("Error occured during upload to hastebin. Action was executed regardless, exit code was `{proc.ExitCode}`");
                    }
                }
                else
                {
                    await msg.ModifyAsync($"Done, output: ```\n{result}```Process exited with code `{proc.ExitCode}`.");
                }
            }
コード例 #2
0
        public async Task <HasteBinResult> Post(string content)
        {
            string fullUrl = _baseUrl;

            if (!fullUrl.EndsWith("/"))
            {
                fullUrl += "/";
            }
            string postUrl = $"{fullUrl}documents";

            var request = new HttpRequestMessage(HttpMethod.Post, new Uri(postUrl));

            request.Content = new StringContent(content);
            HttpResponseMessage result = await _httpClient.SendAsync(request);

            if (result.IsSuccessStatusCode)
            {
                string json = await result.Content.ReadAsStringAsync();

                HasteBinResult hasteBinResult = JsonConvert.DeserializeObject <HasteBinResult>(json);

                if (hasteBinResult?.Key != null)
                {
                    hasteBinResult.FullUrl    = $"{fullUrl}{hasteBinResult.Key}";
                    hasteBinResult.IsSuccess  = true;
                    hasteBinResult.StatusCode = 200;
                    return(hasteBinResult);
                }
            }

            return(new HasteBinResult()
            {
                FullUrl = fullUrl,
                IsSuccess = false,
                StatusCode = (int)result.StatusCode
            });
        }