Merge branch 'DiscordBot' into main
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
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;
|
||||||
@@ -22,9 +23,8 @@ 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<UserRepository>();
|
var usersRepo = Scope.ServiceProvider.GetRequiredService<Repository<User>>();
|
||||||
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,10 +42,13 @@ public class ServerListCommand : BaseModule
|
|||||||
|
|
||||||
foreach (var server in servers.Take(25))
|
foreach (var server in servers.Take(25))
|
||||||
{
|
{
|
||||||
selectOptions.Add(new SelectMenuOptionBuilder()
|
if (!server.Suspended && server.Owner.DiscordId == command.User.Id && user.Status is not (UserStatus.Banned or UserStatus.Disabled))
|
||||||
.WithLabel($"{server.Id} - {server.Name}")
|
{
|
||||||
.WithEmote(Emote.Parse("<:server3:968614410228736070>"))
|
selectOptions.Add(new SelectMenuOptionBuilder()
|
||||||
.WithValue(server.Id.ToString()));
|
.WithLabel($"{server.Id} - {server.Name}")
|
||||||
|
.WithEmote(Emote.Parse("<:server3:968614410228736070>"))
|
||||||
|
.WithValue(server.Id.ToString()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
components = new ComponentBuilder();
|
components = new ComponentBuilder();
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
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;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ 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;
|
||||||
|
|
||||||
@@ -30,6 +31,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;
|
||||||
|
|
||||||
@@ -48,10 +50,24 @@ public class ServerListComponentHandlerModule : BaseModule
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server.Owner.DiscordId != component.User.Id)
|
var usersRepo = Scope.ServiceProvider.GetRequiredService<Repository<User>>();
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +151,7 @@ public class ServerListComponentHandlerModule : BaseModule
|
|||||||
|
|
||||||
|
|
||||||
case "Stop":
|
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);
|
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user