public ValueTask Register(IMessageContextSink messageContextSink) { var api = new TwitchAPI(); api.Settings.ClientId = _twitchSettings.ClientId; api.Settings.Secret = _twitchSettings.ClientSecret; AccessToken = api.V5.Root.GetAccessToken(); // var client = _factory.CreateClient(); // var url = $"https://id.twitch.tv/oauth2/token?grant_type=client_credentials&client_id={_twitchSettings.ClientId}&client_secret={_twitchSettings.ClientSecret}&scope=user_read"; // var kraken_rul = "https://api.twitch.tv/kraken/user"; // var tokenResponse = await client.PostAsync(url, null); // var dict = JsonConvert.DeserializeObject<Dictionary<string, object>>(await tokenResponse.Content.ReadAsStringAsync()); // var AccessToken = dict["access_token"].ToString(); _pubsub.OnPubSubServiceConnected += (s, e) => { _pubsub.ListenToFollows("428420296"); //pubsub.ListenToSubscriptions("428420296"); _pubsub.SendTopics(AccessToken); }; _pubsub.OnFollow += (s, e) => messageContextSink.Send(new( new TwitchFollow(e.Username), e.FollowedChannelId, Constants.Sources.TwitchPubsub )); _pubsub.OnChannelSubscription += (s, e) => messageContextSink.Send(new( new TwitchSubscription( e.Subscription.UserId, e.Subscription.Username, e.Subscription.Time, e.Subscription.TotalMonths, e.Subscription.StreakMonths, e.Subscription.Context ), e.Subscription.ChannelId, Constants.Sources.TwitchPubsub )); _pubsub.Connect(); return(ValueTask.CompletedTask); }
public ValueTask Register(IMessageContextSink messageContextSink) { _client.OnMessageReceived += (s, e) => { var msg = e.ChatMessage; messageContextSink.Send(new( new CustomerMessage(msg.Username, msg.Message), msg.Channel, Constants.Sources.TwitchChat )); }; _client.OnJoinedChannel += (s, e) => messageContextSink.Send(new( new SendTwitchPublicMessage(e.Channel, "Moist Bot in the building, behave."), e.Channel, Constants.Sources.TwitchChat )); _client.Connect(); return(ValueTask.CompletedTask); }