Skip to content

Commit d6f4dd1

Browse files
committed
2 parents e6b68eb + 0be67cf commit d6f4dd1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1883
-330
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,6 @@ __pycache__/
292292
*.btm.cs
293293
*.odx.cs
294294
*.xsd.cs
295+
296+
# Ignore mp3 files
297+
*.mp3

ConsoleChatbot/ConsoleChatbot.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
</ItemGroup>
1717

1818
<ItemGroup>
19-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" />
19+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
2020
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.1" />
2121
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.1" />
22-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
23-
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.1.1" />
22+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
23+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.2.0" />
2424
</ItemGroup>
2525

2626
</Project>

Fritz.Chatbot/AttentionHub.cs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,46 @@
77

88
namespace Fritz.StreamTools.Hubs
99
{
10-
public interface IAttentionHubClient
11-
{
10+
public interface IAttentionHubClient
11+
{
1212

13-
// Cheer 200 parithon 12/18/2018
14-
// Cheer 500 pharewings 12/18/2018
13+
// Cheer 200 parithon 12/18/2018
14+
// Cheer 500 pharewings 12/18/2018
1515
Task AlertFritz();
1616
Task ClientConnected(string connectionId);
1717
Task SummonScott();
18+
19+
Task PlaySoundEffect(string fileName);
20+
21+
Task NotifyChannelPoints(ChannelPointRedemption redemption);
22+
23+
}
24+
25+
public class AttentionHub : Hub<IAttentionHubClient>, IAttentionClient
26+
{
27+
public override Task OnConnectedAsync()
28+
{
29+
return this.Clients.Others.ClientConnected(this.Context.ConnectionId);
1830
}
1931

20-
public class AttentionHub : Hub<IAttentionHubClient>, IAttentionClient
32+
public Task AlertFritz()
33+
{
34+
return this.Clients.Others.AlertFritz();
35+
}
36+
37+
public Task SummonScott()
2138
{
22-
public override Task OnConnectedAsync()
23-
{
24-
return this.Clients.Others.ClientConnected(this.Context.ConnectionId);
25-
}
2639

27-
public Task AlertFritz()
28-
{
29-
return this.Clients.Others.AlertFritz();
30-
}
40+
return this.Clients.Others.SummonScott();
3141

32-
public Task SummonScott()
33-
{
42+
}
3443

35-
return this.Clients.Others.SummonScott();
44+
public Task PlaySoundEffect(string fileName)
45+
{
3646

37-
}
47+
return this.Clients.Others.PlaySoundEffect(fileName);
3848

3949
}
50+
51+
}
4052
}

Fritz.Chatbot/Commands/HelpCommand.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ public HelpCommand(IServiceProvider serviceProvider)
2424
public async Task Execute(IChatService chatService, string userName, ReadOnlyMemory<char> rhs)
2525
{
2626
var commands = _serviceProvider.GetServices<IBasicCommand>();
27+
var textCommandArray = TextCommand._Commands.Select(kv => "!" + kv.Key.ToLower());
28+
var soundFxCommands = SoundFxCommand.Effects.Select(kv => "!" + kv.Key.ToLower());
2729

2830
if (rhs.IsEmpty)
2931
{
3032

3133
var availableCommandArray = commands.Where(c => !string.IsNullOrEmpty(c.Trigger)).Select(c => $"!{c.Trigger.ToLower()}");
32-
var textCommandArray = TextCommand._Commands.Select(kv => "!" + kv.Key.ToLower());
3334

34-
var availableCommands = string.Join(' ', availableCommandArray.Union(textCommandArray).OrderBy(s => s));
35+
var availableCommands = string.Join(' ', availableCommandArray.Union(textCommandArray).Union(soundFxCommands).OrderBy(s => s));
3536

3637
await chatService.SendMessageAsync($"Supported commands: {availableCommands}");
3738
return;
@@ -40,7 +41,19 @@ public async Task Execute(IChatService chatService, string userName, ReadOnlyMem
4041
var cmd = commands.FirstOrDefault(c => rhs.Span.Equals(c.Trigger.AsSpan(), StringComparison.OrdinalIgnoreCase));
4142
if (cmd == null)
4243
{
43-
await chatService.SendMessageAsync("Unknown command to provide help with.");
44+
45+
if (textCommandArray.Contains("!" + rhs.Span.ToString()))
46+
{
47+
await chatService.SendMessageAsync($"{rhs}: A helpful text message");
48+
}
49+
else if (soundFxCommands.Contains("!" + rhs.Span.ToString()))
50+
{
51+
await chatService.SendMessageAsync($"{rhs}: A fun sound effect");
52+
}
53+
else
54+
{
55+
await chatService.SendMessageAsync("Unknown command to provide help with.");
56+
}
4457
return;
4558
}
4659

Fritz.Chatbot/Commands/IBasicCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public interface IBasicCommand2 : IBasicCommand {
4343
/// <param name="userName">User that invoked the command</param>
4444
/// <param name="badges">Badges carried by the user</param>
4545
/// <param name="rhs">The remaining text after the trigger keyword</param>
46-
Task Execute(IChatService chatService, string userName, bool isModerator, bool isBroadcaster, ReadOnlyMemory<char> rhs);
46+
Task Execute(IChatService chatService, string userName, bool isModerator, bool isVip, bool isBroadcaster, ReadOnlyMemory<char> rhs);
4747

4848
}
4949

Fritz.Chatbot/Commands/ProjectCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public ProjectCommand(IConfiguration configuration)
2222

2323
private static string CurrentProject = null;
2424

25-
public async Task Execute(IChatService chatService, string userName, bool isModerator, bool isBroadcaster, ReadOnlyMemory<char> rhs)
25+
public async Task Execute(IChatService chatService, string userName, bool isModerator, bool isVip, bool isBroadcaster, ReadOnlyMemory<char> rhs)
2626
{
2727
if ((isModerator || isBroadcaster) && !rhs.IsEmpty)
2828
{

Fritz.Chatbot/Commands/ScottCommand.cs

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
using Fritz.StreamLib.Core;
6+
7+
namespace Fritz.Chatbot.Commands
8+
{
9+
public class SentimentCommand : IBasicCommand
10+
{
11+
public string Trigger => "sentiment";
12+
public string Description => "Information about the sentiment analysis features of the chat room";
13+
public TimeSpan? Cooldown => TimeSpan.FromSeconds(30);
14+
15+
public async Task Execute(IChatService chatService, string userName, ReadOnlyMemory<char> rhs)
16+
{
17+
18+
var sb = new StringBuilder();
19+
sb.Append($"The sentiment over the last minute is {SentimentSink.Sentiment1Minute.ToString("00.0%")} percent positive ");
20+
sb.Append((SentimentSink.Sentiment1Minute < SentimentSink.Sentiment5Minute) ? "and trending upward (up arrow) " : "and trending downward (down arrow) ");
21+
sb.Append("compared to the last five minutes ");
22+
sb.Append($"The most recent messages were {((SentimentSink.SentimentInstant >=0.5) ? "positive" : "negative")} (smiley face)");
23+
24+
await chatService.SendMessageAsync(sb.ToString());
25+
26+
}
27+
}
28+
}

Fritz.Chatbot/Commands/SentimentSink.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ public class SentimentSink
1010

1111
public static Queue<string> RecentChatMessages { get; } = new Queue<string>();
1212

13+
public static double SentimentInstant { get; set; }
14+
15+
public static double Sentiment1Minute { get; set; }
16+
17+
public static double Sentiment5Minute { get; set; }
18+
1319
}
1420

1521
}

Fritz.Chatbot/Commands/ShoutoutCommand.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@
33
using System.Net.Http;
44
using System.Threading.Tasks;
55
using Fritz.StreamLib.Core;
6+
using Microsoft.Extensions.Logging;
67

78
namespace Fritz.Chatbot.Commands
89
{
910
public class ShoutoutCommand : IBasicCommand2
1011
{
1112
private readonly HttpClient _HttpClient;
13+
private readonly ILogger _Logger;
1214

13-
public ShoutoutCommand(IHttpClientFactory httpClientFactory)
15+
public ShoutoutCommand(IHttpClientFactory httpClientFactory, ILoggerFactory logger)
1416
{
1517

1618
_HttpClient = httpClientFactory.CreateClient("ShoutoutCommand");
19+
_HttpClient.BaseAddress = new Uri("https://api.twitch.tv/helix/users");
20+
21+
_Logger = logger.CreateLogger(nameof(ShoutoutCommand));
1722

1823
}
1924

@@ -24,19 +29,23 @@ public ShoutoutCommand(IHttpClientFactory httpClientFactory)
2429

2530
public TimeSpan? Cooldown => TimeSpan.FromSeconds(5);
2631

27-
public async Task Execute(IChatService chatService, string userName, bool isModerator, bool isBroadcaster, ReadOnlyMemory<char> rhs)
32+
public async Task Execute(IChatService chatService, string userName, bool isModerator, bool isVip, bool isBroadcaster, ReadOnlyMemory<char> rhs)
2833
{
2934

30-
if (!(isModerator || isBroadcaster)) return;
35+
if (!(isModerator || isVip || isBroadcaster)) return;
3136

3237
var rhsTest = rhs.ToString();
3338
if (rhsTest.StartsWith("@")) rhsTest = rhsTest.Substring(1);
3439
if (rhsTest.StartsWith("http")) return;
3540
if (rhsTest.Contains(" ")) return;
3641

3742
rhsTest = WebUtility.UrlEncode(rhsTest);
38-
var result = await _HttpClient.GetAsync(rhsTest);
39-
if (result.StatusCode != HttpStatusCode.OK) return;
43+
var result = await _HttpClient.GetAsync($"?login={rhsTest}");
44+
if (result.StatusCode != HttpStatusCode.OK)
45+
{
46+
_Logger.LogWarning($"Unable to verify Shoutout for {rhsTest}");
47+
return;
48+
}
4049

4150
await chatService.SendMessageAsync($"Please follow @{rhsTest} at: https://twitch.tv/{rhsTest}");
4251

0 commit comments

Comments
 (0)