Skip to content

Commit 3adb385

Browse files
committed
Added some text commands and the old man dev channel points feature
1 parent 1896796 commit 3adb385

File tree

5 files changed

+73
-15
lines changed

5 files changed

+73
-15
lines changed

Fritz.Chatbot/Commands/SoundFxCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public SoundFxCommand(IHubContext<AttentionHub, IAttentionHubClient> hubContext,
2828
public string Description => "Play a fun sound effect in the stream";
2929
public int Order => 1;
3030
public bool Final => true;
31-
public TimeSpan? Cooldown => TimeSpan.FromSeconds(0);
31+
public TimeSpan? Cooldown => TimeSpan.FromSeconds(5);
3232

3333
internal static Dictionary<string, SoundFxDefinition> Effects = new Dictionary<string, SoundFxDefinition>();
3434

Fritz.StreamTools/Fritz.StreamTools.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
</None>
4242
</ItemGroup>
4343
<ItemGroup>
44+
<Folder Include="wwwroot\contents\oldman\" />
4445
<Folder Include="wwwroot\lib\signalr\" />
4546
</ItemGroup>
4647
</Project>

Fritz.StreamTools/Services/TwitchPubSubService.cs

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.Extensions.Options;
1010
using System;
1111
using System.Collections.Generic;
12+
using System.IO;
1213
using System.Linq;
1314
using System.Threading;
1415
using System.Threading.Tasks;
@@ -21,50 +22,95 @@ public class TwitchPubSubService : IHostedService
2122
private IServiceProvider _ServiceProvider;
2223
private CancellationToken _Token;
2324
private Task _BackgroundTask;
25+
private static string[] _OldManSoundFx;
26+
public static short _OldManCount = 0;
2427
private readonly Twitch.PubSub.Proxy _Proxy;
2528
private readonly ConfigurationSettings _Configuration;
29+
private readonly IHostEnvironment _HostEnvironment;
30+
private readonly Dictionary<string, Action<IHubContext<AttentionHub, IAttentionHubClient>>> _ChannelPointActions = new Dictionary<string, Action<IHubContext<AttentionHub, IAttentionHubClient>>>();
2631

27-
public TwitchPubSubService(IServiceProvider serviceProvider, Twitch.PubSub.Proxy proxy, IOptions<ConfigurationSettings> settings)
32+
public TwitchPubSubService(IServiceProvider serviceProvider, Twitch.PubSub.Proxy proxy, IHostEnvironment hostEnvironment, IOptions<ConfigurationSettings> settings)
2833
{
2934
_ServiceProvider = serviceProvider;
3035
_Proxy = proxy;
3136
_Configuration = settings.Value;
37+
_HostEnvironment = hostEnvironment;
38+
39+
InitializeChannelPointActions();
40+
41+
}
42+
43+
private void InitializeChannelPointActions()
44+
{
45+
_ChannelPointActions.Add("get off my lawn!", (c) => TwitchPubSubService.OldManDeveloper(c));
3246
}
3347

3448
public Task StartAsync(CancellationToken cancellationToken)
3549
{
3650
_Proxy.OnChannelPointsRedeemed += _Proxy_OnChannelPointsRedeemed;
3751
_Token = cancellationToken;
3852
_BackgroundTask = _Proxy.StartAsync(new TwitchTopic[] { TwitchTopic.ChannelPoints(_Configuration.UserId) }, _Token);
53+
IdentifyOldManAudio();
3954
return Task.CompletedTask;
4055
}
4156

57+
private void IdentifyOldManAudio()
58+
{
59+
60+
var oldManPath = Path.Combine(_HostEnvironment.ContentRootPath, "wwwroot", "contents", "oldman");
61+
var di = new DirectoryInfo(oldManPath);
62+
_OldManSoundFx = di.GetFiles().Select(f => f.Name).OrderBy(x => Guid.NewGuid()).ToArray();
63+
64+
}
65+
4266
private void _Proxy_OnChannelPointsRedeemed(object sender, ChannelRedemption e)
4367
{
4468
using (var scope = _ServiceProvider.CreateScope())
4569
{
4670
var context = scope.ServiceProvider.GetRequiredService<IHubContext<AttentionHub, IAttentionHubClient>>();
47-
//context.Clients.All.PlaySoundEffect("pointsredeemed.mp3");
48-
var redemption = new ChannelPointRedemption
71+
72+
if (_ChannelPointActions.ContainsKey(e.redemption.reward.title.ToLowerInvariant())) {
73+
_ChannelPointActions[e.redemption.reward.title.ToLowerInvariant()](context);
74+
}
75+
else
4976
{
50-
RedeemingUserName = e.redemption.user.display_name,
51-
RedeemingUserId = e.redemption.user.id,
52-
RewardName = e.redemption.reward.title,
53-
RewardValue = e.redemption.reward.cost,
54-
RewardPrompt = e.redemption.user_input,
55-
BackgroundColor = e.redemption.reward.background_color,
56-
Image_1x = new Uri(e.redemption.reward.image?.url_1x ?? e.redemption.reward.default_image.url_1x),
57-
Image_2x = new Uri(e.redemption.reward.image?.url_2x ?? e.redemption.reward.default_image.url_2x),
58-
Image_4x = new Uri(e.redemption.reward.image?.url_4x ?? e.redemption.reward.default_image.url_4x)
59-
};
60-
context.Clients.All.NotifyChannelPoints(redemption);
77+
78+
var redemption = new ChannelPointRedemption
79+
{
80+
RedeemingUserName = e.redemption.user.display_name,
81+
RedeemingUserId = e.redemption.user.id,
82+
RewardName = e.redemption.reward.title,
83+
RewardValue = e.redemption.reward.cost,
84+
RewardPrompt = e.redemption.user_input,
85+
BackgroundColor = e.redemption.reward.background_color,
86+
Image_1x = new Uri(e.redemption.reward.image?.url_1x ?? e.redemption.reward.default_image.url_1x),
87+
Image_2x = new Uri(e.redemption.reward.image?.url_2x ?? e.redemption.reward.default_image.url_2x),
88+
Image_4x = new Uri(e.redemption.reward.image?.url_4x ?? e.redemption.reward.default_image.url_4x)
89+
};
90+
context.Clients.All.NotifyChannelPoints(redemption);
91+
92+
}
6193
}
6294
}
6395

