Skip to content

Commit 2c57315

Browse files
committed
Added a GFUEL command and made the TextCommand accept a colection of configuration options #255"
1 parent 6fcb2c2 commit 2c57315

File tree

4 files changed

+92
-41
lines changed

4 files changed

+92
-41
lines changed

Fritz.Chatbot/Commands/TextCommand.cs

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,71 @@
33
using System.Text;
44
using System.Threading.Tasks;
55
using Fritz.StreamLib.Core;
6+
using Microsoft.Extensions.Configuration;
7+
using System.Linq;
8+
using System.Xml;
9+
using System.Diagnostics;
610

711
namespace Fritz.Chatbot.Commands
812
{
913

10-
public class TextCommand : IExtendedCommand
14+
public class TextCommand : IExtendedCommand
15+
{
16+
17+
// Cheer 143 cpayette 03/3/19
18+
// Cheer 142 cpayette 2/06/19
19+
// Cheer 150 ramblinggeek 2/06/19
20+
21+
public TextCommand(IConfiguration configuration)
1122
{
23+
this.Configuration = configuration;
1224

13-
// Cheer 143 cpayette 03/3/19
25+
var children = Configuration.GetSection("FritzBot:TextCommand").GetChildren().ToArray();
26+
foreach (var cmd in children)
27+
{
28+
_Commands.Add(cmd.GetValue<string>("command"), cmd.GetValue<string>("response"));
29+
}
1430

15-
public string Name => "TextCommand";
16-
public string Description => "Return a simple line of text";
17-
public int Order => 0;
18-
public bool Final => true;
19-
public TimeSpan? Cooldown => TimeSpan.FromSeconds(5);
31+
}
2032

21-
internal static readonly Dictionary<string, string> _Commands = new Dictionary<string, string>
22-
{
23-
{ "music", "Jeff plays 'Music to Code By' from Carl Franklin: http://mtcb.pwop.com" },
24-
{ "discord", "Join us on the Fritz and Friends Discord server at: https://discord.gg/RnJhrJq" },
25-
{ "github", "Checkout Jeff's GitHub at: https://github.com/csharpfritz and the FritzAndFriends GitHub organization at: https://github.com/FritzAndFriends" },
26-
{ "keyboard", "Jeff uses a Vortex Race 3 with Cherry MX Blue switches, details on his blog at: https://jeffreyfritz.com/2018/07/mechanical-keyboards-i-just-got-one-and-why-you-need-one-too/" },
27-
{ "blog", "Jeff's blog is at: https://jeffreyfritz.com" },
28-
{ "youtube", "Find the archive of videos from our channel at: https://youtube.com/csharpfritz" },
29-
{ "lurk", "is stepping away from keyboard and lurking" },
30-
{ "defend", "csharpNo csharpGritty We shall defend the channel! csharpNo csharpGritty" },
31-
{ "raid", @"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 " +
32-
" ------------ Non-Subscribers copy ------------- twitchRaid twitchRaid twitchRaid CsharpFritz's Coding Squad is Here! All your base are belong to us! twitchRaid twitchRaid twitchRaid " }
33-
};
33+
public string Name => "TextCommand";
34+
public string Description => "Return a simple line of text";
35+
public int Order => 0;
36+
public bool Final => true;
37+
public TimeSpan? Cooldown => TimeSpan.FromSeconds(5);
3438

35-
internal static bool IsCommand(string commandText)
36-
{
39+
public IConfiguration Configuration { get; }
3740

38-
return _Commands.ContainsKey(commandText);
41+
internal static readonly Dictionary<string, string> _Commands = new Dictionary<string, string>();
3942

40-
}
43+
internal static bool IsCommand(string commandText)
44+
{
4145

42-
public bool CanExecute(string userName, string fullCommandText)
43-
{
46+
return _Commands.ContainsKey(commandText);
4447

45-
if (!fullCommandText.StartsWith("!")) return false;
46-
var cmd = fullCommandText.Substring(1).ToLowerInvariant();
47-
return _Commands.ContainsKey(cmd);
48+
}
4849

49-
}
50+
public bool CanExecute(string userName, string fullCommandText)
51+
{
5052

51-
public Task Execute(IChatService chatService, string userName, string fullCommandText)
52-
{
53+
if (!fullCommandText.StartsWith("!")) return false;
54+
var cmd = fullCommandText.Substring(1).ToLowerInvariant();
55+
return _Commands.ContainsKey(cmd);
5356

54-
var cmd = fullCommandText.Substring(1).ToLowerInvariant();
57+
}
58+
59+
public Task Execute(IChatService chatService, string userName, string fullCommandText)
60+
{
5561

56-
if (cmd == "lurk")
57-
return chatService.SendMessageAsync($"@{userName} {_Commands[cmd]}");
62+
var cmd = fullCommandText.Substring(1).ToLowerInvariant();
5863

59-
return chatService.SendMessageAsync($"@{userName} - {_Commands[cmd]}");
64+
if (cmd == "lurk")
65+
return chatService.SendMessageAsync($"@{userName} {_Commands[cmd]}");
66+
67+
return chatService.SendMessageAsync($"@{userName} - {_Commands[cmd]}");
6068

61-
}
6269
}
70+
}
71+
6372

6473
}

Fritz.StreamTools/appsettings.json

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,50 @@
5454
},
5555
"ProjectCommand": {
5656
"TemplateText": "@{0} Jeff is currently working on {1}",
57-
"DefaultText": "nothing! Are we not working on anything @csharpfritz?"
58-
}
57+
"DefaultText": "nothing! Are we not working on anything @csharpfritz?"
58+
},
59+
"TextCommand": [
60+
{
61+
"command": "blog",
62+
"response": "Jeff's blog is at: https://jeffreyfritz.com"
63+
},
64+
{
65+
"command": "defend",
66+
"response": "csharpNo csharpGritty We shall defend the channel! csharpNo csharpGritty"
67+
},
68+
{
69+
"command": "discord",
70+
"response": "Join us on the Fritz and Friends Discord server at: https://discord.gg/RnJhrJq"
71+
},
72+
{
73+
"command": "gfuel",
74+
"response": "Jeff drinks GFUEL from Gamma Labs as a coffee replacement. 0g sugar, 150mg caffeine, 25 calories and you can learn more at https://gfuel.com"
75+
},
76+
{
77+
"command": "github",
78+
"response": "Checkout Jeff's GitHub at: https://github.com/csharpfritz and the FritzAndFriends GitHub organization at: https://github.com/FritzAndFriends"
79+
},
80+
{
81+
"command": "keyboard",
82+
"response": "Jeff uses a Vortex Race 3 with Cherry MX Blue switches, details on his blog at: https://jeffreyfritz.com/2018/07/mechanical-keyboards-i-just-got-one-and-why-you-need-one-too/"
83+
},
84+
{
85+
"command": "lurk",
86+
"response": "is stepping away from keyboard and lurking"
87+
},
88+
{
89+
"command": "music",
90+
"response": "Jeff plays 'Music to Code By' from Carl Franklin: http://mtcb.pwop.com"
91+
},
92+
{
93+
"command": "raid",
94+
"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"
95+
},
96+
{
97+
"command": "youtube",
98+
"response": "Find the archive of videos from our channel at: https://youtube.com/csharpfritz"
99+
}
100+
]
59101
},
60102
"FollowerGoal": {
61103
"Caption": "Follower Goal",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// Write your Javascript code.
1+
// Write your Javascript code.

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "2.1.401"
3+
"version": "2.2.300"
44
}
55
}

0 commit comments

Comments
 (0)