diff --git a/Moonlight/App/Services/DiscordBot/Commands/ServerListCommand.cs b/Moonlight/App/Services/DiscordBot/Commands/ServerListCommand.cs index 68e7fada..5fe5a9dc 100644 --- a/Moonlight/App/Services/DiscordBot/Commands/ServerListCommand.cs +++ b/Moonlight/App/Services/DiscordBot/Commands/ServerListCommand.cs @@ -1,9 +1,10 @@ using Discord; using Discord.WebSocket; -using Logging.Net; using Microsoft.EntityFrameworkCore; +using Moonlight.App.Database.Entities; using Moonlight.App.Repositories; using Moonlight.App.Repositories.Servers; +using UserStatus = Moonlight.App.Models.Misc.UserStatus; namespace Moonlight.App.Services.DiscordBot.Commands; @@ -22,9 +23,8 @@ public class ServerListCommand : BaseModule if (command.User.IsBot) return; if (command.CommandName != "servers") return; - var usersRepo = Scope.ServiceProvider.GetRequiredService(); + var usersRepo = Scope.ServiceProvider.GetRequiredService>(); var user = usersRepo.Get().FirstOrDefault(x => x.DiscordId == command.User.Id); - //var user = usersRepo.Get().FirstOrDefault(x => x.Id == 1); if (user == null) { @@ -42,10 +42,13 @@ public class ServerListCommand : BaseModule foreach (var server in servers.Take(25)) { - selectOptions.Add(new SelectMenuOptionBuilder() - .WithLabel($"{server.Id} - {server.Name}") - .WithEmote(Emote.Parse("<:server3:968614410228736070>")) - .WithValue(server.Id.ToString())); + if (!server.Suspended && server.Owner.DiscordId == command.User.Id && user.Status is not (UserStatus.Banned or UserStatus.Disabled)) + { + selectOptions.Add(new SelectMenuOptionBuilder() + .WithLabel($"{server.Id} - {server.Name}") + .WithEmote(Emote.Parse("<:server3:968614410228736070>")) + .WithValue(server.Id.ToString())); + } } components = new ComponentBuilder(); diff --git a/Moonlight/App/Services/DiscordBot/DiscordBotService.cs b/Moonlight/App/Services/DiscordBot/DiscordBotService.cs index 5a64d70a..696fc335 100644 --- a/Moonlight/App/Services/DiscordBot/DiscordBotService.cs +++ b/Moonlight/App/Services/DiscordBot/DiscordBotService.cs @@ -1,6 +1,5 @@ using System.Diagnostics; using Discord; -using Discord.Commands; using Discord.WebSocket; using Logging.Net; using Moonlight.App.Services.DiscordBot.Commands; diff --git a/Moonlight/App/Services/DiscordBot/Modules/ServerListComponentHandlerModule.cs b/Moonlight/App/Services/DiscordBot/Modules/ServerListComponentHandlerModule.cs index 1a529bc0..6395d297 100644 --- a/Moonlight/App/Services/DiscordBot/Modules/ServerListComponentHandlerModule.cs +++ b/Moonlight/App/Services/DiscordBot/Modules/ServerListComponentHandlerModule.cs @@ -2,9 +2,11 @@ using Discord.WebSocket; using Logging.Net; using Microsoft.EntityFrameworkCore; +using Moonlight.App.Database.Entities; using Moonlight.App.Models.Wings; using Moonlight.App.Repositories; using Moonlight.App.Repositories.Servers; +using UserStatus = Moonlight.App.Models.Misc.UserStatus; namespace Moonlight.App.Services.DiscordBot.Modules; @@ -30,7 +32,8 @@ public class ServerListComponentHandlerModule : BaseModule var dcs = Scope.ServiceProvider.GetRequiredService(); var costomId = component.Data.CustomId.Split("."); EmbedBuilder embed = dcs.EmbedBuilderModule.StandardEmbed("Something went terribly wrong! \n Mission failed please try again later.", Color.Red, component.User); - + ComponentBuilder components = new(); + if (costomId.Length < 3) return; if(costomId[0] is not "Sm") return; @@ -47,11 +50,25 @@ public class ServerListComponentHandlerModule : BaseModule await ErrorEmbedSnippet(component); return; } - - if (server.Owner.DiscordId != component.User.Id) + + var usersRepo = Scope.ServiceProvider.GetRequiredService>(); + var user = usersRepo.Get().FirstOrDefault(x => x.DiscordId == component.User.Id); + + if (user == null) + { + embed = dcs.EmbedBuilderModule.StandardEmbed("Sorry ;( \n Please first create and/or link a Account to Discord! \n Press the Button to register/log in.", Color.Red, component.User); + components.WithButton("Click Here", style: ButtonStyle.Link, url: ConfigService.GetSection("Moonlight").GetValue("AppUrl")); + + await component.RespondAsync(embed: embed.Build(), components: components.Build(), ephemeral: true); + await component.DeleteOriginalResponseAsync(); + return; + } + + if (server.Suspended || user.Status is not (UserStatus.Banned or UserStatus.Disabled) || server.Owner.DiscordId != component.User.Id) { embed = dcs.EmbedBuilderModule.StandardEmbed("Is this your Server? I don't think so. \n Yes i did think of that.", Color.Red, component.User); await component.RespondAsync(embed: embed.Build(), ephemeral: true); + await component.DeleteOriginalResponseAsync(); return; } @@ -135,7 +152,7 @@ public class ServerListComponentHandlerModule : BaseModule case "Stop": - if (serverDetails.State is not ("starting" or "stopping")) + if (serverDetails.State is not ("starting" or "stopping" or "running")) { embed = dcs.EmbedBuilderModule.StandardEmbed("Server is in a Invalid State \n please try again later.", Color.Red, component.User); await component.RespondAsync(embed: embed.Build(), ephemeral: true);