add timeout to ip grab

This commit is contained in:
Elijah R 2024-04-02 23:33:03 -04:00
parent 9aeb024fec
commit 580fe24d32
2 changed files with 30 additions and 5 deletions

View file

@ -176,7 +176,15 @@ public class DiscordCommands : ApplicationCommandModule
foreach (var vm in vms)
{
if (!vm.cvm.ConnectedToVM || vm.cvm.Users.All(u => u.Username != username)) continue;
var ip = await vm.cvm.GetIP(username);
string ip;
try
{
ip = await vm.cvm.GetIP(username);
}
catch (TimeoutException ex)
{
continue;
}
var ipinfo = await Program.IPinfo.IPApi.GetDetailsAsync(ip);
IPEmbeds.Add(new DiscordEmbedBuilder()
.WithAuthor(username)

View file

@ -113,10 +113,19 @@ public class VM
await cvm.Ban(e.Username);
break;
}
string ip;
try
{
ip = await cvm.GetIP(username);
}
catch (TimeoutException ex)
{
ip = "unknown";
}
MessageIncident.Invoke(this, new MessageIncident
{
FilterDescription = filter.Description,
IP = await cvm.GetIP(e.Username),
IP = ip,
Message = e.Message,
Punishment = filter.Punishment,
Username = e.Username,
@ -128,8 +137,16 @@ public class VM
private async Task CheckUsername(User user)
{
var ip = await cvm.GetIP(user.Username);
await database.LogIPAsync(Config.Name, user.Username, IPAddress.Parse(ip));
string ip;
try
{
ip = await cvm.GetIP(username);
await database.LogIPAsync(Config.Name, user.Username, IPAddress.Parse(ip));
}
catch (TimeoutException ex)
{
ip = "unknown";
}
if (user.Rank != Rank.Unregistered) return;
foreach (var filter in Program.Filters.Where(f => f.CheckUsername))
{
@ -140,7 +157,7 @@ public class VM
UsernameIncident.Invoke(this, new UsernameIncident
{
FilterDescription = filter.Description,
IP = await cvm.GetIP(user.Username),
IP = ip,
Username = user.Username,
VM = Config.Name
});