TwitchLib / TwitchLib.Client

Client component of TwitchLib.
39 stars 61 forks source link

Client events not firing? #190

Closed A5ho9999 closed 2 years ago

A5ho9999 commented 2 years ago

After updating to April 28th prerelease and removing the deprecated packages some Client events seem to be broken in some way. I don't get any errors from it but when these events should fire Client events just stop working. The events I know that seem to have an issue are the events related to Re/new subscriptions and Gifting as well as Raids. Other events like the message received work find until one of those events are triggered then the Client no longer responds to further events but is still connected. Sorry for the lack of information in this one but it's all I have.

Edit: Also forgot to add, even when removing listening to the events it still seems to happen when the action is done in the channel.

Syzuna commented 2 years ago

I setup a test and everything seems to work as expected with the latest dev branch. Raids worked without killing the client. Sub Bomb and its indiividual 5 gifted subs events worked without killing the client.

So cant replicate.

A5ho9999 commented 2 years ago

I'm not sure what has happened, it was working fine before update and removing old packages. I made no actual code changes.

Tested more with a raid and the event isn't even firing. The data is received but the event itself it's trigger, tested with breakpoints to see if it was.

Here is all the information I have

Client Settings

ClientOptions Options = new()
{
    MessagesAllowedInPeriod = 100,
    ThrottlingPeriod = TimeSpan.FromSeconds(60),
};
WebSocketClient WebSocket = new(Options);

Client = new TwitchClient(WebSocket);
Client.OnError += OnError;
Client.OnIncorrectLogin += OnIncorrectLogin;
Client.OnConnectionError += OnConnectionError;
Client.OnNoPermissionError +=OnNoPermissionError;
Client.OnFailureToReceiveJoinConfirmation += OnFailureToReceiveJoinConfirmation;
Client.OnConnected += OnConnected;
Client.OnDisconnected += OnDisconnected;
Client.OnReconnected += OnReconnected;
Client.OnSendReceiveData += OnSendReceiveData;
Client.OnJoinedChannel += OnJoinedChannel;
Client.OnLeftChannel += OnLeftChannel;
Client.OnMessageReceived += OnMessageReceived;
Client.OnMessageSent += OnMessageSent;
Client.OnUserJoined += OnUserJoined;
Client.OnUserLeft += OnUserLeft;

Client.OnRaidNotification += OnRaidNotification;

Raid Method

private void OnRaidNotification(object sender, OnRaidNotificationArgs e)
{
        Console.WriteLine("raid");
}

Console Output

