From ba8b81a9a76b7669725e88999bf87678ee2d6dba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=E2=96=88=E2=96=88=E2=96=88=E2=96=88=E2=96=88?= Date: Sun, 9 Feb 2025 15:57:36 -0500 Subject: [PATCH] fix: Index out of range exception in Cheap Viewers rule Need to generalize this and clean up the code later but this at least fixes the immediate issue with the method. nullinside-development-group/nullinside-api-twitch-bot#63 --- .../ChatRules/BestCheapViewersTests.cs | 2 ++ src/Nullinside.Api.TwitchBot.Tests/ChatRules/DoghypeTests.cs | 1 + src/Nullinside.Api.TwitchBot/ChatRules/BestCheapViewers.cs | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Nullinside.Api.TwitchBot.Tests/ChatRules/BestCheapViewersTests.cs b/src/Nullinside.Api.TwitchBot.Tests/ChatRules/BestCheapViewersTests.cs index 88007ed..40141a0 100644 --- a/src/Nullinside.Api.TwitchBot.Tests/ChatRules/BestCheapViewersTests.cs +++ b/src/Nullinside.Api.TwitchBot.Tests/ChatRules/BestCheapViewersTests.cs @@ -15,6 +15,8 @@ public class BestCheapViewersTests : AChatRuleUnitTestBase { /// /// The string that should fail. [Test] + [TestCase("C\u032dheap viewe\u034crs on\u0306 vwrpro.ru @8v2JcQFL")] + [TestCase("Ch\u031ae\u0345ap viewers on *** @STGPMoLg")] [TestCase("Best\u036e vie\u0350wers \u0337on ***")] [TestCase("Best viewers on ***")] [TestCase("Best viewers on ***")] diff --git a/src/Nullinside.Api.TwitchBot.Tests/ChatRules/DoghypeTests.cs b/src/Nullinside.Api.TwitchBot.Tests/ChatRules/DoghypeTests.cs index e1e71ce..aa484df 100644 --- a/src/Nullinside.Api.TwitchBot.Tests/ChatRules/DoghypeTests.cs +++ b/src/Nullinside.Api.TwitchBot.Tests/ChatRules/DoghypeTests.cs @@ -15,6 +15,7 @@ public class DogehypeTests : AChatRuleUnitTestBase { /// /// The string that should fail. [Test] + [TestCase("Visit dogehype dot com today and effortlessly boost your Twitch rankings! @opAzPMVt")] [TestCase("Visit dogehype dot com and watch your channel grow today! @5MGxTnYl")] [TestCase("Visit dogehype dot com today and climb the Twitch rankings with ease! Whether you're just starting out or looking to take your stream to the next level, DogeHype has the tools you need to succeed. @gqznceDC")] [TestCase("Visit dogehype .biz com today and climb the Twitch rankings with ease! Whether you're just starting out or looking to take your stream to the next level, DogeHype has the tools you need to succeed. @Axxq7ntz")] diff --git a/src/Nullinside.Api.TwitchBot/ChatRules/BestCheapViewers.cs b/src/Nullinside.Api.TwitchBot/ChatRules/BestCheapViewers.cs index 5af5588..a3c8c27 100644 --- a/src/Nullinside.Api.TwitchBot/ChatRules/BestCheapViewers.cs +++ b/src/Nullinside.Api.TwitchBot/ChatRules/BestCheapViewers.cs @@ -47,7 +47,7 @@ public override async Task Handle(string channelId, ITwitchApiProxy botPro int offset = 0; for (int i = 0; i < expected.Length; i++) { // If this is a normal character it should be in the correct position. - if (normalized[i + offset] == expected[i]) { + if (i + offset < normalized.Length && normalized[i + offset] == expected[i]) { ++matches; } // If this is an accent mark then the next character should match and the whole string we're evalutating