Exemplo n.º 1
0
            public async Task Shell(CommandContext ctx, [RemainingText] string command)
            {
                DiscordMessage msg = await ctx.Channel.SendMessageAsync("executing..");

                ShellResult finishedShell = Helpers.RunShellCommand(command);

                if (finishedShell.result.Length > 1947)
                {
                    HasteBinResult hasteURL = await Program.hasteUploader.Post(finishedShell.result);

                    if (hasteURL.IsSuccess)
                    {
                        await msg.ModifyAsync($"Done, but output exceeded character limit! (`{finishedShell.result.Length}`/`1947`)\n" +
                                              $"Full output can be viewed here: {Program.cfgjson.HastebinEndpoint}/raw/{hasteURL.Key}\nProcess exited with code `{finishedShell.proc.ExitCode}`.");
                    }
                    else
                    {
                        Console.WriteLine(finishedShell.result);
                        await msg.ModifyAsync($"Error occured during upload to Hastebin.\nAction was executed regardless, shell exit code was `{finishedShell.proc.ExitCode}`. Hastebin status code is `{hasteURL.StatusCode}`.\nPlease check the console/log for the command output.");
                    }
                }
                else
                {
                    await msg.ModifyAsync($"Done, output: ```\n" +
                                          $"{finishedShell.result}```Process exited with code `{finishedShell.proc.ExitCode}`.");
                }
            }
Exemplo n.º 2
0
                public async Task Link(CommandContext ctx, string key, string url)
                {
                    using HttpClient httpClient = new();

                    // add / if it doesnt exist
                    string baseUrl = Program.cfgjson.WorkerLinks.BaseUrl;

                    if (!baseUrl.EndsWith("/"))
                    {
                        baseUrl += "/";
                    }

                    HttpRequestMessage request;

                    if (key == "null" || key == "random" || key == "gen")
                    {
                        request = new HttpRequestMessage(HttpMethod.Post, "")
                        {
                        };
                    }
                    else
                    {
                        request = new HttpRequestMessage(HttpMethod.Put, baseUrl + key)
                        {
                        };
                    }

                    request.Headers.Add("Authorization", Program.cfgjson.WorkerLinks.Secret);
                    request.Headers.Add("URL", url);

                    HttpResponseMessage response = await httpClient.SendAsync(request);

                    int    httpStatusCode = (int)response.StatusCode;
                    string httpStatus     = response.StatusCode.ToString();
                    string responseText   = await response.Content.ReadAsStringAsync();

                    if (responseText.Length > 1940)
                    {
                        HasteBinResult hasteURL = await Program.hasteUploader.Post(responseText);

                        if (hasteURL.IsSuccess)
                        {
                            // responseText = hasteURL.FullUrl;
                            await ctx.RespondAsync($"Worker responded with code: `{httpStatusCode}` (`{httpStatus}`)\n{hasteURL.FullUrl}");

                            return;
                        }
                        else
                        {
                            Console.WriteLine(responseText);
                            responseText = "Error occured during upload to Hastebin. Please check the console/logs for the output.";
                        }
                    }
                    await ctx.RespondAsync($"Worker responded with code: `{httpStatusCode}` (`{httpStatus}`)\n```json\n{responseText}\n```");
                }
Exemplo n.º 3
0
                public async Task DeleteLink(CommandContext ctx, string key = "")
                {
                    // handle root, also handled with no args
                    if (key == "/")
                    {
                        key = "";
                    }

                    // create http client with base url e.g. https://erisa.link
                    using HttpClient httpClient = new()
                          {
                              BaseAddress = new Uri(Program.cfgjson.WorkerLinks.BaseUrl)
                          };

                    // create request object
                    HttpRequestMessage request;

                    request = new HttpRequestMessage(HttpMethod.Delete, key)
                    {
                    };
                    request.Headers.Add("Authorization", Program.cfgjson.WorkerLinks.Secret);

                    // fire off and handle the request
                    HttpResponseMessage response = await httpClient.SendAsync(request);

                    int    httpStatusCode = (int)response.StatusCode;
                    string httpStatus     = response.StatusCode.ToString();
                    string responseText   = await response.Content.ReadAsStringAsync();

                    if (responseText.Length > 1940)
                    {
                        HasteBinResult hasteURL = await Program.hasteUploader.Post(responseText);

                        if (hasteURL.IsSuccess)
                        {
                            // responseText = hasteURL.FullUrl;
                            await ctx.RespondAsync($"Worker responded with code: `{httpStatusCode}` (`{httpStatus}`)\n{hasteURL.FullUrl}");

                            return;
                        }
                        else
                        {
                            Console.WriteLine(responseText);
                            responseText = "Error occured during upload to Hastebin. Please check the console/logs for the output.";
                        }
                    }
                    await ctx.RespondAsync($"Worker responded with code: `{httpStatusCode}` (`{httpStatus}`)\n```json\n{responseText}\n```");
                }
            }
Exemplo n.º 4
0
        public async Task <HasteBinResult> Post(string content)
        {
            string fullUrl = _baseUrl;

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

            HttpRequestMessage request = new(HttpMethod.Post, new Uri(postUrl))
            {
                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
            });
        }
    }