Skip to content

Commit 90208af

Browse files
committed
Added Scott command #232
1 parent c7de8df commit 90208af

File tree

8 files changed

+74
-5
lines changed

8 files changed

+74
-5
lines changed

Fritz.Chatbot/AttentionHub.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public interface IAttentionHubClient
1414
// Cheer 500 pharewings 12/18/2018
1515
Task AlertFritz();
1616
Task ClientConnected(string connectionId);
17+
Task SummonScott();
1718
}
1819

1920
public class AttentionHub : Hub<IAttentionHubClient>, IAttentionClient
@@ -27,5 +28,13 @@ public Task AlertFritz()
2728
{
2829
return this.Clients.Others.AlertFritz();
2930
}
31+
32+
public Task SummonScott()
33+
{
34+
35+
return this.Clients.Others.SummonScott();
36+
37+
}
38+
3039
}
3140
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Text;
3+
using System.Threading.Tasks;
4+
using Fritz.StreamLib.Core;
5+
using Fritz.StreamTools.Hubs;
6+
using Microsoft.AspNetCore.SignalR;
7+
using Microsoft.AspNetCore.SignalR.Client;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.Hosting;
10+
using Microsoft.Extensions.Logging;
11+
12+
namespace Fritz.Chatbot.Commands
13+
{
14+
public class ScottCommand : IBasicCommand
15+
{
16+
private readonly IConfiguration Configuration;
17+
18+
public ILogger Logger { get; }
19+
public IHubContext<AttentionHub, IAttentionHubClient> HubContext { get; }
20+
21+
public ScottCommand(IConfiguration configuration, IHubContext<AttentionHub, IAttentionHubClient> hubContext, ILoggerFactory loggerFactory)
22+
{
23+
this.Configuration = configuration;
24+
this.Logger = loggerFactory.CreateLogger("ScottCommand");
25+
26+
this.HubContext = hubContext;
27+
28+
}
29+
30+
//protected HubConnection Client { get; }
31+
32+
public string Trigger => "scott";
33+
34+
public string Description => "Request Frau Farbissina to summon Scott";
35+
36+
#if DEBUG
37+
public TimeSpan? Cooldown => TimeSpan.FromSeconds(60);
38+
#else
39+
public TimeSpan? Cooldown => TimeSpan.Parse(Configuration["FritzBot:AttentionCommand:Cooldown"]);
40+
#endif
41+
42+
public async Task Execute(IChatService chatService, string userName, ReadOnlyMemory<char> rhs)
43+
{
44+
45+
await this.HubContext.Clients.All.SummonScott();
46+
47+
await chatService.SendMessageAsync(string.Format("SCOTTTTTT!!!", userName));
48+
49+
}
50+
51+
}
52+
}

Fritz.StreamTools/Fritz.StreamTools.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131
<PackageReference Include="System.Memory" Version="4.5.1" />
3232
</ItemGroup>
3333
<ItemGroup>
34-
<None Include="wwwroot\contents\hey_listen.wav">
35-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
36-
</None>
3734
<None Include="wwwroot\js\GoalConfiguration\GoalConfiguration.js" />
3835
<None Include="wwwroot\js\GoalConfiguration\GoogleFonts.js" />
3936
<None Include="wwwroot\js\GoalConfiguration\Preview.js" />

Fritz.StreamTools/Views/Attention/Index.cshtml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@
1313
<script src="~/js/attentionhub.js"></script>
1414

1515
<script>
16-
var audio = new Audio('@Url.Content(@"~/contents/hey_listen.wav")');
17-
16+
var audio = new Audio('@Url.Content(@"~/contents/hey_listen.mp3")');
17+
var scottAudio = new Audio('@Url.Content(@"~/contents/Scott!!.mp3")');
18+
1819
var hub = new AttentionHub();
1920
hub.onAlertFritz = () => {
2021
alertFritz();
2122
}
2223
24+
hub.onSummonScott = () => {
25+
scottAudio.play();
26+
}
27+
2328
function alertFritz() {
2429
audio.play();
2530
}
15.6 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

Fritz.StreamTools/wwwroot/js/attentionhub.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
class AttentionHub {
33
constructor() {
44
this.onAlertFritz = null;
5+
this.onSummonScott = null;
56
this.debug = true;
67
this._hub = null;
78
}
@@ -34,6 +35,11 @@ class AttentionHub {
3435
if (this.onAlertFritz) this.onAlertFritz();
3536
});
3637

38+
this._hub.on("SummonScott", () => {
39+
if (this.debug) console.debug("Summoning Scott!");
40+
if (this.onSummonScott) this.onSummonScott();
41+
});
42+
3743
return this._hub.start();
3844
}
3945

0 commit comments

Comments
 (0)