|
3 | 3 | using System.Text;
|
4 | 4 | using System.Threading.Tasks;
|
5 | 5 | using Fritz.StreamLib.Core;
|
| 6 | +using Microsoft.Extensions.Configuration; |
| 7 | +using System.Linq; |
| 8 | +using System.Xml; |
| 9 | +using System.Diagnostics; |
6 | 10 |
|
7 | 11 | namespace Fritz.Chatbot.Commands
|
8 | 12 | {
|
9 | 13 |
|
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) |
11 | 22 | {
|
| 23 | + this.Configuration = configuration; |
12 | 24 |
|
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 | + } |
14 | 30 |
|
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 | + } |
20 | 32 |
|
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); |
34 | 38 |
|
35 |
| - internal static bool IsCommand(string commandText) |
36 |
| - { |
| 39 | + public IConfiguration Configuration { get; } |
37 | 40 |
|
38 |
| - return _Commands.ContainsKey(commandText); |
| 41 | + internal static readonly Dictionary<string, string> _Commands = new Dictionary<string, string>(); |
39 | 42 |
|
40 |
| - } |
| 43 | + internal static bool IsCommand(string commandText) |
| 44 | + { |
41 | 45 |
|
42 |
| - public bool CanExecute(string userName, string fullCommandText) |
43 |
| - { |
| 46 | + return _Commands.ContainsKey(commandText); |
44 | 47 |
|
45 |
| - if (!fullCommandText.StartsWith("!")) return false; |
46 |
| - var cmd = fullCommandText.Substring(1).ToLowerInvariant(); |
47 |
| - return _Commands.ContainsKey(cmd); |
| 48 | + } |
48 | 49 |
|
49 |
| - } |
| 50 | + public bool CanExecute(string userName, string fullCommandText) |
| 51 | + { |
50 | 52 |
|
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); |
53 | 56 |
|
54 |
| - var cmd = fullCommandText.Substring(1).ToLowerInvariant(); |
| 57 | + } |
| 58 | + |
| 59 | + public Task Execute(IChatService chatService, string userName, string fullCommandText) |
| 60 | + { |
55 | 61 |
|
56 |
| - if (cmd == "lurk") |
57 |
| - return chatService.SendMessageAsync($"@{userName} {_Commands[cmd]}"); |
| 62 | + var cmd = fullCommandText.Substring(1).ToLowerInvariant(); |
58 | 63 |
|
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]}"); |
60 | 68 |
|
61 |
| - } |
62 | 69 | }
|
| 70 | + } |
| 71 | + |
63 | 72 |
|
64 | 73 | }
|
0 commit comments