Skip to content

Commit dcd5660

Browse files
committed
Fixed text command to handle a CR delimited array, added cooldown timers
1 parent c70a7bb commit dcd5660

File tree

5 files changed

+51
-34
lines changed

5 files changed

+51
-34
lines changed

Fritz.Chatbot/Commands/SoundFxCommand.cs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ public SoundFxCommand(IHubContext<AttentionHub, IAttentionHubClient> hubContext,
3131
public TimeSpan? Cooldown => TimeSpan.FromSeconds(0);
3232

3333
internal static Dictionary<string, SoundFxDefinition> Effects = new Dictionary<string, SoundFxDefinition>();
34-
/*
35-
{
36-
{ "ohmy", ("Oh my... something strange is happening", "ohmy.mp3", TimeSpan.FromSeconds(30) ) },
37-
{ "andthen", ("... and then ...", "andthen#.mp3", TimeSpan.FromSeconds(120) ) },
38-
{ "javascript", ("Horses LOVE JavaScript!", "javascript.mp3", TimeSpan.FromSeconds(30) ) },
39-
{ "rimshot", ("Ba Dum Tish!", "rimshot.mp3", TimeSpan.FromSeconds(60)) }
40-
};
41-
*/
4234

4335
private static readonly Dictionary<string, List<string>> MultipleFileTriggers = new Dictionary<string, List<string>>();
4436

@@ -74,30 +66,24 @@ public Task Execute(IChatService chatService, string userName, string fullComman
7466
bool InternalCooldownCheck()
7567
{
7668

77-
if (cmdText == "andthen")
78-
{
79-
if (!CheckMultipleFilesCooldown(cmd, cmdText))
80-
{
81-
chatService.SendMessageAsync($"@{userName} - No AND THEN!");
82-
return false;
83-
}
84-
85-
return true;
86-
}
87-
else if (cmd.Files != null)
69+
if (cmd.Files != null)
8870
{
89-
if (!CheckMultipleFilesCooldown(cmd, cmdText))
71+
TimeSpan cooldownRemaining;
72+
if (!CheckMultipleFilesCooldown(cmd, cmdText, out cooldownRemaining))
9073
{
9174
// TODO: Something witty to indicate the message isn't available
92-
chatService.SendMessageAsync($"@{userName} - Scott is taking a break.. check back soon!");
75+
chatService.SendMessageAsync($"@{userName} - {cmd.CooldownMessage} - Please wait another {Math.Round(cooldownRemaining.TotalSeconds)} seconds");
9376
return false;
9477
}
9578
return true;
9679
}
9780

9881
if (!SoundCooldowns.ContainsKey(cmdText)) return true;
9982
var cooldown = TimeSpan.FromSeconds(Effects[cmdText].Cooldown);
100-
return (SoundCooldowns[cmdText].Add(cooldown) < DateTime.Now);
83+
84+
var cooldownWaiting = (SoundCooldowns[cmdText].Add(cooldown).Subtract(DateTime.Now));
85+
if (cooldownWaiting.TotalSeconds > 0) chatService.SendMessageAsync($"The !{cmdText} is not available for another {Math.Round(cooldownWaiting.TotalSeconds)} seconds");
86+
return cooldownWaiting.TotalSeconds <= 0;
10187

10288
}
10389

@@ -118,10 +104,11 @@ private DateTime CalculateMultipleFileCooldownTime(SoundFxDefinition cmd, string
118104

119105
}
120106

121-
private bool CheckMultipleFilesCooldown(SoundFxDefinition cmd, string cmdText)
107+
private bool CheckMultipleFilesCooldown(SoundFxDefinition cmd, string cmdText, out TimeSpan cooldownRemaining)
122108
{
123109

124110
var cooldown = TimeSpan.FromSeconds(Effects[cmdText].Cooldown);
111+
cooldownRemaining = TimeSpan.Zero;
125112

126113
if (SoundCooldowns.ContainsKey(cmdText))
127114
{
@@ -133,6 +120,7 @@ private bool CheckMultipleFilesCooldown(SoundFxDefinition cmd, string cmdText)
133120
}
134121
else
135122
{
123+
cooldownRemaining = SoundCooldowns[cmdText].Add(cooldown).Subtract(DateTime.Now);
136124
return (MultipleFileTriggers[cmdText].Count != cmd.Files.Length);
137125
}
138126
}
@@ -169,5 +157,7 @@ public class SoundFxDefinition
169157

170158
public int Cooldown { get; set; }
171159

160+
public string CooldownMessage { get; set; }
161+
172162
}
173163
}

