Revert "Merge branch 'DiscordBot' into main"

This reverts commit cdf2988cb6, reversing
changes made to 76415b4a0a.
This commit is contained in:
Marcel Baumgartner
2023-06-20 20:59:49 +02:00
parent cdf2988cb6
commit 1b40250750
3 changed files with 12 additions and 30 deletions

View File

@@ -1,10 +1,9 @@
using Discord; using Discord;
using Discord.WebSocket; using Discord.WebSocket;
using Logging.Net;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Moonlight.App.Database.Entities;
using Moonlight.App.Repositories; using Moonlight.App.Repositories;
using Moonlight.App.Repositories.Servers; using Moonlight.App.Repositories.Servers;
using UserStatus = Moonlight.App.Models.Misc.UserStatus;
namespace Moonlight.App.Services.DiscordBot.Commands; namespace Moonlight.App.Services.DiscordBot.Commands;
@@ -23,8 +22,9 @@ public class ServerListCommand : BaseModule
if (command.User.IsBot) return; if (command.User.IsBot) return;
if (command.CommandName != "servers") return; if (command.CommandName != "servers") return;
var usersRepo = Scope.ServiceProvider.GetRequiredService<Repository<User>>(); var usersRepo = Scope.ServiceProvider.GetRequiredService<UserRepository>();
var user = usersRepo.Get().FirstOrDefault(x => x.DiscordId == command.User.Id); var user = usersRepo.Get().FirstOrDefault(x => x.DiscordId == command.User.Id);
//var user = usersRepo.Get().FirstOrDefault(x => x.Id == 1);
if (user == null) if (user == null)
{ {
@@ -42,13 +42,10 @@ public class ServerListCommand : BaseModule
foreach (var server in servers.Take(25)) foreach (var server in servers.Take(25))
{ {
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}")
selectOptions.Add(new SelectMenuOptionBuilder() .WithEmote(Emote.Parse("<:server3:968614410228736070>"))
.WithLabel($"{server.Id} - {server.Name}") .WithValue(server.Id.ToString()));
.WithEmote(Emote.Parse("<:server3:968614410228736070>"))
.WithValue(server.Id.ToString()));
}
} }
components = new ComponentBuilder(); components = new ComponentBuilder();

View File

@@ -1,5 +1,6 @@
using System.Diagnostics; using System.Diagnostics;
using Discord; using Discord;
using Discord.Commands;
using Discord.WebSocket; using Discord.WebSocket;
using Logging.Net; using Logging.Net;
using Moonlight.App.Services.DiscordBot.Commands; using Moonlight.App.Services.DiscordBot.Commands;

View File

@@ -5,7 +5,6 @@ using Microsoft.EntityFrameworkCore;
using Moonlight.App.ApiClients.Wings; using Moonlight.App.ApiClients.Wings;
using Moonlight.App.Repositories; using Moonlight.App.Repositories;
using Moonlight.App.Repositories.Servers; using Moonlight.App.Repositories.Servers;
using UserStatus = Moonlight.App.Models.Misc.UserStatus;
namespace Moonlight.App.Services.DiscordBot.Modules; namespace Moonlight.App.Services.DiscordBot.Modules;
@@ -31,8 +30,7 @@ public class ServerListComponentHandlerModule : BaseModule
var dcs = Scope.ServiceProvider.GetRequiredService<DiscordBotService>(); var dcs = Scope.ServiceProvider.GetRequiredService<DiscordBotService>();
var costomId = component.Data.CustomId.Split("."); 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); 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.Length < 3) return;
if(costomId[0] is not "Sm") return; if(costomId[0] is not "Sm") return;
@@ -49,25 +47,11 @@ public class ServerListComponentHandlerModule : BaseModule
await ErrorEmbedSnippet(component); await ErrorEmbedSnippet(component);
return; return;
} }
var usersRepo = Scope.ServiceProvider.GetRequiredService<Repository<User>>(); if (server.Owner.DiscordId != component.User.Id)
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<String>("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); 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.RespondAsync(embed: embed.Build(), ephemeral: true);
await component.DeleteOriginalResponseAsync();
return; return;
} }
@@ -151,7 +135,7 @@ public class ServerListComponentHandlerModule : BaseModule
case "Stop": case "Stop":
if (serverDetails.State is not ("starting" or "stopping" or "running")) if (serverDetails.State is not ("starting" or "stopping"))
{ {
embed = dcs.EmbedBuilderModule.StandardEmbed("Server is in a Invalid State \n please try again later.", Color.Red, component.User); 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); await component.RespondAsync(embed: embed.Build(), ephemeral: true);