From fdd23ad00f2e3704b3c65c5de1f995569317fe80 Mon Sep 17 00:00:00 2001 From: Daan Boerlage Date: Tue, 19 Jul 2022 16:22:46 +0200 Subject: [PATCH] Fix some unchecked access in the giveRole function in the reactionListener that would crash the bot if an expected value wasn't around --- src/Core/ReactionListener/ReactionListener.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Core/ReactionListener/ReactionListener.cs b/src/Core/ReactionListener/ReactionListener.cs index 84367c9..c90316e 100644 --- a/src/Core/ReactionListener/ReactionListener.cs +++ b/src/Core/ReactionListener/ReactionListener.cs @@ -70,7 +70,10 @@ namespace Geekbot.Core.ReactionListener public async void GiveRole(ISocketMessageChannel channel, SocketReaction reaction) { - var roleId = _listener[reaction.MessageId][reaction.Emote]; + _listener.TryGetValue(reaction.MessageId, out var registeredReactions); + if (registeredReactions == null) return; + if (!registeredReactions.ContainsKey(reaction.Emote)) return; + var roleId = registeredReactions[reaction.Emote]; var guild = (SocketGuildChannel) channel; var role = guild.Guild.GetRole(roleId); await ((IGuildUser) reaction.User.Value).AddRoleAsync(role);