Fritz.Chatbot/Commands/TextCommand.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,32 @@ public Task Execute(IChatService chatService, string userName, string fullComman
6464
if (cmd == "lurk")
6565
return chatService.SendMessageAsync($"@{userName} {_Commands[cmd]}");
6666

67-
return chatService.SendMessageAsync($"@{userName} - {_Commands[cmd]}");
68-
69-
}
67+
if (!_Commands[cmd].Contains('\n'))
68+
{
69+
return chatService.SendMessageAsync($"@{userName} - {_Commands[cmd]}");
70+
} else {
71+
var messages = _Commands[cmd].Split('\n');
72+
73+
Task firstTask = null;
74+
Task previousTask = null;
75+
foreach (var msg in messages)
76+
{
77+
if (firstTask == null)
78+
{
79+
firstTask = chatService.SendMessageAsync(msg);
80+
previousTask = firstTask;
81+
}
82+
else
83+
{
84+
var thisTask = chatService.SendMessageAsync(msg);
85+
previousTask.ContinueWith((o) => thisTask);
86+
previousTask = thisTask;
87+
}
88+
}
89+
return firstTask;
90+
}
91+
92+
}
7093
}
7194

7295

Fritz.StreamTools/Fritz.StreamTools.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.7.1" />
2525
<PackageReference Include="Microsoft.AspNetCore.App" />
2626
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="1.1.5" />
27-
<PackageReference Include="Microsoft.Azure.CognitiveServices.Language.TextAnalytics" Version="3.0.0" />
27+
<PackageReference Include="Microsoft.Azure.CognitiveServices.Language.TextAnalytics" Version="4.0.0" />
2828
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" />
2929
<PackageReference Include="Octokit" Version="0.32.0" />
3030
<PackageReference Include="System.IO.Abstractions" Version="6.0.14" />

Fritz.StreamTools/Services/SentimentService.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ public async Task Run()
7575
var messageList = SentimentSink.RecentChatMessages.Select((value, index) => new MultiLanguageInput { Text = value, Id = index.ToString(), Language = "en" }).ToList();
7676
SentimentSink.RecentChatMessages.Clear();
7777

78-
SentimentBatchResult results = await _client.SentimentAsync(null,
79-
new MultiLanguageBatchInput(messageList)
80-
);
78+
// Cheer 100 goranhal 25/8/19
79+
// Cheer 100 cadmus 25/8/19
80+
// Cheer 100 eternaldevcoder 25/8/19
81+
82+
SentimentBatchResult results = await _client.SentimentBatchAsync(new MultiLanguageBatchInput(messageList));
8183

8284
var avgScore = results.Documents
8385
.Where(d => d.Score.HasValue)

Fritz.StreamTools/appsettings.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
},
4646
"SentimentAnalysisKey": "I'M NOT TYPING HERE...",
4747
"HypeCommand": {
48-
"TemplateText": "PartyPopper PartyPopper HYPE! PartyPopper PartyPopper ",
48+
"TemplateText": "csharpHypebot csharpHypebot bleedPurple PartyHat HYPE! PartyHat bleedPurple csharpHypebot csharpHypebot",
4949
"RepeatCount": 3
5050
},
5151
"AttentionCommand": {
@@ -72,7 +72,8 @@
7272
"andthen5.mp3",
7373
"andthen6.mp3"
7474
],
75-
"cooldown": 120
75+
"cooldown": 120,
76+
"CooldownMessage": "No AND THEN!"
7677
},
7778
"javascript": {
7879
"response": "Horses LOVE JavaScript!",
@@ -97,7 +98,8 @@
9798
"greatscott_6.mp3",
9899
"greatscott_7.mp3"
99100
],
100-
"cooldown": 30
101+
"cooldown": 30,
102+
"CooldownMessage": "Scott is taking a break.. check back soon!"
101103
},
102104
"squirrel": {
103105
"response": "Hey look, a SQUIRREL! Jeff's not distracted AT ALL",
@@ -149,7 +151,7 @@
149151
},
150152
{
151153
"command": "raid",
152-
"response": "Prepare to RAID! Copy this text to use when we reach our raid target: ------------ Subscribers copy ------------- csharpRaid csharpRaid csharpRaid CsharpFritz's Coding Squad is Here! All your base are belong to us! csharpRaid csharpRaid csharpRaid ------------ Non-Subscribers copy ------------- twitchRaid twitchRaid twitchRaid CsharpFritz's Coding Squad is Here! All your base are belong to us! twitchRaid twitchRaid twitchRaid"
154+
"response": "Prepare to RAID! Copy this text to use when we reach our raid target:\n▬▬ Subscribers Copy ▬▬\ncsharpRaid csharpRaid csharpRaid CsharpFritz's Coding Squad is Here! All your base are belong to us! csharpRaid csharpRaid csharpRaid\n▬▬ Non-Subscribers ▬▬\ntwitchRaid twitchRaid twitchRaid CsharpFritz's Coding Squad is Here! All your base are belong to us! twitchRaid twitchRaid twitchRaid"
153155
},
154156
{
155157
"command": "tacos",

0 commit comments

Comments
 (0)