Skip to content

Commit 1da2d03

Browse files
authored
September 2020 fixes (#449)
* Removed coffee text commands * Increased Teammate detection timeout to 2 hours by default * Removed broadcaster from Teammate detection * Now awaiting the delay between Teammate notifications * Set default TODO scroll speed to 5 * Moved todo speed to AppSettings.FritzBot.TodoSpeed * Cleaned up TODO commands, adding replace * Fixed #440 - Added undone feature to TODO
1 parent 1c23ba1 commit 1da2d03

File tree

4 files changed

+75
-16
lines changed

4 files changed

+75
-16
lines changed

Fritz.Chatbot/Commands/TeamCommand.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class TeamCommand : IExtendedCommand
2020
private static HashSet<string> _Teammates = new HashSet<string>();
2121
private static Dictionary<string, DateTime> _TeammateCooldown = new Dictionary<string, DateTime>();
2222
private string _TeamName;
23+
private readonly string _BroadcasterChannel;
2324
private HttpClient _HttpClient;
2425
private readonly IHubContext<AttentionHub> _Context;
2526
private ILogger _Logger;
@@ -36,6 +37,7 @@ public class TeamCommand : IExtendedCommand
3637
public TeamCommand(IConfiguration configuration, ILoggerFactory loggerFactory, IHubContext<AttentionHub> context, IHttpClientFactory httpClientFactory)
3738
{
3839
_TeamName = configuration["StreamServices:Twitch:Team"];
40+
_BroadcasterChannel = configuration["StreamServices:Twitch:Channel"];
3941
ShoutoutCooldown = configuration.GetValue("StreamServices:Twitch:TeamCooldown", TimeSpan.FromHours(1));
4042
ShoutoutFormat = configuration.GetValue("StreamServices:Twitch:TeamShoutoutFormat", "");
4143
_Context = context;
@@ -68,7 +70,7 @@ private void SendNotificationsToWidget()
6870
if (_TeammateNotifications.TryPeek(out var _)) {
6971

7072
_Context.Clients.All.SendAsync("Teammate", _TeammateNotifications.Dequeue());
71-
Task.Delay(5000);
73+
Task.Delay(5000).GetAwaiter().GetResult(); // TODO: This notification needs to go into a queue
7274

7375
}
7476

@@ -80,6 +82,13 @@ public bool CanExecute(string userName, string fullCommandText)
8082
{
8183

8284
var u = userName.ToLowerInvariant();
85+
86+
// Add check to make sure we don't notify if the chatter is the Twitch broadcaster
87+
if (u.Equals(_BroadcasterChannel, StringComparison.InvariantCultureIgnoreCase))
88+
{
89+
return false;
90+
}
91+
8392
var isTeammate = _Teammates.Contains(u);
8493
var recentShoutout = _TeammateCooldown.ContainsKey(u) && (DateTime.UtcNow.Subtract(_TeammateCooldown[u]) < ShoutoutCooldown);
8594

Fritz.Chatbot/Commands/ToDoCommand.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ public class ToDoCommand : IBasicCommand2
2020

2121
private readonly Dictionary<string, Func<string[], ToDoCommand, Task>> _Verbs = new Dictionary<string, Func<string[], ToDoCommand, Task>> {
2222
{"add", AddTodo },
23+
{"replace", ReplaceTodo },
2324
{"remove", RemoveTodo },
2425
{"done", DoneTodo },
26+
{"undone", UndoneTodo },
2527
{"clear", ClearTodo },
2628
{"active", Activate },
2729
{"deactivate", Deactivate },
@@ -101,6 +103,35 @@ private static async Task DoneTodo(string[] args, ToDoCommand cmd)
101103

102104
}
103105

106+
private static async Task UndoneTodo(string[] args, ToDoCommand cmd)
107+
{
108+
109+
if (int.TryParse(args[1], out var id) && _ToDos.Any(t => t.Key == id))
110+
{
111+
var todo = _ToDos[id];
112+
todo.completed = false;
113+
_ToDos[id] = todo;
114+
await cmd._HubContext.Clients.All.SendAsync("todo_undone", id);
115+
}
116+
117+
}
118+
119+
120+
121+
private static async Task ReplaceTodo(string[] args, ToDoCommand cmd)
122+
{
123+
if (int.TryParse(args[1], out var replaceId) && _ToDos.Any(t => t.Key == replaceId))
124+
{
125+
var thisTodo = _ToDos[replaceId];
126+
thisTodo.text = args[2];
127+
_ToDos[replaceId] = thisTodo;
128+
await cmd._HubContext.Clients.All.SendAsync("todo_replace", replaceId, args[2]);
129+
}
130+
131+
}
132+
133+
134+
104135
private static async Task RemoveTodo(string[] args, ToDoCommand cmd)
105136
{
106137

Fritz.StreamTools/Pages/ToDo.cshtml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@page
2-
@{
3-
}
2+
@inject Microsoft.Extensions.Configuration.IConfiguration Configuration
43
<!DOCTYPE html>
54

65
<html>
@@ -26,7 +25,7 @@
2625
<script>
2726
2827
var debug = true;
29-
var scrollSpeed = 1.5;
28+
var scrollSpeed = @(Configuration["FritzBot:Todo:Speed"] ?? "5");
3029
3130
3231
(function () {
@@ -64,6 +63,14 @@
6463
if (this.debug) console.debug("Done ToDo", { id });
6564
this.Complete(id);
6665
});
66+
this._hub.on('todo_undone', (id) => {
67+
if (this.debug) console.debug("Undone ToDo", { id });
68+
this.Incomplete(id);
69+
});
70+
this._hub.on('todo_replace', (id, text) => {
71+
if (this.debug) console.debug("Replace ToDo", { id, text });
72+
this.Replace(id, text);
73+
});
6774
this._hub.on("todo_remove", (id) => {
6875
if (this.debug) console.debug("Remove ToDo", { id });
6976
this.Remove(id);
@@ -109,6 +116,22 @@
109116
110117
}
111118
119+
this.Incomplete = function (id) {
120+
var el = document.querySelectorAll(`li[data-id='${id}'] > i`);
121+
el[0].className = "far fa-square";
122+
if (el.length > 1) el[1].className = "far fa-square";
123+
124+
}
125+
126+
this.Replace = function (id, text) {
127+
var el = document.querySelectorAll(`li[data-id='${id}'] > i`);
128+
var regEx = /\s\d+\..*/g;
129+
for (var e in el) {
130+
e.innerHTML = e.innerHTML.replace(regEx, ` ${id}. ${text}`);
131+
}
132+
133+
}
134+
112135
this.Clear = function (id) {
113136
var el = document.querySelectorAll(`li[data-id='${id}'] > i`);
114137
el[0].className = "far fa-square";

Fritz.StreamTools/appsettings.json

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"ChatBotName": "FritzBot_",
2222
"Team": "livecoders",
2323
"TeamDisplayName": "The Live Coders",
24-
"TeamCooldown": "01:00:00",
24+
"TeamCooldown": "02:00:00",
2525
"TeamShoutoutFormat": "Welcome @{teammate} from the Live Coders! livecodersLogo livecodersLogo"
2626
},
2727
"Mixer": {
@@ -85,7 +85,7 @@
8585
"response": "csharpNo csharpAndThen!",
8686
"file": "noandthen.mp3",
8787
"cooldown": 60,
88-
"CooldownMessage": "NO NO ANDTHEN!"
88+
"CooldownMessage": "NO NO ANDTHEN!"
8989
},
9090
"anticipation": {
9191
"response": "We're waiting in.... Antici.... pation",
@@ -164,14 +164,6 @@
164164
"command": "blog",
165165
"response": "Jeff's blog is at: https://jeffreyfritz.com"
166166
},
167-
{
168-
"command": "coffee",
169-
"response": "HTTP 418 - Jeff drinks Madrinas coffee - Use code: FRITZ to receive 20% off of your order at https://www.madrinascoffee.com"
170-
},
171-
{
172-
"command": "madrinas",
173-
"response": "HTTP 418 - Madrinas coffee - Fuel for the grind, fuel for your mind. Use code: FRITZ to receive 20% off of your order at https://www.madrinascoffee.com"
174-
},
175167
{
176168
"command": "defend",
177169
"response": "csharpNo csharpGritty We shall defend the channel! csharpNo csharpGritty"
@@ -181,7 +173,7 @@
181173
"response": "Join us on the Fritz and Friends Discord server at: https://discord.gg/RnJhrJq"
182174
},
183175
{
184-
"command": "font",
176+
"command": "font",
185177
"response": "Jeff typically uses the open source Cascadia Code font available at: https://github.com/microsoft/cascadia-code"
186178
},
187179
{
@@ -216,7 +208,11 @@
216208
"command": "youtube",
217209
"response": "Find the archive of videos from our channel at: https://youtube.com/csharpfritz"
218210
}
219-
]
211+
],
212+
"Todo": {
213+
"Speed": 5
214+
}
215+
220216
},
221217
"FollowerGoal": {
222218
"Caption": "Follower Goal",

0 commit comments

Comments
 (0)