Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DotNetTwitchBot.Test/Bot/Commands/Misc/RaidTrackerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public async Task OnIncomingRaid_NoneExisting_ShouldSucceed()
//Assert
dbContext.RaidHistory.Received(1).Update(Arg.Any<RaidHistoryEntry>());
await dbContext.Received(1).SaveChangesAsync();
await serviceBackbone.Received(1).SendChatMessage(Arg.Any<string>());
await serviceBackbone.Received(1).SendChatMessage(Arg.Any<string>(), Arg.Any<bool>());
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public async Task OnCheer_ShouldAwardPointsForCheer()
_serviceBackbone.CheerEvent += Raise.Event<AsyncEventHandler<CheerEventArgs>>(this, cheerEventArgs);

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

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

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

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

await _pointsSystem.Received(1).AddPointsByUserIdAndGame("user123", "TwitchEventBonus", 2500);
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!");
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);
}

[Fact]
Expand Down
16 changes: 14 additions & 2 deletions DotNetTwitchBot.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33414.496
# Visual Studio Version 18
VisualStudioVersion = 18.2.11415.280 d18.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetTwitchBot", "DotNetTwitchBot\DotNetTwitchBot.csproj", "{AAE6EFEA-8861-4AAA-B8D3-20163977C51C}"
EndProject
Expand All @@ -12,6 +12,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TwitchLib.Api", "TwitchLib.Api\TwitchLib.Api\TwitchLib.Api.csproj", "{7BE46FB0-00E5-01EC-1D50-22FEBCF124CC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TwitchLib.EventSub.Websockets", "TwitchLib.EventSub.Websockets\TwitchLib.EventSub.Websockets\TwitchLib.EventSub.Websockets.csproj", "{842D0F11-90CF-35F7-978C-606F4EEEE54D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -26,6 +30,14 @@ Global
{01E5DBD1-FF3E-4C27-B47A-7485785AE23C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{01E5DBD1-FF3E-4C27-B47A-7485785AE23C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{01E5DBD1-FF3E-4C27-B47A-7485785AE23C}.Release|Any CPU.Build.0 = Release|Any CPU
{7BE46FB0-00E5-01EC-1D50-22FEBCF124CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7BE46FB0-00E5-01EC-1D50-22FEBCF124CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7BE46FB0-00E5-01EC-1D50-22FEBCF124CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7BE46FB0-00E5-01EC-1D50-22FEBCF124CC}.Release|Any CPU.Build.0 = Release|Any CPU
{842D0F11-90CF-35F7-978C-606F4EEEE54D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{842D0F11-90CF-35F7-978C-606F4EEEE54D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{842D0F11-90CF-35F7-978C-606F4EEEE54D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{842D0F11-90CF-35F7-978C-606F4EEEE54D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class ReplyToMessageHandler(ITwitchChatBot chatBot) : INotificationHandle
{
public Task Handle(ReplyToMessage request, CancellationToken cancellationToken)
{
return chatBot.ReplyToMessage(request.Name ,request.MessageId, request.Message);
return chatBot.ReplyToMessage(request.Name, request.MessageId, request.Message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace DotNetTwitchBot.Application.ChatMessage.Notifications
{
public class ReplyToMessage(string name, string messageId, string message) : INotification
public class ReplyToMessage(string name, string messageId, string message, bool sourceOnly = true) : INotification
{
public string Name { get; } = name;
public string MessageId { get; } = messageId;
public string Message { get; } = message;
public bool SourceOnly { get; } = sourceOnly;
}
}
6 changes: 3 additions & 3 deletions DotNetTwitchBot/Bot/Commands/BaseCommandService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ public async Task SendChatMessage(string name, string message)
await ServiceBackbone.SendChatMessage(name, message);
}

public async Task RespondWithMessage(CommandEventArgs e, string message)
public async Task RespondWithMessage(CommandEventArgs e, string message, bool sourceOnly = true)
{
message = message.TrimStart('!').Trim();

if (string.IsNullOrWhiteSpace(e.MessageId))
{
await ServiceBackbone.SendChatMessage(e.DisplayName, message);
await ServiceBackbone.SendChatMessage(e.DisplayName, message, sourceOnly);
}
else
{
await mediator.Publish(new ReplyToMessage(e.DisplayName, e.MessageId, message));
await mediator.Publish(new ReplyToMessage(e.DisplayName, e.MessageId, message, sourceOnly));
}
}

Expand Down
4 changes: 4 additions & 0 deletions DotNetTwitchBot/Bot/Commands/CommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public class CommandHandler(

public static bool CheckToRunBroadcasterOnly(CommandEventArgs eventArgs, BaseCommandProperties commandProperties)
{
if(commandProperties.SourceOnly && eventArgs.FromOwnChannel == false)
{
return false;
}
if (commandProperties.RunFromBroadcasterOnly == false) return true;
if (eventArgs.FromOwnChannel == false) return false;
return true;
Expand Down
10 changes: 5 additions & 5 deletions DotNetTwitchBot/Bot/Commands/Custom/CustomCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public async Task ReceivedChatMessage(ChatMessageEventArgs e)
return;
}

await ProcessTagsAndSayMessage(commandEventArgs, keyword.Keyword.Response, false);
await ProcessTagsAndSayMessage(commandEventArgs, keyword.Keyword.Response, false, keyword.Keyword.SourceOnly);

if (keyword.Keyword.GlobalCooldown > 0)
{
Expand Down Expand Up @@ -339,7 +339,7 @@ private async Task ExecuteCommand(CommandEventArgs e)
}
}

await ProcessTagsAndSayMessage(e, command.Response, command.RespondAsStreamer);
await ProcessTagsAndSayMessage(e, command.Response, command.RespondAsStreamer, command.SourceOnly);
if (command.GlobalCooldown > 0)
{
await CommandHandler.AddGlobalCooldown(e.Command, command.GlobalCooldown);
Expand Down Expand Up @@ -562,7 +562,7 @@ private Task<CustomCommandResult> GetResult(string tagName, CommandEventArgs eve
};
}

private async Task ProcessTagsAndSayMessage(CommandEventArgs eventArgs, string commandText, bool respondAsStreamer)
private async Task ProcessTagsAndSayMessage(CommandEventArgs eventArgs, string commandText, bool respondAsStreamer, bool sourceOnly)
{
var messages = commandText.Split("\n");
foreach (var oldMessage in messages)
Expand All @@ -582,11 +582,11 @@ private async Task ProcessTagsAndSayMessage(CommandEventArgs eventArgs, string c
}
else if (result.ReplyToMessage)
{
await ServiceBackbone.ResponseWithMessage(eventArgs, message);
await ServiceBackbone.ResponseWithMessage(eventArgs, message, sourceOnly);
}
else
{
await ServiceBackbone.SendChatMessage(message);
await ServiceBackbone.SendChatMessage(message, sourceOnly);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion DotNetTwitchBot/Bot/Commands/IBaseCommandService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public interface IBaseCommandService
Task OnCommand(object? sender, CommandEventArgs e);
Task Register();
Task<DefaultCommand> RegisterDefaultCommand(DefaultCommand defaultCommand);
Task RespondWithMessage(CommandEventArgs e, string message);
Task RespondWithMessage(CommandEventArgs e, string message, bool sourceOnly = true);
}
}
2 changes: 1 addition & 1 deletion DotNetTwitchBot/Bot/Commands/Misc/RaidTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private async Task OnIncomingRaid(object? sender, RaidEventArgs e)

public async Task OnIncomingRaid(RaidEventArgs e)
{
await ServiceBackbone.SendChatMessage($"{e.DisplayName} just raided with {e.NumberOfViewers} viewers! sptvHype");
await ServiceBackbone.SendChatMessage($"{e.DisplayName} just raided with {e.NumberOfViewers} viewers! sptvHype", false);
try
{
await using var scope = _scopeFactory.CreateAsyncScope();
Expand Down
8 changes: 4 additions & 4 deletions DotNetTwitchBot/Bot/Commands/Misc/ShoutoutSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ public async Task OnChatMessage(ChatMessageEventArgs e)
}
if (autoShoutout != null)
{
await Shoutout(name, autoShoutout.AutoPlayClip);
await Shoutout(name, autoShoutout.AutoPlayClip, true, false);
}
}

private async Task Shoutout(string name, bool playClip, bool useAi = true)
private async Task Shoutout(string name, bool playClip, bool useAi, bool sourceOnly)
{
AutoShoutout? autoShoutout = null;
await using (var scope = _scopeFactory.CreateAsyncScope())
Expand Down Expand Up @@ -128,7 +128,7 @@ private async Task Shoutout(string name, bool playClip, bool useAi = true)
}

message = message.Replace("(name)", name).Replace("(game)", game);
await ServiceBackbone.SendChatMessage(message);
await ServiceBackbone.SendChatMessage(message, false);
if(playClip) await _clipService.PlayRandomClipForStreamer(name);

await TwitchShoutOut(userId);
Expand Down Expand Up @@ -200,7 +200,7 @@ public override async Task OnCommand(object? sender, CommandEventArgs e)
{
throw new SkipCooldownException();
}
await Shoutout(e.TargetUser, true);
await Shoutout(e.TargetUser, true, true, command.CommandProperties.SourceOnly);
break;
}
}
Expand Down
8 changes: 4 additions & 4 deletions DotNetTwitchBot/Bot/Core/IServiceBackbone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public interface IServiceBackbone
Task OnUserLeft(string username);
Task OnWhisperCommand(CommandEventArgs command);
Task RunCommand(CommandEventArgs eventArgs);
Task SendChatMessage(string message);
Task SendChatMessage(string name, string message);
Task SendChatMessageWithTitle(string viewerName, string message);
Task SendChatMessage(string message, bool sourceOnly = true);
Task SendChatMessage(string name, string message, bool sourceOnly = true);
Task SendChatMessageWithTitle(string viewerName, string message, bool sourceOnly = true);
Task OnViewerBan(string userId, string username, bool unbanned, DateTimeOffset? endsAt);
Task ResponseWithMessage(CommandEventArgs e, string message);
Task ResponseWithMessage(CommandEventArgs e, string message, bool sourceOnly = true);
}
}
8 changes: 4 additions & 4 deletions DotNetTwitchBot/Bot/Core/Points/TwitchEventsBonus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private async Task OnCheer(object sender, CheerEventArgs e)
{
if (string.IsNullOrWhiteSpace(e.Name) || e.IsAnonymous || string.IsNullOrWhiteSpace(e.UserId))
{
await ServiceBackbone.SendChatMessage($"Someone just cheered {e.Amount} bits! sptvHype");
await ServiceBackbone.SendChatMessage($"Someone just cheered {e.Amount} bits! sptvHype", false);
return;
}
try
Expand All @@ -86,7 +86,7 @@ private async Task OnCheer(object sender, CheerEventArgs e)
var pointType = await pointsSystem.GetPointTypeForGame(ModuleName);
logger.LogInformation("Gave {name} {points} {PointType} for cheering.", e.Name, pointsToAward, pointType.Name);
await pointsSystem.AddPointsByUserIdAndGame(e.UserId, ModuleName, pointsToAward);
await ServiceBackbone.SendChatMessage($"{e.DisplayName} just cheered {e.Amount} bits! sptvHype");
await ServiceBackbone.SendChatMessage($"{e.DisplayName} just cheered {e.Amount} bits! sptvHype", false);
}
}
catch (Exception ex)
Expand All @@ -109,7 +109,7 @@ private async Task OnSubScriptionGift(object sender, SubscriptionGiftEventArgs a
{
message += $" They have gifted a total of {args.TotalGifted} subs to the channel!";
}
await ServiceBackbone.SendChatMessage(message);
await ServiceBackbone.SendChatMessage(message, false);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -171,7 +171,7 @@ private async Task OnSubscription(object sender, SubscriptionEventArgs e)
}

message += "! sptvHype";
await ServiceBackbone.SendChatMessage(message);
await ServiceBackbone.SendChatMessage(message, false);

}
catch (Exception ex)
Expand Down
12 changes: 6 additions & 6 deletions DotNetTwitchBot/Bot/Core/ServiceBackbone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,30 +106,30 @@ public async Task OnWhisperCommand(CommandEventArgs command)
}
}

public Task SendChatMessage(string message)
public Task SendChatMessage(string message, bool sourceOnly = true)
{
return mediator.Publish(new SendBotMessage(message));
}

public async Task ResponseWithMessage(CommandEventArgs e, string message)
public async Task ResponseWithMessage(CommandEventArgs e, string message, bool sourceOnly = true)
{
message = message.TrimStart('!').Trim();

if (string.IsNullOrWhiteSpace(e.MessageId))
{
await SendChatMessage(e.DisplayName, message);
await SendChatMessage(e.DisplayName, message, sourceOnly);
}
else
{
await mediator.Publish(new ReplyToMessage(e.DisplayName ,e.MessageId, message));
await mediator.Publish(new ReplyToMessage(e.DisplayName ,e.MessageId, message, sourceOnly));
}
}

public async Task SendChatMessage(string name, string message)
public async Task SendChatMessage(string name, string message, bool sourceOnly = true)
{
await SendChatMessage(string.Format("@{0}, {1}", name, message));
}
public async Task SendChatMessageWithTitle(string viewerName, string message)
public async Task SendChatMessageWithTitle(string viewerName, string message, bool sourceOnly = true)
{
using var scope = scopeFactory.CreateAsyncScope();
var viewerService = scope.ServiceProvider.GetRequiredService<Commands.Features.IViewerFeature>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class BaseCommandProperties
public bool SayCooldown { get; set; } = true;
public bool SayRankRequirement { get; set; } = false;
public bool ExcludeFromUi { get; set; } = false;
public bool SourceOnly { get; set; } = true;
public string Category { get; set; } = "";
public string Description { get; set; } = "";
public bool RunFromBroadcasterOnly { get; set; } = false;
Expand Down
5 changes: 3 additions & 2 deletions DotNetTwitchBot/Bot/TwitchServices/ITwitchChatBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
public interface ITwitchChatBot : IHostedService
{
Task<bool> IsConnected();
Task ReplyToMessage(string name, string messageId, string message);
Task SendMessage(string message);
Task<bool> RefreshAccessToken();
Task ReplyToMessage(string name, string messageId, string message, bool sourceOnly = true);
Task SendMessage(string message, bool sourceOnly = true);
void SetAccessToken(string accessToken);
}
}
Loading
Loading