add ID argument
This commit is contained in:
parent
411649c377
commit
c2a53464a2
2 changed files with 42 additions and 10 deletions
|
@ -9,14 +9,29 @@ public class DiscordCommands : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashCommand("vnc", "View insecure VNCs around the world!")]
|
[SlashCommand("vnc", "View insecure VNCs around the world!")]
|
||||||
public async Task VNC(InteractionContext ctx,
|
public async Task VNC(InteractionContext ctx,
|
||||||
[Option("country", "If specified, a random VNC from this country")] string? country = null)
|
[Option("country", "If specified, a random VNC from this country")] string? country = null,
|
||||||
|
[Option("id", "If specified, a specific VNC by ID")] long? id = null)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Getting random VNC for {ctx.User.Username} in {country ?? "any country"}");
|
|
||||||
await ctx.DeferAsync();
|
await ctx.DeferAsync();
|
||||||
VNC vnc;
|
VNC vnc;
|
||||||
using var http = new HttpClient();
|
using var http = new HttpClient();
|
||||||
if (country != null)
|
if (id != null)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine($"Getting VNC ID {id} for {ctx.User.Username}");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var response = await http.GetStringAsync($"https://computernewb.com/vncresolver/api/scans/vnc/id/{id}");
|
||||||
|
vnc = JsonSerializer.Deserialize<VNC>(response);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"Failed to fetch VNC data ({ex.Message}). Please ping an admin!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (country != null)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Getting VNC from {country} for {ctx.User.Username}");
|
||||||
if (!Regex.IsMatch(country, "^[a-zA-Z]{2}$"))
|
if (!Regex.IsMatch(country, "^[a-zA-Z]{2}$"))
|
||||||
{
|
{
|
||||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent(
|
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent(
|
||||||
|
@ -39,15 +54,10 @@ public class DiscordCommands : ApplicationCommandModule
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var random = new Random().Next(results.count);
|
var random = new Random().Next(results.count);
|
||||||
response = await http.GetStringAsync(
|
|
||||||
$"https://computernewb.com/vncresolver/api/scans/vnc/id/{results.result[random]}");
|
|
||||||
vnc = JsonSerializer.Deserialize<VNC>(response);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var response = await http.GetStringAsync("https://computernewb.com/vncresolver/api/scans/vnc/random");
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
response = await http.GetStringAsync(
|
||||||
|
$"https://computernewb.com/vncresolver/api/scans/vnc/id/{results.result[random]}");
|
||||||
vnc = JsonSerializer.Deserialize<VNC>(response);
|
vnc = JsonSerializer.Deserialize<VNC>(response);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -56,12 +66,33 @@ public class DiscordCommands : ApplicationCommandModule
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Getting random VNC for {ctx.User.Username}");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var response = await http.GetStringAsync("https://computernewb.com/vncresolver/api/scans/vnc/random");
|
||||||
|
vnc = JsonSerializer.Deserialize<VNC>(response);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"Failed to fetch VNC data ({ex.Message}). Please ping an admin!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (vnc == null)
|
if (vnc == null)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Failed to fetch VNC data (response was null)");
|
Console.WriteLine("Failed to fetch VNC data (response was null)");
|
||||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Failed to fetch VNC data (response was null, please ping an admin!)"));
|
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Failed to fetch VNC data (response was null, please ping an admin!)"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (vnc.error != null)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Error: {vnc.error}");
|
||||||
|
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent(vnc.error));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var embed = new DiscordEmbedBuilder()
|
var embed = new DiscordEmbedBuilder()
|
||||||
.WithTitle($"VNC {vnc.id}").WithUrl($"https://computernewb.com/vncresolver/browse/#id/{vnc.id}")
|
.WithTitle($"VNC {vnc.id}").WithUrl($"https://computernewb.com/vncresolver/browse/#id/{vnc.id}")
|
||||||
|
|
|
@ -2,6 +2,7 @@ namespace CollabBot;
|
||||||
|
|
||||||
public class VNC
|
public class VNC
|
||||||
{
|
{
|
||||||
|
public string? error { get; set; }
|
||||||
public int id { get; set; }
|
public int id { get; set; }
|
||||||
public string ip { get; set; }
|
public string ip { get; set; }
|
||||||
public int port { get; set; }
|
public int port { get; set; }
|
||||||
|
|
Loading…
Reference in a new issue