private void Initialize() { string payload = $"@badge-info=subscriber/1;badges=moderator/1,subscriber/0;client-nonce=60576a3018294221da54321a7397db58;color=;display-name=francoe1;emotes=;first-msg=0;flags=;id=9e4e255d-3c8d-4cdb-88ca-62ab7a3c37a9;mod=1;room-id=130747120;subscriber=1;tmi-sent-ts=1635094303777;turbo=0;user-id=147383910;user-type=mod :[email protected] PRIVMSG #rhomita :{COMMAND_NAME} {COMMAND_PARAMS}"; TwitchInputLine command = new TwitchInputLine(payload, COMMAND_PREFIX); TwitchChatMessageParser message = new TwitchChatMessageParser(command); _command = new TwitchChatCommand(message.User, message.Sent, message.Bits, message.Id); _handler = new TwitchCommandHandler(COMMAND_PREFIX); }
public void ReadMessageChatTextWithEspecialCharacters() { const string MESSAGE = "BEGIN <> !� {} \\ // ' \" :) :| @: #~$%&/()=^^^^^^****���� END"; string PAYLOAD = $"@badge-info=subscriber/1;badges=moderator/1,subscriber/0;client-nonce=b185f1767a4a2a8d5786a41f9de64a77;color=;display-name=francoe1;emotes=;first-msg=0;flags=;id=e83072fb-51b3-4217-a746-ff6e23ae09b7;mod=1;room-id=130747120;subscriber=1;tmi-sent-ts=1635094309746;turbo=0;user-id=147383910;user-type=mod :[email protected] PRIVMSG #rhomita :{MESSAGE}"; TwitchInputLine command = new TwitchInputLine(PAYLOAD, COMMAND_PREFIX); TwitchChatMessageParser message = new TwitchChatMessageParser(command); TwitchChatMessage chatCommand = new TwitchChatMessage(message.User, message.Sent, message.Bits, message.Id); Assert.IsTrue(chatCommand.Message == MESSAGE); }
public void ReadMessageChatCommandTest() { const string COMMAND = "!start"; string PAYLOAD = $"@badge-info=subscriber/1;badges=moderator/1,subscriber/0;client-nonce=60576a3018294221da54321a7397db58;color=;display-name=francoe1;emotes=;first-msg=0;flags=;id=9e4e255d-3c8d-4cdb-88ca-62ab7a3c37a9;mod=1;room-id=130747120;subscriber=1;tmi-sent-ts=1635094303777;turbo=0;user-id=147383910;user-type=mod :[email protected] PRIVMSG #rhomita :{COMMAND}"; TwitchInputLine command = new TwitchInputLine(PAYLOAD, COMMAND_PREFIX); TwitchChatMessageParser message = new TwitchChatMessageParser(command); TwitchChatCommand chatCommand = new TwitchChatCommand(message.User, message.Sent, message.Bits, message.Id); Assert.IsTrue(chatCommand.Command == COMMAND); }
public void ReadMessageTest() { const string MESSAGE_ID = ""; const string MESSAGE_SENT = "!command_name"; const int MESSAGE_BIT = 0; const int MESSAGE_BADGES_COUNT = 2; const string USER_ID = "00000000000"; const string USER_DISPLAY_NAME = "user_display_name"; string PAYLOAD = $"@badge-info=subscriber/1;badges=moderator/1,subscriber/0;client-nonce=60576a3018294221da54321a7397db58;color=;display-name={USER_DISPLAY_NAME};emotes=;first-msg=0;flags=;id=9e4e255d-3c8d-4cdb-88ca-62ab7a3c37a9;mod=1;room-id=130747120;subscriber=1;tmi-sent-ts=1635094303777;turbo=0;user-id={USER_ID};user-type=mod :[email protected] PRIVMSG #rhomita :{MESSAGE_SENT}"; TwitchInputLine command = new TwitchInputLine(PAYLOAD, COMMAND_PREFIX); TwitchChatMessageParser message = new TwitchChatMessageParser(command); Assert.AreEqual(message.Id, MESSAGE_ID, "Invalid message id"); Assert.AreEqual(message.Sent, MESSAGE_SENT, "Invalid message sent"); Assert.AreEqual(message.Bits, MESSAGE_BIT, "Invalid user display name"); Assert.AreEqual(message.Badges.Count, MESSAGE_BADGES_COUNT, "Invalid user display name"); Assert.IsNotNull(message.User, "Invalid user data"); Assert.AreEqual(message.User.Id, USER_ID, "Invalid user id"); Assert.AreEqual(message.User.DisplayName, USER_DISPLAY_NAME, "Invalid user display name"); }
private void ReadChatLine() { if (_twitchClient.Available <= 0) { return; } string source = _reader.ReadLine(); TwitchInputLine inputLine = new TwitchInputLine(source, _commandPrefix); onTwitchInputLine?.Invoke(inputLine); switch (inputLine.Type) { case TwitchInputType.LOGIN: if (inputLine.IsValidLogin(_twitchConnectConfig)) { _isAuthenticated = true; _onSuccess?.Invoke(); _onSuccess = null; Debug.Log("<color=green>¡Success Twitch Connection!</color>"); } else { _onError?.Invoke(LOGIN_WRONG_USERNAME); _onError = null; Debug.Log("<color=red>¡Error Twitch Connection: Token is valid but it belongs to another user!</color>"); } break; case TwitchInputType.NOTICE: string lineMessage = inputLine.Message; string userErrorMessage; string errorMessage; if (lineMessage.Contains(TwitchChatRegex.LOGIN_FAILED_MESSAGE)) { userErrorMessage = LOGIN_FAILED_MESSAGE; errorMessage = LOGIN_FAILED_MESSAGE; } else if (lineMessage.Contains(TwitchChatRegex.LOGIN_WRONG_REQUEST_MESSAGE)) { userErrorMessage = LOGIN_WRONG_REQUEST_MESSAGE; errorMessage = LOGIN_WRONG_REQUEST_MESSAGE; } else { userErrorMessage = LOGIN_UNEXPECTED_ERROR_MESSAGE; errorMessage = lineMessage; } _onError?.Invoke(userErrorMessage); _onError = null; Debug.Log($"<color=red>Twitch connection error: {errorMessage}</color>"); break; case TwitchInputType.PING: _writer.WriteLine(COMMAND_PONG); _writer.Flush(); break; case TwitchInputType.MESSAGE_COMMAND: { TwitchChatMessageParser payload = new TwitchChatMessageParser(inputLine); TwitchChatCommand chatCommand = new TwitchChatCommand(payload.User, payload.Sent, payload.Bits, payload.Id); onChatCommandReceived?.Invoke(chatCommand); } break; case TwitchInputType.MESSAGE_CHAT: { TwitchChatMessageParser payload = new TwitchChatMessageParser(inputLine); TwitchChatMessage chatMessage = new TwitchChatMessage(payload.User, payload.Sent, payload.Bits, payload.Id); onChatMessageReceived?.Invoke(chatMessage); } break; case TwitchInputType.MESSAGE_REWARD: { TwitchChatRewardParser payload = new TwitchChatRewardParser(inputLine); TwitchChatReward chatReward = new TwitchChatReward(payload.User, payload.Sent, payload.Id); onChatRewardReceived?.Invoke(chatReward); } break; case TwitchInputType.JOIN: TwitchUserManager.AddUser(inputLine.UserName); break; case TwitchInputType.PART: TwitchUserManager.RemoveUser(inputLine.UserName); break; } }