add per-vm mods, fix typo
This commit is contained in:
parent
07e15ff0fb
commit
6f0def0d03
2 changed files with 26 additions and 20 deletions
|
@ -72,10 +72,6 @@ public class DiscordCommands : ApplicationCommandModule
|
|||
[SlashCommand("ban", "Ban a user")]
|
||||
public async Task Ban(InteractionContext ctx, [Option("username", "User to ban")] string username,
|
||||
[Option("vm", "VM to ban from")] [ChoiceProvider(typeof(VMAutocompleteProvider))] string VM) {
|
||||
if (ctx.Member.Roles.All(r => !Program.Config.Discord.ModRoles.Contains(r.Id))) {
|
||||
await ctx.CreateResponseAsync("You do not have permission to use that command.");
|
||||
return;
|
||||
}
|
||||
if (Program.VMs.All(v => v.Config.Name != VM)) {
|
||||
await ctx.CreateResponseAsync("No VM by that name found.");
|
||||
return;
|
||||
|
@ -84,6 +80,10 @@ public class DiscordCommands : ApplicationCommandModule
|
|||
if (!vm.cvm.ConnectedToVM) {
|
||||
await ctx.CreateResponseAsync($"Not currently connected to {vm.Config.Name}");
|
||||
}
|
||||
if (vm.Config.DiscordMods?.Contains(ctx.Member.Id) != true && ctx.Member.Roles.All(r => !Program.Config.Discord.ModRoles.Contains(r.Id))) {
|
||||
await ctx.CreateResponseAsync("You do not have permission to use that command.");
|
||||
return;
|
||||
}
|
||||
if (vm.cvm.Users.All(u => u.Username != username)) {
|
||||
await ctx.CreateResponseAsync($"User {username} not found on {VM}");
|
||||
return;
|
||||
|
@ -95,10 +95,6 @@ public class DiscordCommands : ApplicationCommandModule
|
|||
[SlashCommand("kick", "Kick a user")]
|
||||
public async Task Kick(InteractionContext ctx, [Option("username", "User to kick")] string username,
|
||||
[Option("vm", "VM to kick from"), ChoiceProvider(typeof(VMAutocompleteProvider))] string VM) {
|
||||
if (ctx.Member.Roles.All(r => !Program.Config.Discord.ModRoles.Contains(r.Id))) {
|
||||
await ctx.CreateResponseAsync("You do not have permission to use that command.");
|
||||
return;
|
||||
}
|
||||
if (Program.VMs.All(v => v.Config.Name != VM)) {
|
||||
await ctx.CreateResponseAsync("No VM by that name found.");
|
||||
return;
|
||||
|
@ -107,6 +103,10 @@ public class DiscordCommands : ApplicationCommandModule
|
|||
if (!vm.cvm.ConnectedToVM) {
|
||||
await ctx.CreateResponseAsync($"Not currently connected to {vm.Config.Name}");
|
||||
}
|
||||
if (vm.Config.DiscordMods?.Contains(ctx.Member.Id) != true && ctx.Member.Roles.All(r => !Program.Config.Discord.ModRoles.Contains(r.Id))) {
|
||||
await ctx.CreateResponseAsync("You do not have permission to use that command.");
|
||||
return;
|
||||
}
|
||||
if (vm.cvm.Users.All(u => u.Username != username)) {
|
||||
await ctx.CreateResponseAsync($"User {username} not found on {VM}");
|
||||
return;
|
||||
|
@ -119,10 +119,6 @@ public class DiscordCommands : ApplicationCommandModule
|
|||
public async Task Reboot(InteractionContext ctx,
|
||||
[Option("vm", "VM to reboot"), ChoiceProvider(typeof(VMAutocompleteProvider))] string VM)
|
||||
{
|
||||
if (ctx.Member.Roles.All(r => !Program.Config.Discord.ModRoles.Contains(r.Id))) {
|
||||
await ctx.CreateResponseAsync("You do not have permission to use that command.");
|
||||
return;
|
||||
}
|
||||
if (Program.VMs.All(v => v.Config.Name != VM)) {
|
||||
await ctx.CreateResponseAsync("No VM by that name found.");
|
||||
return;
|
||||
|
@ -131,18 +127,18 @@ public class DiscordCommands : ApplicationCommandModule
|
|||
if (!vm.cvm.ConnectedToVM) {
|
||||
await ctx.CreateResponseAsync($"Not currently connected to {vm.Config.Name}");
|
||||
}
|
||||
if (vm.Config.DiscordMods?.Contains(ctx.Member.Id) != true && ctx.Member.Roles.All(r => !Program.Config.Discord.ModRoles.Contains(r.Id))) {
|
||||
await ctx.CreateResponseAsync("You do not have permission to use that command.");
|
||||
return;
|
||||
}
|
||||
await vm.cvm.Reboot();
|
||||
await ctx.CreateResponseAsync($"Successfully rebooted {vm}");
|
||||
}
|
||||
|
||||
[SlashCommand("restpre", "Restore a VM")]
|
||||
[SlashCommand("restore", "Restore a VM")]
|
||||
public async Task Restore(InteractionContext ctx,
|
||||
[Option("vm", "VM to restore"), ChoiceProvider(typeof(VMAutocompleteProvider))] string VM)
|
||||
{
|
||||
if (ctx.Member.Roles.All(r => !Program.Config.Discord.ModRoles.Contains(r.Id))) {
|
||||
await ctx.CreateResponseAsync("You do not have permission to use that command.");
|
||||
return;
|
||||
}
|
||||
if (Program.VMs.All(v => v.Config.Name != VM)) {
|
||||
await ctx.CreateResponseAsync("No VM by that name found.");
|
||||
return;
|
||||
|
@ -151,6 +147,10 @@ public class DiscordCommands : ApplicationCommandModule
|
|||
if (!vm.cvm.ConnectedToVM) {
|
||||
await ctx.CreateResponseAsync($"Not currently connected to {vm.Config.Name}");
|
||||
}
|
||||
if (vm.Config.DiscordMods?.Contains(ctx.Member.Id) != true && ctx.Member.Roles.All(r => !Program.Config.Discord.ModRoles.Contains(r.Id))) {
|
||||
await ctx.CreateResponseAsync("You do not have permission to use that command.");
|
||||
return;
|
||||
}
|
||||
await vm.cvm.Restore();
|
||||
await ctx.CreateResponseAsync($"Successfully restored {vm}");
|
||||
}
|
||||
|
@ -158,17 +158,22 @@ public class DiscordCommands : ApplicationCommandModule
|
|||
[SlashCommand("getip", "Get the IP address of a user")]
|
||||
public async Task GetIP(InteractionContext ctx, [Option("username", "Username to grab IP from")] string username)
|
||||
{
|
||||
if (ctx.Member.Roles.All(r => !Program.Config.Discord.ModRoles.Contains(r.Id))) {
|
||||
VM[] vms;
|
||||
if (ctx.Member.Roles.Any(r => Program.Config.Discord.ModRoles.Contains(r.Id)))
|
||||
vms = Program.VMs;
|
||||
else
|
||||
vms = Program.VMs.Where(v => v.Config.DiscordMods?.Contains(ctx.Member.Id) == true).ToArray();
|
||||
if (vms.Length == 0) {
|
||||
await ctx.CreateResponseAsync("You do not have permission to use that command.");
|
||||
return;
|
||||
}
|
||||
if (Program.VMs.All(v => v.cvm.Users.All(u => u.Username != username))) {
|
||||
if (vms.All(v => v.cvm.Users.All(u => u.Username != username))) {
|
||||
await ctx.CreateResponseAsync($"{username} not found on any VM");
|
||||
return;
|
||||
}
|
||||
await ctx.DeferAsync();
|
||||
List<DiscordEmbed> IPEmbeds = new();
|
||||
foreach (var vm in Program.VMs)
|
||||
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);
|
||||
|
|
|
@ -32,6 +32,7 @@ public class ConfigVM
|
|||
public string URL { get; set; }
|
||||
public string Node { get; set; }
|
||||
public string Password { get; set; }
|
||||
public ulong[]? DiscordMods { get; set; }
|
||||
}
|
||||
|
||||
public class ConfigDatabase
|
||||
|
|
Loading…
Reference in a new issue