private async Task TwitchClient_OnGiftedSubscription(TwitchMessage.GiftSub giftSub) { // if the gift sub is to a channel we're in (and it's for the bot), send the celebratory messages if (_tokens.UserId == giftSub.RecipientId && _client.JoinedChannels.Contains(giftSub.Channel)) { _logger.LogInformation("We got gifted a subscription to channel {ChannelId}!", giftSub.RoomId); await _mediator.Send(new SendMessageRequest(giftSub.RoomId, $"🎉 Thanks for the gift sub @{giftSub.SenderDisplayName}! 🎉")); await _mediator.Publish(new GenerateMessageNotification(giftSub.RoomId)); } }
public async Task TwitchClientShouldSupportReceivingGiftSubs() { // Arrange var client = new TwitchClient(_output.BuildLoggerFor <TwitchClient>()); TwitchMessage.GiftSub giftSub = null; var cts = new CancellationTokenSource(); cts.CancelAfter(TimeSpan.FromMinutes(1)); async Task ReadLoop() { while (client.IsConnected && giftSub is null) { giftSub = await client.ReadMessageAsync <TwitchMessage.GiftSub>(token : cts.Token); } } // Act await client.ConnectAsync("fdgttest", "", serverUri : "wss://irc.fdgt.dev"); var readTask = ReadLoop(); await client.JoinChannelAsync("fdgt"); while (!client.JoinedChannels.Contains("fdgt")) { ; } await client.SendChatMessageAsync("fdgt", "subgift --count 25 --userid 123 --userid2 456 --channelid 789"); await readTask; // Assert Assert.NotNull(giftSub); Assert.Equal("fdgt", giftSub.Channel); Assert.Equal("fdgttest", giftSub.SenderUserName); }