diff --git a/ModularAssistentForDiscordServer/Commands/Slash/About.cs b/ModularAssistentForDiscordServer/Commands/Slash/About.cs index 2a8d3cf..57b035d 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/About.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/About.cs @@ -20,7 +20,7 @@ namespace MADS.Commands.Slash; -public class About : MadsBaseApplicationCommand +public sealed class About : MadsBaseApplicationCommand { [SlashCommand("about", "Infos about the bot")] public async Task AboutCommand(InteractionContext ctx) diff --git a/ModularAssistentForDiscordServer/Commands/Slash/BotStats.cs b/ModularAssistentForDiscordServer/Commands/Slash/BotStats.cs index 614c4c8..3e204b6 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/BotStats.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/BotStats.cs @@ -25,7 +25,7 @@ namespace MADS.Commands.Slash; -public class BotStats : MadsBaseApplicationCommand +public sealed class BotStats : MadsBaseApplicationCommand { private IDbContextFactory _contextFactory; private DiscordRestClient _discordRestClient; diff --git a/ModularAssistentForDiscordServer/Commands/Slash/Jumpad.cs b/ModularAssistentForDiscordServer/Commands/Slash/Jumpad.cs index 1c8177e..d81db95 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/Jumpad.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/Jumpad.cs @@ -21,7 +21,7 @@ namespace MADS.Commands.Slash; [GuildOnly] -public class Jumppad : MadsBaseApplicationCommand +public sealed class Jumppad : MadsBaseApplicationCommand { [SlashCommand("jumppad", "Create a jumppad button"), SlashCommandPermissions(Permissions.MoveMembers)] public async Task Test diff --git a/ModularAssistentForDiscordServer/Commands/Slash/MessageSnipe.cs b/ModularAssistentForDiscordServer/Commands/Slash/MessageSnipe.cs index 8586e5b..45e0844 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/MessageSnipe.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/MessageSnipe.cs @@ -22,7 +22,7 @@ namespace MADS.Commands.Slash; -public class MessageSnipe : MadsBaseApplicationCommand +public sealed class MessageSnipe : MadsBaseApplicationCommand { private MessageSnipeService _messageSnipeService; @@ -60,8 +60,7 @@ private async Task DoSnipeAsync(InteractionContext ctx, bool edit) if (!result) { - await ctx.EditResponseAsync( - new DiscordWebhookBuilder().WithContent("⚠️ No message to snipe! Either nothing was deleted, or the message has expired (12 hours)!")); + await EditResponse_Error("⚠️ No message to snipe! Either nothing was deleted, or the message has expired (12 hours)!"); return; } diff --git a/ModularAssistentForDiscordServer/Commands/Slash/NoBtches.cs b/ModularAssistentForDiscordServer/Commands/Slash/NoBtches.cs index 50390bc..22674ce 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/NoBtches.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/NoBtches.cs @@ -17,7 +17,7 @@ namespace MADS.Commands.Slash; -public class NoBtches : MadsBaseApplicationCommand +public sealed class NoBtches : MadsBaseApplicationCommand { [SlashCommand("nobtches", "nobtches api")] public async Task PingCommand diff --git a/ModularAssistentForDiscordServer/Commands/Slash/Ping.cs b/ModularAssistentForDiscordServer/Commands/Slash/Ping.cs index 2d204e7..e0d1722 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/Ping.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/Ping.cs @@ -18,7 +18,7 @@ namespace MADS.Commands.Slash; -public class Ping : MadsBaseApplicationCommand +public sealed class Ping : MadsBaseApplicationCommand { [SlashCommand("ping", "Get the bot's ping")] public async Task PingCommand(InteractionContext ctx) diff --git a/ModularAssistentForDiscordServer/Commands/Slash/Purge.cs b/ModularAssistentForDiscordServer/Commands/Slash/Purge.cs index 8acd319..8503d44 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/Purge.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/Purge.cs @@ -20,7 +20,7 @@ namespace MADS.Commands.Slash; -public class Purge : MadsBaseApplicationCommand +public sealed class Purge : MadsBaseApplicationCommand { [SlashCommand("purge", "Purges messages"), SlashRequirePermissions(Permissions.ManageMessages), @@ -32,7 +32,7 @@ public async Task PurgeMessages { if (amount > 100) { - await ctx.CreateResponseAsync("You cannot purge more than 100 messages at once", true); + await CreateResponse_Error("You cannot purge more than 100 messages at once", true); return; } diff --git a/ModularAssistentForDiscordServer/Commands/Slash/Quotes.cs b/ModularAssistentForDiscordServer/Commands/Slash/Quotes.cs index f437214..92240b0 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/Quotes.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/Quotes.cs @@ -23,7 +23,7 @@ namespace MADS.Commands.Slash; [SlashCommandGroup("Quotes", "Commands related to adding and retrieving quotes"), SlashRequireGuild] -public class Quotes : MadsBaseApplicationCommand +public sealed class Quotes : MadsBaseApplicationCommand { private QuotesService _quotesService; diff --git a/ModularAssistentForDiscordServer/Commands/Slash/Reminder.cs b/ModularAssistentForDiscordServer/Commands/Slash/Reminder.cs index c63aa2d..70be7ab 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/Reminder.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/Reminder.cs @@ -26,7 +26,7 @@ namespace MADS.Commands.Slash; [SlashCommandGroup("reminder", "mangage reminders")] -public class Reminder : MadsBaseApplicationCommand +public sealed class Reminder : MadsBaseApplicationCommand { private ReminderService _reminderService; @@ -50,7 +50,7 @@ public async Task AddReminder if (timeSpan is null) { - await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Invalid timespan (5s, 3m, 7h, 2d)")); + await EditResponse_Error("Invalid timespan (5s, 3m, 7h, 2d)"); return; } @@ -66,9 +66,7 @@ public async Task AddReminder await _reminderService.AddReminder(newReminder); - await ctx.EditResponseAsync( - new DiscordWebhookBuilder().WithContent( - $"Reminder created. I will remind you in {Formatter.Timestamp(timeSpan.Value)}")); + await EditResponse_Success($"Reminder created. I will remind you in {Formatter.Timestamp(timeSpan.Value)}"); } [SlashCommand("list", "list your Reminder")] @@ -107,7 +105,7 @@ long id if (reminder is null) { - await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Reminder does not exsists")); + await EditResponse_Error("Reminder does not exists"); return; } @@ -115,8 +113,7 @@ long id if (!success) { - await ctx.EditResponseAsync( - new DiscordWebhookBuilder().WithContent("Something went wrong. Please try again")); + await EditResponse_Error("Something went wrong. Please try again"); return; } diff --git a/ModularAssistentForDiscordServer/Commands/Slash/RoleSelection.cs b/ModularAssistentForDiscordServer/Commands/Slash/RoleSelection.cs index dc3d432..e78608b 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/RoleSelection.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/RoleSelection.cs @@ -18,10 +18,11 @@ using DSharpPlus.SlashCommands; using DSharpPlus.SlashCommands.Attributes; using MADS.Extensions; +using Serilog; namespace MADS.Commands.Slash; -public class RoleSelection : MadsBaseApplicationCommand +public sealed class RoleSelection : MadsBaseApplicationCommand { [SlashCommand("RoleSelection", "Use this command in the channel the message should be posted"), SlashRequirePermissions(Permissions.ManageRoles), diff --git a/ModularAssistentForDiscordServer/Commands/Slash/StarboardConfig.cs b/ModularAssistentForDiscordServer/Commands/Slash/StarboardConfig.cs index c2113e0..80aed56 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/StarboardConfig.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/StarboardConfig.cs @@ -24,7 +24,7 @@ namespace MADS.Commands.Slash; -public class StarboardConfig : MadsBaseApplicationCommand +public sealed class StarboardConfig : MadsBaseApplicationCommand { private static readonly Regex EmoteRegex = new(@"^<(?a)?:(?[a-zA-Z0-9_]+?):(?\d+?)>$", RegexOptions.ECMAScript | RegexOptions.Compiled); diff --git a/ModularAssistentForDiscordServer/Commands/Slash/VoiceAlerts.cs b/ModularAssistentForDiscordServer/Commands/Slash/VoiceAlerts.cs index 741e896..0c2b707 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/VoiceAlerts.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/VoiceAlerts.cs @@ -24,7 +24,7 @@ namespace MADS.Commands.Slash; [SlashCommandGroup("voicealerts", "mangage voicealerts")] -public class VoiceAlerts : MadsBaseApplicationCommand +public sealed class VoiceAlerts : MadsBaseApplicationCommand { private VoiceAlertService _voiceAlertService; diff --git a/ModularAssistentForDiscordServer/Commands/Slash/moveEmoji.cs b/ModularAssistentForDiscordServer/Commands/Slash/moveEmoji.cs index 595b2f9..04874c7 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/moveEmoji.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/moveEmoji.cs @@ -23,7 +23,7 @@ namespace MADS.Commands.Slash; -public class MoveEmoji : MadsBaseApplicationCommand +public sealed class MoveEmoji : MadsBaseApplicationCommand { private const string EmojiRegex = @""; @@ -38,7 +38,7 @@ await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWith if (!matches.Any()) { - await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("There are no emojis in your input")); + await EditResponse_Error("There are no emojis in your input"); return; } @@ -47,7 +47,10 @@ await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWith var animated = matches[0].Value.StartsWith(" guilds = new(); @@ -63,8 +66,7 @@ await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWith if (!guilds.Any()) { - await ctx.EditResponseAsync( - new DiscordWebhookBuilder().WithContent("There are no guilds where you are able to add emojis")); + await EditResponse_Error("There are no guilds where you are able to add emojis"); return; } @@ -104,7 +106,7 @@ await ctx.EditResponseAsync(new DiscordWebhookBuilder await CopyEmoji(ctx.Client, emojiName, emojiId, animated, guildId); } - await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("End")); + await EditResponse_Success("Emoji moved"); } private static async Task CopyEmoji(DiscordClient client, string name, ulong id, bool animated, ulong targetGuild) diff --git a/ModularAssistentForDiscordServer/Commands/Text/Base/Eval.cs b/ModularAssistentForDiscordServer/Commands/Text/Base/Eval.cs index 5799376..7b093c0 100644 --- a/ModularAssistentForDiscordServer/Commands/Text/Base/Eval.cs +++ b/ModularAssistentForDiscordServer/Commands/Text/Base/Eval.cs @@ -50,7 +50,7 @@ public async Task EvalCommand(CommandContext ctx, [RemainingText] string code) var scriptOptions = ScriptOptions.Default; scriptOptions = scriptOptions.WithImports("System", "System.Collections.Generic", "System.Linq", "System.Text", "System.Threading.Tasks", "DSharpPlus", "DSharpPlus.Entities", "DSharpPlus.CommandsNext", - "DSharpPlus.Interactivity", "DSharpPlus.Rest", "DSharpPlus.SlashCommands", "DSharpPlus.VoiceNext", + "DSharpPlus.Interactivity", "DSharpPlus.SlashCommands", "MADS", "Humanizer"); scriptOptions = scriptOptions.WithReferences(AppDomain.CurrentDomain.GetAssemblies() .Where(assembly => diff --git a/ModularAssistentForDiscordServer/Commands/Text/Base/ExitGuild.cs b/ModularAssistentForDiscordServer/Commands/Text/Base/ExitGuild.cs index a62400d..cf80a26 100644 --- a/ModularAssistentForDiscordServer/Commands/Text/Base/ExitGuild.cs +++ b/ModularAssistentForDiscordServer/Commands/Text/Base/ExitGuild.cs @@ -34,4 +34,11 @@ public async Task LeaveGuildOwner(CommandContext ctx) await ctx.Message.DeleteAsync(); await ctx.Guild.LeaveAsync(); } + + [Command("test"), Description("Leave given server"), RequireGuild, Hidden, RequireOwner] + public async Task Test(CommandContext ctx) + { + var usr1 = await ctx.Client.GetUserAsync(262722553380864011); + await ctx.RespondAsync(usr1.Username); + } } \ No newline at end of file diff --git a/ModularAssistentForDiscordServer/ModularAssistentForDiscordServer.csproj b/ModularAssistentForDiscordServer/ModularAssistentForDiscordServer.csproj index 0ac823a..ae77a57 100644 --- a/ModularAssistentForDiscordServer/ModularAssistentForDiscordServer.csproj +++ b/ModularAssistentForDiscordServer/ModularAssistentForDiscordServer.csproj @@ -42,11 +42,11 @@ - - - - - - + + + + + + diff --git a/ModularAssistentForDiscordServer/Program.cs b/ModularAssistentForDiscordServer/Program.cs index 46a2dfb..7d73203 100644 --- a/ModularAssistentForDiscordServer/Program.cs +++ b/ModularAssistentForDiscordServer/Program.cs @@ -28,7 +28,7 @@ namespace MADS; internal static class MainProgram { - public static void Main() + public async static Task Main() { Log.Logger = new LoggerConfiguration() .WriteTo.Console() @@ -55,17 +55,14 @@ public static void Main() //Create a discordWebhookClient and add the debug webhook from the config.json var webhookClient = new DiscordWebhookClient(); var webhookUrl = new Uri(config.DiscordWebhook); - webhookClient.AddWebhookAsync(webhookUrl).GetAwaiter().GetResult(); - - //loop while the bot shouldn't be canceled - //while (!cancellationSource.IsCancellationRequested) - //{ + await webhookClient.AddWebhookAsync(webhookUrl); + //Create a new instance of the bot ModularDiscordBot modularDiscordBot = new(); //execute the bot and catch uncaught exceptions try { - modularDiscordBot.RunAsync(cancellationSource.Token).GetAwaiter().GetResult(); + await modularDiscordBot.RunAsync(cancellationSource.Token); } catch (Exception e) { @@ -73,15 +70,8 @@ public static void Main() var _ = LogToWebhookAsync(e); } - - try - { - Task.Delay(10_000, cancellationSource.Token).GetAwaiter().GetResult(); - } - catch (TaskCanceledException) - { - } - //} + + cancellationSource.Token.WaitHandle.WaitOne(); } private static bool ValidateConfig() diff --git a/ModularAssistentForDiscordServer/Services/DiscordClientService.cs b/ModularAssistentForDiscordServer/Services/DiscordClientService.cs index 4c4cf00..eaff538 100644 --- a/ModularAssistentForDiscordServer/Services/DiscordClientService.cs +++ b/ModularAssistentForDiscordServer/Services/DiscordClientService.cs @@ -129,7 +129,7 @@ public async Task StartAsync(CancellationToken cancellationToken) var context = await _dbContextFactory.CreateDbContextAsync(); if ((await context.Database.GetPendingMigrationsAsync()).Any()) await context.Database.MigrateAsync(); - + DiscordActivity act = new("over some Servers", ActivityType.Watching); diff --git a/ModularAssistentForDiscordServer/config.json b/ModularAssistentForDiscordServer/config.json index 6c7d90a..498f542 100644 --- a/ModularAssistentForDiscordServer/config.json +++ b/ModularAssistentForDiscordServer/config.json @@ -1,7 +1,9 @@ { - "token": "", + "token": "", "defaultPrefix": "!", "minmumloglvl": 1, "databaseConnectionString": "Server=192.168.178.61,Port=3306;Database=MadsDB;User=USR;Password=PWD;", + "databaseConnectionStringQuartz": "Server=192.168.178.61,Port=3306;Database=MadsDB;User=USR;Password=PWD;", + "discordWebhook": null, "DmProxyChannelId": 0 } \ No newline at end of file