[11/05/2022:11:56:14 AM] | [Twitch] | [Received] :tmi.twitch.tv 001 lordbloobbot :Welcome, GLHF!
[11/05/2022:11:56:14 AM] | [Twitch] | [Received] :tmi.twitch.tv 002 lordbloobbot :Your host is tmi.twitch.tv
[11/05/2022:11:56:14 AM] | [Twitch] | [Received] :tmi.twitch.tv 003 lordbloobbot :This server is rather new
[11/05/2022:11:56:14 AM] | [Twitch] | [Received] :tmi.twitch.tv 004 lordbloobbot :-
[11/05/2022:11:56:14 AM] | [Twitch] | **Twitch Client is connected**.
[11/05/2022:11:56:14 AM] | [Twitch] | [Received] :tmi.twitch.tv 375 lordbloobbot :-
[11/05/2022:11:56:14 AM] | [Twitch] | [Received] :tmi.twitch.tv 372 lordbloobbot :You are in a maze of twisty passages, all alike.
[11/05/2022:11:56:14 AM] | [Twitch] | [Received] :tmi.twitch.tv 376 lordbloobbot :>
[11/05/2022:11:56:14 AM] | [Twitch] | [Received] :tmi.twitch.tv CAP * ACK :twitch.tv/membership
[11/05/2022:11:56:14 AM] | [Twitch] | [Received] :tmi.twitch.tv CAP * ACK :twitch.tv/commands
[11/05/2022:11:56:14 AM] | [Twitch] | [Received] :tmi.twitch.tv CAP * ACK :twitch.tv/tags
[11/05/2022:11:56:14 AM] | [Twitch] | [Received] :lordbloobbot!lordbloobbot@lordbloobbot.tmi.twitch.tv JOIN #elainettie
[11/05/2022:11:56:14 AM] | [Twitch] | lordbloobbot joined the Stream
[11/05/2022:11:56:16 AM] | [Twitch] | [Received] :lordbloobbot.tmi.twitch.tv 353 lordbloobbot = #elainettie :lordbloobbot
[11/05/2022:11:56:16 AM] | [Twitch] | [Received] :lordbloobbot.tmi.twitch.tv 366 lordbloobbot #elainettie :End of /NAMES list
[11/05/2022:11:56:16 AM] | [Twitch] | [Received] @badge-info=;badges=moderator/1;color=;display-name=lordbloobbot;emote-sets=0,0849a24f-a026-43d3-9edc-0b5406890256;mod=1;subscriber=0;user-type=mod :tmi.twitch.tv USERSTATE #elainettie
[11/05/2022:11:56:16 AM] | [Twitch] | [Received] @emote-only=0;followers-only=-1;r9k=0;rituals=0;room-id=652106707;slow=0;subs-only=0 :tmi.twitch.tv ROOMSTATE #elainettie
[11/05/2022:11:56:16 AM] | [Twitch] | **Connected to `elainettie`**.
[11/05/2022:11:56:16 AM] | [Twitch] | **Connected to PubSub Server**.
[11/05/2022:11:56:16 AM] | [Twitch] | {"type":"RESPONSE","error":"","nonce":"8BcWWFoJ"}

