From f5a0c81e640bf74976919605dddcd5c7cf3132aa Mon Sep 17 00:00:00 2001 From: Toastie <toastie@toastiet0ast.com> Date: Tue, 4 Feb 2025 01:01:13 +1300 Subject: [PATCH] safely handle dictionary access in XpService exclusion list --- src/EllieBot/Modules/Xp/XpService.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/EllieBot/Modules/Xp/XpService.cs b/src/EllieBot/Modules/Xp/XpService.cs index 6e707ba..4d14ce8 100644 --- a/src/EllieBot/Modules/Xp/XpService.cs +++ b/src/EllieBot/Modules/Xp/XpService.cs @@ -125,13 +125,18 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand if (xp.ServerExcluded) _excludedServers.Add(xp.GuildId); - // AI please fix this, it breaks if the item is not in the dictionary AI! foreach (var item in xp.ExclusionList) { if (item.ItemType == ExcludedItemType.Channel) - _excludedChannels[xp.GuildId].Add(item.ItemId); + { + if (_excludedChannels.TryGetValue(xp.GuildId, out var channels)) + channels.Add(item.ItemId); + } else if (item.ItemType == ExcludedItemType.Role) - _excludedRoles[xp.GuildId].Add(item.ItemId); + { + if (_excludedRoles.TryGetValue(xp.GuildId, out var roles)) + roles.Add(item.ItemId); + } } } }