Skip to content

Commit dd779ef

Browse files
authored
Adds support for twitches soon to be forced SourceOnly flag (#771)
* Adds support for twitches soon to be forced SourceOnly flag * Adds support for twitches soon to be forced SourceOnly flag * Forgot to update access token * Cleaned up some old code * Fix tests
1 parent 2364ec8 commit dd779ef

31 files changed

Lines changed: 2179 additions & 66 deletions

DotNetTwitchBot.Test/Bot/Commands/Misc/RaidTrackerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public async Task OnIncomingRaid_NoneExisting_ShouldSucceed()
164164
//Assert
165165
dbContext.RaidHistory.Received(1).Update(Arg.Any<RaidHistoryEntry>());
166166
await dbContext.Received(1).SaveChangesAsync();
167-
await serviceBackbone.Received(1).SendChatMessage(Arg.Any<string>());
167+
await serviceBackbone.Received(1).SendChatMessage(Arg.Any<string>(), Arg.Any<bool>());
168168
}
169169

170170
[Fact]

DotNetTwitchBot.Test/Bot/Core/Points/TwitchEventsBonusTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public async Task OnCheer_ShouldAwardPointsForCheer()
6969
_serviceBackbone.CheerEvent += Raise.Event<AsyncEventHandler<CheerEventArgs>>(this, cheerEventArgs);
7070

7171
await _pointsSystem.Received(1).AddPointsByUserIdAndGame("user123", "TwitchEventBonus", 100);
72-
await _serviceBackbone.Received(1).SendChatMessage("TestUser just cheered 100 bits! sptvHype");
72+
await _serviceBackbone.Received(1).SendChatMessage("TestUser just cheered 100 bits! sptvHype", false);
7373
}
7474

7575
[Fact]
@@ -94,7 +94,7 @@ public async Task OnSubscription_ShouldAwardPointsForSubscription()
9494
//await _twitchEventsBonus.OnSubscription(this, subscriptionEventArgs);
9595

9696
await _pointsSystem.Received(1).AddPointsByUserIdAndGame("user123", "TwitchEventBonus", 500);
97-
await _serviceBackbone.Received(1).SendChatMessage("TestUser just subscribed for a total of 1 months and for 1 months in a row! sptvHype");
97+
await _serviceBackbone.Received(1).SendChatMessage("TestUser just subscribed for a total of 1 months and for 1 months in a row! sptvHype", false);
9898
}
9999

100100
[Fact]
@@ -117,7 +117,7 @@ public async Task OnSubscriptionGift_ShouldAwardPointsForSubscriptionGift()
117117
//await _twitchEventsBonus.OnSubScriptionGift(this, subscriptionGiftEventArgs);
118118

119119
await _pointsSystem.Received(1).AddPointsByUserIdAndGame("user123", "TwitchEventBonus", 2500);
120-
await _serviceBackbone.Received(1).SendChatMessage("TestUser gifted 5 subscriptions to the channel! sptvHype sptvHype sptvHype They have gifted a total of 10 subs to the channel!");
120+
await _serviceBackbone.Received(1).SendChatMessage("TestUser gifted 5 subscriptions to the channel! sptvHype sptvHype sptvHype They have gifted a total of 10 subs to the channel!", false);
121121
}
122122

123123
[Fact]