[11/05/2022:11:56:24 AM] | [Twitch] | [Received] :kattynah!kattynah@kattynah.tmi.twitch.tv JOIN #elainettie
[11/05/2022:11:56:24 AM] | [Twitch] | kattynah joined the Stream
[11/05/2022:11:56:24 AM] | [Twitch] | [Received] :mooseref!mooseref@mooseref.tmi.twitch.tv JOIN #elainettie
[11/05/2022:11:56:24 AM] | [Twitch] | mooseref joined the Stream
[11/05/2022:11:56:25 AM] | [Twitch] | [Received] :waptart!waptart@waptart.tmi.twitch.tv JOIN #elainettie
[11/05/2022:11:56:25 AM] | [Twitch] | waptart joined the Stream
[11/05/2022:11:56:25 AM] | [Twitch] | [Received] :yeezyjesuspeezus!yeezyjesuspeezus@yeezyjesuspeezus.tmi.twitch.tv JOIN #elainettie
[11/05/2022:11:56:25 AM] | [Twitch] | yeezyjesuspeezus joined the Stream
[11/05/2022:11:56:25 AM] | [Twitch] | [Received] :rogueg1rl!rogueg1rl@rogueg1rl.tmi.twitch.tv JOIN #elainettie
[11/05/2022:11:56:25 AM] | [Twitch] | rogueg1rl joined the Stream
[11/05/2022:11:56:26 AM] | [Twitch] | [Received] :aboutw!aboutw@aboutw.tmi.twitch.tv JOIN #elainettie
[11/05/2022:11:56:26 AM] | [Twitch] | aboutw joined the Stream
[11/05/2022:11:56:26 AM] | [Twitch] | [Received] :soupat2!soupat2@soupat2.tmi.twitch.tv JOIN #elainettie
[11/05/2022:11:56:26 AM] | [Twitch] | soupat2 joined the Stream
[11/05/2022:11:56:26 AM] | [Twitch] | [Received] :la_kaylee!la_kaylee@la_kaylee.tmi.twitch.tv JOIN #elainettie
[11/05/2022:11:56:26 AM] | [Twitch] | la_kaylee joined the Stream
[11/05/2022:11:56:26 AM] | [Twitch] | [Received] :lanarayyyy!lanarayyyy@lanarayyyy.tmi.twitch.tv JOIN #elainettie
[11/05/2022:11:56:26 AM] | [Twitch] | lanarayyyy joined the Stream
[11/05/2022:11:56:27 AM] | [Twitch] | [Received] :nekochanbot7837!nekochanbot7837@nekochanbot7837.tmi.twitch.tv JOIN #elainettie
[11/05/2022:11:56:27 AM] | [Twitch] | nekochanbot7837 joined the Stream
[11/05/2022:11:56:27 AM] | [Twitch] | [Received] :academyimpossible!academyimpossible@academyimpossible.tmi.twitch.tv JOIN #elainettie
[11/05/2022:11:56:27 AM] | [Twitch] | academyimpossible joined the Stream
[11/05/2022:11:56:27 AM] | [Twitch] | [Received] :losjaraswines!losjaraswines@losjaraswines.tmi.twitch.tv JOIN #elainettie
[11/05/2022:11:56:27 AM] | [Twitch] | losjaraswines joined the Stream
[11/05/2022:11:56:28 AM] | [Twitch] | [Received] :business_daddy!business_daddy@business_daddy.tmi.twitch.tv JOIN #elainettie
[11/05/2022:11:56:28 AM] | [Twitch] | business_daddy joined the Stream
[11/05/2022:11:56:28 AM] | [Twitch] | [Received] :damethedime!damethedime@damethedime.tmi.twitch.tv JOIN #elainettie
[11/05/2022:11:56:28 AM] | [Twitch] | damethedime joined the Stream
[11/05/2022:11:56:28 AM] | [Twitch] | [Received] :streamelements!streamelements@streamelements.tmi.twitch.tv JOIN #elainettie
[11/05/2022:11:56:28 AM] | [Twitch] | streamelements joined the Stream
[11/05/2022:11:56:30 AM] | [Twitch] | [Received] @badge-info=founder/14;badges=moderator/1,founder/0,hype-train/2;client-nonce=3465e19f872d137293892bedb3fb1c0c;color=#8D02B3;display-name=NekoChanBot7837;emotes=;first-msg=0;flags=;id=2b3a0ba6-f519-403b-8ccd-e2afb98d2c1a;mod=1;room-id=652106707;subscriber=1;tmi-sent-ts=1652235989876;turbo=0;user-id=245737288;user-type=mod :nekochanbot7837!nekochanbot7837@nekochanbot7837.tmi.twitch.tv PRIVMSG #elainettie :message
[11/05/2022:11:56:30 AM] | [Twitch] | Message Received: NekoChanBot7837: message
[11/05/2022:11:56:57 AM] | [Twitch] | [Received] @badge-info=founder/14;badges=moderator/1,founder/0,hype-train/2;color=#8D02B3;display-name=NekoChanBot7837;emotes=;flags=;id=a57eb4f0-fed4-4982-a858-2186f525eec7;login=nekochanbot7837;mod=1;msg-id=raid;msg-param-displayName=NekoChanBot7837;msg-param-login=nekochanbot7837;msg-param-profileImageURL=https://static-cdn.jtvnw.net/jtv_user_pictures/21ed8b47-d00c-451e-968d-5a861e4b7967-profile_image-70x70.png;msg-param-viewerCount=1;room-id=652106707;subscriber=1;system-msg=1\sraiders\sfrom\sNekoChanBot7837\shave\sjoined!;tmi-sent-ts=1652236016915;user-id=245737288;user-type=mod :tmi.twitch.tv USERNOTICE #elainettie
[11/05/2022:11:59:16 AM] | [Twitch] | { "type": "PONG" }

[11/05/2022:12:02:16 PM] | [Twitch] | { "type": "PONG" }
Mahsaap commented 2 years ago

Have you tried the events that are not working on their own? Add onlog event as well to help

Syzuna commented 2 years ago

I wish I could help you in any way right now but all my attempts to replicate your issue fail. I even tested it on the exact same channel as you but it still went through.

