diff --git a/Services/CommonFunctions/CF_ModLogs.Hooks.cs b/Services/CommonFunctions/CF_ModLogs.Hooks.cs index 2823e83..5dce387 100644 --- a/Services/CommonFunctions/CF_ModLogs.Hooks.cs +++ b/Services/CommonFunctions/CF_ModLogs.Hooks.cs @@ -68,8 +68,8 @@ partial class RegexbotClient { // Attempt warning message var userSearch = _svcEntityCache.QueryUserCache(targetUser.ToString()); var userDisp = userSearch != null - ? $" user **{userSearch.Username}#{userSearch.Discriminator}**" - : $" user with ID **{targetUser}**"; + ? $"**{userSearch.Username}#{userSearch.Discriminator}**" + : $"user with ID **{targetUser}**"; var targetGuildUser = guild.GetUser(targetUser); if (targetGuildUser == null) return (entry, new LogAppendResult( new HttpException(System.Net.HttpStatusCode.NotFound, null), entry.LogId, userDisp)); diff --git a/Services/CommonFunctions/CF_ModLogs.cs b/Services/CommonFunctions/CF_ModLogs.cs index 48c5fb8..ab1cf81 100644 --- a/Services/CommonFunctions/CF_ModLogs.cs +++ b/Services/CommonFunctions/CF_ModLogs.cs @@ -4,12 +4,6 @@ using RegexBot.Data; namespace RegexBot.Services.CommonFunctions; internal partial class CommonFunctionsService : Service { - - // things this should do: - // set a note - // set a warn (like note, but spicy) - // -> return with a WarnLogResult? And send it down the chute... - // Called by EF_Removals, this processes a removal into a log entry. // A notification for this entry is then propagated. private void ModLogsProcessRemoval(ulong guildId, ulong targetId, ModLogType remType, string source, string? logReason) { diff --git a/Services/CommonFunctions/CF_Removals.cs b/Services/CommonFunctions/CF_Removals.cs index 1dd5126..e543203 100644 --- a/Services/CommonFunctions/CF_Removals.cs +++ b/Services/CommonFunctions/CF_Removals.cs @@ -14,6 +14,7 @@ internal partial class CommonFunctionsService : Service { if (t == RemovalType.Kick && utarget == null) return new BanKickResult(null, false, true, RemovalType.Kick, 0); // Send DM notification + // Must be done before removal, or we risk not being able to send a notification afterwards if (sendDmToTarget) { if (utarget != null) dmSuccess = await BanKickSendNotificationAsync(utarget, t, logReason); else dmSuccess = false; @@ -27,11 +28,9 @@ internal partial class CommonFunctionsService : Service { } catch (HttpException ex) { return new BanKickResult(ex, dmSuccess, false, t, target); } - - // Report successful action - var result = new BanKickResult(null, dmSuccess, false, t, target); ModLogsProcessRemoval(guild.Id, target, t == RemovalType.Ban ? ModLogType.Ban : ModLogType.Kick, source, logReason); - return result; + + return new BanKickResult(null, dmSuccess, false, t, target); } private async Task BanKickSendNotificationAsync(SocketGuildUser target, RemovalType action, string? reason) { @@ -41,10 +40,9 @@ internal partial class CommonFunctionsService : Service { var outMessage = string.IsNullOrWhiteSpace(reason) ? string.Format(DMTemplate + ".", action == RemovalType.Ban ? "banned" : "kicked", target.Guild.Name) : string.Format(DMTemplate + DMTemplateReason, action == RemovalType.Ban ? "banned" : "kicked", target.Guild.Name, reason); + var dch = await target.CreateDMChannelAsync(); - try { await dch.SendMessageAsync(outMessage); } catch (HttpException) { return false; } - return true; } } \ No newline at end of file