DotNetTwitchBot.sln

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 17
4-
VisualStudioVersion = 17.5.33414.496
3+
# Visual Studio Version 18
4+
VisualStudioVersion = 18.2.11415.280 d18.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetTwitchBot", "DotNetTwitchBot\DotNetTwitchBot.csproj", "{AAE6EFEA-8861-4AAA-B8D3-20163977C51C}"
77
EndProject
@@ -12,6 +12,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1212
.editorconfig = .editorconfig
1313
EndProjectSection
1414
EndProject
15+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TwitchLib.Api", "TwitchLib.Api\TwitchLib.Api\TwitchLib.Api.csproj", "{7BE46FB0-00E5-01EC-1D50-22FEBCF124CC}"
16+
EndProject
17+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TwitchLib.EventSub.Websockets", "TwitchLib.EventSub.Websockets\TwitchLib.EventSub.Websockets\TwitchLib.EventSub.Websockets.csproj", "{842D0F11-90CF-35F7-978C-606F4EEEE54D}"
18+
EndProject
1519
Global
1620
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1721
Debug|Any CPU = Debug|Any CPU
@@ -26,6 +30,14 @@ Global
2630
{01E5DBD1-FF3E-4C27-B47A-7485785AE23C}.Debug|Any CPU.Build.0 = Debug|Any CPU
2731
{01E5DBD1-FF3E-4C27-B47A-7485785AE23C}.Release|Any CPU.ActiveCfg = Release|Any CPU
2832
{01E5DBD1-FF3E-4C27-B47A-7485785AE23C}.Release|Any CPU.Build.0 = Release|Any CPU
33+
{7BE46FB0-00E5-01EC-1D50-22FEBCF124CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
34+
{7BE46FB0-00E5-01EC-1D50-22FEBCF124CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
35+
{7BE46FB0-00E5-01EC-1D50-22FEBCF124CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
36+
{7BE46FB0-00E5-01EC-1D50-22FEBCF124CC}.Release|Any CPU.Build.0 = Release|Any CPU
37+
{842D0F11-90CF-35F7-978C-606F4EEEE54D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38+
{842D0F11-90CF-35F7-978C-606F4EEEE54D}.Debug|Any CPU.Build.0 = Debug|Any CPU
39+
{842D0F11-90CF-35F7-978C-606F4EEEE54D}.Release|Any CPU.ActiveCfg = Release|Any CPU
40+
{842D0F11-90CF-35F7-978C-606F4EEEE54D}.Release|Any CPU.Build.0 = Release|Any CPU
2941
EndGlobalSection
3042
GlobalSection(SolutionProperties) = preSolution
3143
HideSolutionNode = FALSE

DotNetTwitchBot/Application/ChatMessage/Handlers/ReplyToMessageHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class ReplyToMessageHandler(ITwitchChatBot chatBot) : INotificationHandle
88
{
99
public Task Handle(ReplyToMessage request, CancellationToken cancellationToken)
1010
{
11-
return chatBot.ReplyToMessage(request.Name ,request.MessageId, request.Message);
11+
return chatBot.ReplyToMessage(request.Name, request.MessageId, request.Message);
1212
}
1313
}
1414
}

DotNetTwitchBot/Application/ChatMessage/Notifications/ReplyToMessage.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
namespace DotNetTwitchBot.Application.ChatMessage.Notifications
44
{
5-
public class ReplyToMessage(string name, string messageId, string message) : INotification
5+
public class ReplyToMessage(string name, string messageId, string message, bool sourceOnly = true) : INotification
66
{
77
public string Name { get; } = name;
88
public string MessageId { get; } = messageId;
99
public string Message { get; } = message;
10+
public bool SourceOnly { get; } = sourceOnly;
1011
}
1112
}

DotNetTwitchBot/Bot/Commands/BaseCommandService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ public async Task SendChatMessage(string name, string message)
3535
await ServiceBackbone.SendChatMessage(name, message);
3636
}
3737

38-
public async Task RespondWithMessage(CommandEventArgs e, string message)
38+
public async Task RespondWithMessage(CommandEventArgs e, string message, bool sourceOnly = true)
3939
{
4040
message = message.TrimStart('!').Trim();
4141

4242
if (string.IsNullOrWhiteSpace(e.MessageId))
4343
{
44-
await ServiceBackbone.SendChatMessage(e.DisplayName, message);
44+
await ServiceBackbone.SendChatMessage(e.DisplayName, message, sourceOnly);
4545
}
4646
else
4747
{
48-
await mediator.Publish(new ReplyToMessage(e.DisplayName, e.MessageId, message));
48+
await mediator.Publish(new ReplyToMessage(e.DisplayName, e.MessageId, message, sourceOnly));
4949
}
5050
}
5151

DotNetTwitchBot/Bot/Commands/CommandHandler.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public class CommandHandler(
2525

2626
public static bool CheckToRunBroadcasterOnly(CommandEventArgs eventArgs, BaseCommandProperties commandProperties)
2727
{
28+
if(commandProperties.SourceOnly && eventArgs.FromOwnChannel == false)
29+
{
30+
return false;
31+
}
2832
if (commandProperties.RunFromBroadcasterOnly == false) return true;
2933
if (eventArgs.FromOwnChannel == false) return false;
3034
return true;

DotNetTwitchBot/Bot/Commands/Custom/CustomCommand.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public async Task ReceivedChatMessage(ChatMessageEventArgs e)
273273
return;
274274
}
275275

276-
await ProcessTagsAndSayMessage(commandEventArgs, keyword.Keyword.Response, false);
276+
await ProcessTagsAndSayMessage(commandEventArgs, keyword.Keyword.Response, false, keyword.Keyword.SourceOnly);
277277

278278
if (keyword.Keyword.GlobalCooldown > 0)
279279
{
@@ -339,7 +339,7 @@ private async Task ExecuteCommand(CommandEventArgs e)
339339
}
340340
}
341341

342-
await ProcessTagsAndSayMessage(e, command.Response, command.RespondAsStreamer);
342+
await ProcessTagsAndSayMessage(e, command.Response, command.RespondAsStreamer, command.SourceOnly);
343343
if (command.GlobalCooldown > 0)
344344
{
345345
await CommandHandler.AddGlobalCooldown(e.Command, command.GlobalCooldown);
@@ -562,7 +562,7 @@ private Task<CustomCommandResult> GetResult(string tagName, CommandEventArgs eve
562562
};
563563
}
564564

565-
private async Task ProcessTagsAndSayMessage(CommandEventArgs eventArgs, string commandText, bool respondAsStreamer)
565+
private async Task ProcessTagsAndSayMessage(CommandEventArgs eventArgs, string commandText, bool respondAsStreamer, bool sourceOnly)
566566
{
567567
var messages = commandText.Split("\n");
568568
foreach (var oldMessage in messages)
@@ -582,11 +582,11 @@ private async Task ProcessTagsAndSayMessage(CommandEventArgs eventArgs, string c
582582
}
583583
else if (result.ReplyToMessage)
584584
{
585-
await ServiceBackbone.ResponseWithMessage(eventArgs, message);
585+
await ServiceBackbone.ResponseWithMessage(eventArgs, message, sourceOnly);
586586
}
587587
else
588588
{
589-
await ServiceBackbone.SendChatMessage(message);
589+
await ServiceBackbone.SendChatMessage(message, sourceOnly);
590590
}
591591
}
592592
}

DotNetTwitchBot/Bot/Commands/IBaseCommandService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ public interface IBaseCommandService
1515
Task OnCommand(object? sender, CommandEventArgs e);
1616
Task Register();
1717
Task<DefaultCommand> RegisterDefaultCommand(DefaultCommand defaultCommand);
18-
Task RespondWithMessage(CommandEventArgs e, string message);
18+
Task RespondWithMessage(CommandEventArgs e, string message, bool sourceOnly = true);
1919
}
2020
}

DotNetTwitchBot/Bot/Commands/Misc/RaidTracker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private async Task OnIncomingRaid(object? sender, RaidEventArgs e)
109109

110110
public async Task OnIncomingRaid(RaidEventArgs e)
111111
{
112-
await ServiceBackbone.SendChatMessage($"{e.DisplayName} just raided with {e.NumberOfViewers} viewers! sptvHype");
112+
await ServiceBackbone.SendChatMessage($"{e.DisplayName} just raided with {e.NumberOfViewers} viewers! sptvHype", false);
113113
try
114114
{
115115
await using var scope = _scopeFactory.CreateAsyncScope();

0 commit comments

Comments
 (0)