info: TwitchLib.Client.TwitchClient[0]
      [TwitchLib, 3.2.6.0] Received: @badge-info=;badges=twitchconEU2019/1;color=#B22222;display-name=Syzuna;emotes=;flags=;id=87b22e55-3c17-4033-81e4-c7ec80fd1b0a;login=syzuna;mod=0;msg-id=raid;msg-param-displayName=Syzuna;msg-param-login=syzuna;msg-param-profileImageURL=https://static-cdn.jtvnw.net/jtv_user_pictures/syzuna-profile_image-ef6a295b96ae24fd-70x70.jpeg;msg-param-viewerCount=1;room-id=652106707;subscriber=0;system-msg=1\sraiders\sfrom\sSyzuna\shave\sjoined!;tmi-sent-ts=1652273189208;user-id=102943601;user-type= :tmi.twitch.tv USERNOTICE #elainettie      
info: ClientTest.Worker[0]
      New Raid from syzuna to elainettie with 1 viewers
Mahsaap commented 2 years ago

Is it possible you can post the whole client settings? I don't see connect in what you showed. I realise this had worked before the update but we have no clue ATM. Also what version did you update from and what framework?

A5ho9999 commented 2 years ago

I'm not too sure on the last version I was using. I'll try to revert to older ones today to see if it'll still work. I'll provide the current code setup, it's ran along side a Discord Bot so I've edited out most of that as it shouldn't be effecting anything.

Using .NET 6

internal class Program
{
    static async Task Main(string[] args) => await ConnectClient.RunAsync();
}
internal static async Task RunAsync()
{
    using var services = ConfigureServices(config);
    {
         services.GetRequiredService<TwitchHandler>().TwitchConnect();
         await Task.Delay(Timeout.Infinite);
    }
}
private static ServiceProvider ConfigureServices()
{
    return new ServiceCollection()
        .AddSingleton<TwitchHandler>()
        .BuildServiceProvider();
}
public class TwitchHandler
    {
        private static LiveStreamMonitorService Monitor;
        private static TwitchClient Client;
        private static TwitchPubSub PubSub;
        private static ITwitchAPI API;
        private static IServiceProvider Services;

        private static readonly ClientOptions Options;
        private static readonly WebSocketClient WebSocket;

        private static readonly ConnectionCredentials Credentials = new(TwitchConfig.BotName, TwitchConfig.BloobAccess);

        public TwitchHandler(IServiceProvider services)
        {
                Services = services;

                ClientOptions Options = new()
                {
                    MessagesAllowedInPeriod = 100,
                    ThrottlingPeriod = TimeSpan.FromSeconds(60),
                };
                WebSocketClient WebSocket = new(Options);

                API = new TwitchAPI();
                API.Settings.ClientId = TwitchConfig.TwitchClient;
                API.Settings.AccessToken = TwitchConfig.OAuthToken;
                API.Settings.Secret = TwitchConfig.ClientSecret;

                Client = new TwitchClient(WebSocket);
                Client.OnError += OnError;
                Client.OnIncorrectLogin += OnIncorrectLogin;
                Client.OnConnectionError += OnConnectionError;
                Client.OnNoPermissionError += OnNoPermissionError;
                Client.OnFailureToReceiveJoinConfirmation += OnFailureToReceiveJoinConfirmation;
                Client.OnConnected += OnConnected;
                Client.OnDisconnected += OnDisconnected;
                Client.OnReconnected += OnReconnected;
                Client.OnSendReceiveData += OnSendReceiveData;
                Client.OnJoinedChannel += OnJoinedChannel;
                Client.OnLeftChannel += OnLeftChannel;
                Client.OnMessageReceived += OnMessageReceived;
                Client.OnMessageSent += OnMessageSent;
                Client.OnUserJoined += OnUserJoined;
                Client.OnUserLeft += OnUserLeft;
                Client.OnChatCleared += OnChatCleared;
                Client.OnMessageCleared += OnMessageCleared;
                Client.OnUserBanned += OnUserBanned;
                Client.OnUserTimedout += OnUserTimedout;
                Client.OnRaidNotification += OnRaidNotification;

                Monitor = new LiveStreamMonitorService(API, 30);
                Monitor.OnStreamOnline += Monitor_OnStreamOnline;
                Monitor.OnStreamOffline += Monitor_OnStreamOffline;

                PubSub = new TwitchPubSub();
                PubSub.OnListenResponse += OnListenResponse;
                PubSub.OnPubSubServiceConnected += OnPubSubServiceConnected;
                PubSub.OnPubSubServiceClosed += OnPubSubServiceClosed;
                PubSub.OnPubSubServiceError += OnPubSubServiceError;
                PubSub.OnLog += PubSub_OnLog;

                ListenToBits(TwitchConfig.ChannelId);
                ListenToFollows(TwitchConfig.ChannelId);
                ListenToChannelPoints(TwitchConfig.ChannelId);
                ListenToSubs(TwitchConfig.ChannelId);
                ListenToVideoPlayback(TwitchConfig.ChannelId);
        }

        internal void TwitchConnect()
        {
                List<string> MonitorList = new() { TwitchConfig.ChannelName };

                Monitor.SetChannelsByName(MonitorList);
                Client.Initialize(Credentials);

                Monitor.Start();
                Client.Connect();
                PubSub.Connect();
        }
}

