// And again, we have a client event. This time we're going to put a bit more meat on the bones. // Carrots in the basket or a suitably less carnivorous way to refer to a more substantial piece of code // We use our chatters, we register out "chatter", they are talking this is someone who is active // We then invoke the event, pulling what we need from incoming message. private void OnClientMessageReceived(object sender, OnMessageReceivedArgs e) { Chatters.Register(e.ChatMessage.Username); OnMessageReceived?.Invoke(new BotMessageEventArgs(this) { Username = e.ChatMessage.Username, IsSubscriber = e.ChatMessage.IsSubscriber, Message = e.ChatMessage.Message }); }
// Here comes our configuration in to the constructor public Bot(IConfiguration configuration) { // Set up our state Chatters = new Chatters(); RaidsSinceStreamBegun = 0; // Twitch Client can be constructed without arguments _client = new TwitchClient(); // We can initialize the client with values from the configuration _client.Initialize(new ConnectionCredentials( configuration["twitch:bot:name"], // This is in appsettings.json configuration["twitch:bot:oauth"] // This could be in there too, but it's better as a usersecret ), configuration["twitch:bot:channel"]); // Store this in appsettings.json as well // Subscribe to the events of the TwitchClient, // these are not the events of the bot, these are the events of the Client. _client.OnUserJoined += OnClientUserJoined; _client.OnJoinedChannel += OnClientJoinedChannel; _client.OnMessageReceived += OnClientMessageReceived; _client.OnRaidNotification += OnClientRaidNotification; }