Misc fixes and edits

This commit is contained in:
Noi 2022-09-20 20:39:37 -07:00
parent c4c13b733f
commit 911ae63713
3 changed files with 6 additions and 14 deletions

View file

@ -68,8 +68,8 @@ partial class RegexbotClient {
// Attempt warning message // Attempt warning message
var userSearch = _svcEntityCache.QueryUserCache(targetUser.ToString()); var userSearch = _svcEntityCache.QueryUserCache(targetUser.ToString());
var userDisp = userSearch != null var userDisp = userSearch != null
? $" user **{userSearch.Username}#{userSearch.Discriminator}**" ? $"**{userSearch.Username}#{userSearch.Discriminator}**"
: $" user with ID **{targetUser}**"; : $"user with ID **{targetUser}**";
var targetGuildUser = guild.GetUser(targetUser); var targetGuildUser = guild.GetUser(targetUser);
if (targetGuildUser == null) return (entry, new LogAppendResult( if (targetGuildUser == null) return (entry, new LogAppendResult(
new HttpException(System.Net.HttpStatusCode.NotFound, null), entry.LogId, userDisp)); new HttpException(System.Net.HttpStatusCode.NotFound, null), entry.LogId, userDisp));

View file

@ -4,12 +4,6 @@ using RegexBot.Data;
namespace RegexBot.Services.CommonFunctions; namespace RegexBot.Services.CommonFunctions;
internal partial class CommonFunctionsService : Service { 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. // Called by EF_Removals, this processes a removal into a log entry.
// A notification for this entry is then propagated. // A notification for this entry is then propagated.
private void ModLogsProcessRemoval(ulong guildId, ulong targetId, ModLogType remType, string source, string? logReason) { private void ModLogsProcessRemoval(ulong guildId, ulong targetId, ModLogType remType, string source, string? logReason) {

View file

@ -14,6 +14,7 @@ internal partial class CommonFunctionsService : Service {
if (t == RemovalType.Kick && utarget == null) return new BanKickResult(null, false, true, RemovalType.Kick, 0); if (t == RemovalType.Kick && utarget == null) return new BanKickResult(null, false, true, RemovalType.Kick, 0);
// Send DM notification // Send DM notification
// Must be done before removal, or we risk not being able to send a notification afterwards
if (sendDmToTarget) { if (sendDmToTarget) {
if (utarget != null) dmSuccess = await BanKickSendNotificationAsync(utarget, t, logReason); if (utarget != null) dmSuccess = await BanKickSendNotificationAsync(utarget, t, logReason);
else dmSuccess = false; else dmSuccess = false;
@ -27,11 +28,9 @@ internal partial class CommonFunctionsService : Service {
} catch (HttpException ex) { } catch (HttpException ex) {
return new BanKickResult(ex, dmSuccess, false, t, target); 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); 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<bool> BanKickSendNotificationAsync(SocketGuildUser target, RemovalType action, string? reason) { private async Task<bool> BanKickSendNotificationAsync(SocketGuildUser target, RemovalType action, string? reason) {
@ -41,10 +40,9 @@ internal partial class CommonFunctionsService : Service {
var outMessage = string.IsNullOrWhiteSpace(reason) var outMessage = string.IsNullOrWhiteSpace(reason)
? string.Format(DMTemplate + ".", action == RemovalType.Ban ? "banned" : "kicked", target.Guild.Name) ? string.Format(DMTemplate + ".", action == RemovalType.Ban ? "banned" : "kicked", target.Guild.Name)
: string.Format(DMTemplate + DMTemplateReason, action == RemovalType.Ban ? "banned" : "kicked", target.Guild.Name, reason); : string.Format(DMTemplate + DMTemplateReason, action == RemovalType.Ban ? "banned" : "kicked", target.Guild.Name, reason);
var dch = await target.CreateDMChannelAsync(); var dch = await target.CreateDMChannelAsync();
try { await dch.SendMessageAsync(outMessage); } catch (HttpException) { return false; } try { await dch.SendMessageAsync(outMessage); } catch (HttpException) { return false; }
return true; return true;
} }
} }