Edit: Unable to currently check previous versions due to a loading error with visual studio itself, waiting to hear back from windows support >-<

A5ho9999 commented 2 years ago

So I was able to successfully detect a raid event after reverting Client, Client Enums and Models back to 3.2.0, without making any code changes.

Syzuna commented 2 years ago

Thats really weird... Like you can see in the logs I posted I am using 3.2.6 from the latest dev branch release and it worked perfectly fine the whole evening for me detecting multiple raids, some sub gifts and so on.... Also using .NET 6 there. Is there really no error log or any exception log anywhere? without one its like impossible to pin the root cause I'm afraid

A5ho9999 commented 2 years ago

Nope, just tried all possible sections with catching any exception and OnLog and nothing. Just same the result of the event not firing after receiving the data. Going to slowly check each version to see where it actually stops working.

A5ho9999 commented 2 years ago

Okay so I tried all the releases up to 3.2.5 and then all the pre-release from there, They all worked fine until the latest 3.2.6-preview-6109ec73405e067631aac6c8c837bc87dec6ad63 for the Client. Enums and Models were fine on the latest release. So I really have no idea what is happening here.

Syzuna commented 2 years ago

ok so the latest preview added announcements... they are a USERNOTICE like raids... were there any announcements before you tested raids?

Syzuna commented 2 years ago

ok no... annoucements work as intended so those shouldnt cause internal issues

A5ho9999 commented 2 years ago

Yeah was just having a quick look over the announcement changes, but wouldn't make much sense if there was an issue but working for you as well. Went to go test the announcements and found "Reference to type 'Announcement' claims it is defined in 'TwitchLib.Client.Models', but it could not be found" when attempting to access the OnAnnouncementArgs? I have the latest Models and Enums being 3.2.5-preview-eb210b24b724f0df6e3ce9566fe25ba3ce6ab13f

Syzuna commented 2 years ago

wait why are those still 3.2.5... I did forget to bump their version didnt I... fml... but that shouldnt be an issue... you have the wrong version of them tho the commit sha in the package name should be 6109ec73405e067631aac6c8c837bc87dec6ad63

or 68b54074c332c2df84025bb1798568ac16aafc66 with the new release now

sadly nuget sorts them wrong sometimes...

A5ho9999 commented 2 years ago

Yup, that would appear to be it, switching to 6109ec7 and the raid event triggers fine. bad nuget

Syzuna commented 2 years ago

well also partly my fault bcs I forgot to bump 2 nugets version numbers x.x

A5ho9999 commented 2 years ago

It happens, Thanks for sticking with me through this pain T-T Updated to the new ones and is still working fine ^ - ^