public async Task InitializeAsync() { if (settings.Twitch.EnableChatBot) { client.Initialize(credentials, settings.Twitch.Channel); client.OnLog += Client_OnLog; client.OnMessageReceived += Client_OnMessageReceived; client.OnConnected += Client_OnConnected; client.OnDisconnected += Client_OnDisconnected; client.OnConnectionError += Client_OnConnectionError; client.Connect(); } if (settings.Twitch.EnablePubSub) { string channelId = await GetChannelId(); pubSub.ListenToRewards(channelId); pubSub.OnRewardRedeemed += PubSub_OnRewardRedeemed; pubSub.OnLog += PubSub_OnLog; pubSub.OnPubSubServiceConnected += PubSub_OnPubSubServiceConnected; pubSub.OnPubSubServiceError += PubSub_OnPubSubServiceError; pubSub.OnPubSubServiceClosed += PubSub_OnPubSubServiceClosed; pubSub.Connect(); } }
/// <summary> /// Async main method /// </summary> /// <param name="args">Arguments</param> /// <returns>the Task</returns> private async Task MainAsync(string[] args) { var channelId = mySettings.twitch.channelId; var clientId = mySettings.twitch.api.clientId; var secret = mySettings.twitch.api.secret; var accessToken = mySettings.twitch.token.userAccess; // Set up twitchlib api API = new AmongUsTwitchAPI(mySettings); API.getAPI().Settings.ClientId = clientId; API.getAPI().Settings.Secret = secret; //Set up twitchlib pubsub PubSub = new TwitchPubSub(); PubSub.OnListenResponse += OnListenResponse; PubSub.OnPubSubServiceConnected += OnPubSubServiceConnected; PubSub.OnPubSubServiceClosed += OnPubSubServiceClosed; PubSub.OnPubSubServiceError += OnPubSubServiceError; // Create Among Us Twitch Channel Points await API.CreateAmongUsTwitchRewards(); // Set up listeners ListenToRewards(channelId); // Connect to pubsub PubSub.Connect(); // Sets up the pipe server pipeServer = new NamedPipeServerStream("AmongUsTwitchModPipe", PipeDirection.InOut, 4); sw = new StreamWriter(pipeServer); sr = new StreamReader(pipeServer); _logger.Information("NamedPipeServerStream object created."); // Wait for a client to connect _logger.Information("Waiting for client connection..."); await pipeServer.WaitForConnectionAsync(); _logger.Information("Client connected."); // Keep the program going await Task.Delay(Timeout.Infinite); }
public void Init() { _client.ListenToSubscriptions(_twitchChannelId); _client.OnPubSubServiceConnected += OnPubSubServiceConnected; _client.Connect(); }