PostLoggingSetup
This commit is contained in:
parent
d140e50cbc
commit
b503e6edeb
|
@ -96,9 +96,11 @@ public class ConfigV1
|
|||
|
||||
[JsonProperty("LoggingId")]
|
||||
[Description("This must be a PostChannel Recomended use: /setup")]
|
||||
public long LoggingId { get; set; }
|
||||
|
||||
public long PostChannelId { get; set; }
|
||||
|
||||
[JsonProperty("ThreadChannels")]
|
||||
[Description("This is reqired for Logging Don't Touch")]
|
||||
public List<long>? PostIds { get; set; }
|
||||
}
|
||||
|
||||
public class WebHookData
|
||||
|
|
|
@ -12,25 +12,23 @@ public class CommandControllerModule : BaseModule
|
|||
private async Task OnSlashCommandExecuted(SocketSlashCommand command)
|
||||
{
|
||||
if(!ConfigService.Get().Discord.Bot.Enable == false) return;
|
||||
if(command.User.IsBot) return;
|
||||
var dsc = Scope.ServiceProvider.GetRequiredService<DiscordBotService>();
|
||||
|
||||
//Global Commands
|
||||
switch (command.CommandName)
|
||||
{
|
||||
case "help":
|
||||
|
||||
break;
|
||||
case "help": await dsc.HelpCommand.Handler(command); break;
|
||||
}
|
||||
|
||||
//Guild Commands that can only be executed on the main Guild (Support Server)
|
||||
if(command.GuildId != (ulong)DiscordConfig.GuildId) return;
|
||||
switch (command.CommandName)
|
||||
{
|
||||
case "help":
|
||||
|
||||
break;
|
||||
case "setup": await dsc.SetupCommand.Handler(command); break;
|
||||
}
|
||||
}
|
||||
|
||||
public override Task Init()
|
||||
{ throw new NotImplementedException(); }
|
||||
{ throw new NotImplementedException(); }
|
||||
}
|
93
Moonlight/App/Services/Discord/Bot/Commands/SetupCommand.cs
Normal file
93
Moonlight/App/Services/Discord/Bot/Commands/SetupCommand.cs
Normal file
|
@ -0,0 +1,93 @@
|
|||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
|
||||
namespace Moonlight.App.Services.Discord.Bot.Commands;
|
||||
|
||||
public class SetupCommand : BaseModule
|
||||
{
|
||||
public SetupCommand(DiscordSocketClient client, ConfigService configService, IServiceScope scope) : base(client, configService, scope)
|
||||
{ }
|
||||
|
||||
[RequireUserPermission(GuildPermission.Administrator)]
|
||||
public async Task Handler(SocketSlashCommand command)
|
||||
{
|
||||
var dsc = Scope.ServiceProvider.GetRequiredService<DiscordBotService>();
|
||||
var guild = Client.GetGuild((ulong)DiscordConfig.GuildId);
|
||||
var user = guild.GetUser(command.User.Id);
|
||||
|
||||
// Permission check
|
||||
if (user is { GuildPermissions.Administrator: false } || guild.CurrentUser.GuildPermissions is { ManageChannels: false })
|
||||
{
|
||||
await command.RespondAsync(ephemeral: true, embed: dsc.EmbedBuilderModule.ErrorEmbed("Insufficient permissions", "You must have Administrator \n The Bot must have `Channel Edit` Permissions", command.User).Build());
|
||||
return;
|
||||
}
|
||||
|
||||
// Already setup
|
||||
if (guild.GetChannel((ulong)DiscordConfig.PostChannelId) != null)
|
||||
{
|
||||
await command.RespondAsync(ephemeral: true, embed: dsc.EmbedBuilderModule.ErrorEmbed("Already setup", "Setup canceled!", command.User).Build());
|
||||
return;
|
||||
}
|
||||
|
||||
// Automatic setup
|
||||
if (command.Data.Options.FirstOrDefault() != null && (bool)command.Data.Options.FirstOrDefault())
|
||||
{
|
||||
await command.RespondAsync(ephemeral: true, embed: dsc.EmbedBuilderModule.WarningEmbed("Automatic Setup", "This is the fast setup.\n Please wait...", command.User).Build());
|
||||
|
||||
var postChannel = await guild.CreateForumChannelAsync("NotifyChannel", x =>
|
||||
{
|
||||
x.DefaultLayout = ForumLayout.List;
|
||||
x.Flags = ChannelFlags.Pinned;
|
||||
x.PermissionOverwrites = new List<Overwrite>
|
||||
{
|
||||
new(guild.EveryoneRole.Id, PermissionTarget.Role, new OverwritePermissions(viewChannel: PermValue.Deny)),
|
||||
new(guild.CurrentUser.Id, PermissionTarget.User, new OverwritePermissions(viewChannel: PermValue.Allow))
|
||||
};
|
||||
});
|
||||
|
||||
var posts = new List<long>();
|
||||
|
||||
foreach (DiscordLogging x in Enum.GetValues(typeof(DiscordLogging)))
|
||||
{
|
||||
var post = await postChannel.CreatePostAsync( $"{x}", ThreadArchiveDuration.OneWeek,
|
||||
embed: dsc.EmbedBuilderModule.InfoEmbed($"{x}", "# Don't Remove the Channel \n Logging for ...", Client.CurrentUser).Build());
|
||||
|
||||
posts.Add((long)post.Id);
|
||||
}
|
||||
|
||||
//Save to Config
|
||||
ConfigService.Get().Discord.Bot.PostChannelId = (long)postChannel.Id;
|
||||
ConfigService.Get().Discord.Bot.PostIds = posts;
|
||||
ConfigService.Save();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
await command.RespondAsync(ephemeral: true, embed: dsc.EmbedBuilderModule.SuccessEmbed("Manuel Setup", "This is the custom setup.", command.User).Build());
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override async Task Init()
|
||||
{
|
||||
var command = new SlashCommandBuilder()
|
||||
{
|
||||
Name = "setup",
|
||||
Description = "Setup the bot and Channels",
|
||||
DefaultMemberPermissions = GuildPermission.ViewAuditLog,
|
||||
Options = new List<SlashCommandOptionBuilder>(new List<SlashCommandOptionBuilder>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Name = "fast",
|
||||
Description = "Fast Setup channel will be automatically created",
|
||||
Type = ApplicationCommandOptionType.Boolean,
|
||||
IsRequired = false
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
await Client.GetGuild((ulong)DiscordConfig.GuildId).CreateApplicationCommandAsync(command.Build());
|
||||
}
|
||||
}
|
|
@ -23,9 +23,10 @@ public class DiscordBotService
|
|||
private readonly DiscordSocketClient Client;
|
||||
|
||||
// References
|
||||
public CommandControllerModule CommandControllerModule { get; private set; }
|
||||
public EmbedBuilderModule EmbedBuilderModule { get; private set; }
|
||||
public CommandControllerModule CommandControllerModule { get; private set; }
|
||||
public HelpCommand HelpCommand { get; private set; }
|
||||
public SetupCommand SetupCommand { get; private set; }
|
||||
|
||||
|
||||
public DiscordBotService(IServiceScopeFactory serviceScopeFactory, ConfigService configService)
|
||||
|
@ -34,7 +35,7 @@ public class DiscordBotService
|
|||
ConfigService = configService;
|
||||
Client = new DiscordSocketClient( new DiscordSocketConfig
|
||||
{
|
||||
GatewayIntents = GatewayIntents.All
|
||||
GatewayIntents = GatewayIntents.Guilds
|
||||
});
|
||||
|
||||
Task.Run(MainAsync);
|
||||
|
@ -54,6 +55,7 @@ public class DiscordBotService
|
|||
//Commands
|
||||
CommandControllerModule = new CommandControllerModule(Client, ConfigService, ServiceScope);
|
||||
HelpCommand = new HelpCommand(Client, ConfigService, ServiceScope);
|
||||
SetupCommand = new SetupCommand(Client, ConfigService, ServiceScope);
|
||||
|
||||
|
||||
//Module
|
||||
|
@ -73,7 +75,7 @@ public class DiscordBotService
|
|||
Logger.Info($"Invite link: https://discord.com/api/oauth2/authorize?client_id={Client.CurrentUser.Id}&permissions=1099511696391&scope=bot%20applications.commands");
|
||||
Logger.Info($"Login as {Client.CurrentUser.Username}#{Client.CurrentUser.DiscriminatorValue}");
|
||||
|
||||
CreateCommands();
|
||||
Init();
|
||||
}
|
||||
|
||||
|
||||
|
@ -94,7 +96,7 @@ public class DiscordBotService
|
|||
}
|
||||
|
||||
#region InitLogic
|
||||
public async void CreateCommands()
|
||||
public async void Init()
|
||||
{
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
|
|
9
Moonlight/App/Services/Discord/DiscordLogging.cs
Normal file
9
Moonlight/App/Services/Discord/DiscordLogging.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
namespace Moonlight.App.Services.Discord;
|
||||
|
||||
public enum DiscordLogging
|
||||
{
|
||||
VeryImportant,
|
||||
System,
|
||||
Services,
|
||||
Ticket
|
||||
}
|
Loading…
Reference in a new issue