6496
public Task StopAsync(CancellationToken cancellationToken)
6597
{
6698
_Proxy.Dispose();
6799
return Task.CompletedTask;
100+
68101
}
102+
103+
#region Channel Point Actions
104+
105+
public static void OldManDeveloper(IHubContext<AttentionHub, IAttentionHubClient> hubContext)
106+
{
107+
108+
var fx = _OldManSoundFx[_OldManCount++ % _OldManSoundFx.Length];
109+
hubContext.Clients.All.PlaySoundEffect($"oldman/{fx}");
110+
111+
}
112+
113+
#endregion
114+
69115
}
70116
}

Fritz.StreamTools/Views/Attention/Points.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
font-size: 42px;
1717
color: #FFF;
1818
text-shadow: 1px 1px 1px #000;
19+
background-color: rgba(0, 0, 153, 0.4);
1920
}
2021
2122
@@keyframes fadeIn {

Fritz.StreamTools/appsettings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@
7777
"cooldown": 120,
7878
"CooldownMessage": "No AND THEN!"
7979
},
80+
"noandthen": {
81+
"response": "csharpNo csharpAndThen!",
82+
"file": "noandthen.mp3",
83+
"cooldown": 60,
84+
"CooldownMessage": "NO NO ANDTHEN!"
85+
},
8086
"anticipation": {
8187
"response": "We're waiting in.... Antici.... pation",
8288
"file": "anticipation.mp3",
@@ -170,6 +176,10 @@
170176
"command": "discord",
171177
"response": "Join us on the Fritz and Friends Discord server at: https://discord.gg/RnJhrJq"
172178
},
179+
{
180+
"command": "font",
181+
"response": "Jeff typically uses the open source Cascadia Code font available at: https://github.com/microsoft/cascadia-code"
182+
},
173183
{
174184
"command": "github",
175185
"response": "Checkout Jeff's GitHub at: https://github.com/csharpfritz and the FritzAndFriends GitHub organization at: https://github.com/FritzAndFriends"

0 commit comments

Comments
 (0)