From 1684b62e7d2e78ccd7414194d0e0ead0742f3c96 Mon Sep 17 00:00:00 2001 From: jetsparrow Date: Wed, 19 Dec 2018 22:45:57 +0300 Subject: [PATCH] pass through parsed string instead of sender to command --- JetKarmaBot/CommandRouter.cs | 8 ++++---- JetKarmaBot/Commands/AwardCommand.cs | 4 ++-- JetKarmaBot/Commands/IChatCommand.cs | 2 +- JetKarmaBot/Commands/StartCommand.cs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/JetKarmaBot/CommandRouter.cs b/JetKarmaBot/CommandRouter.cs index 71cfb46..1824eaa 100644 --- a/JetKarmaBot/CommandRouter.cs +++ b/JetKarmaBot/CommandRouter.cs @@ -20,13 +20,13 @@ namespace JetKarmaBot { var text = args.Message.Text; - if (CommandString.TryParse(text, out var cs)) + if (CommandString.TryParse(text, out var cmd)) { - if (cs.UserName != null && cs.UserName != BotUser.Username) // directed not at us! + if (cmd.UserName != null && cmd.UserName != BotUser.Username) // directed not at us! return false; - if (commands.ContainsKey(cs.Command)) - return commands[cs.Command].Execute(sender,args); + if (commands.ContainsKey(cmd.Command)) + return commands[cmd.Command].Execute(cmd, args); } return false; diff --git a/JetKarmaBot/Commands/AwardCommand.cs b/JetKarmaBot/Commands/AwardCommand.cs index 4b3d507..401c6b2 100644 --- a/JetKarmaBot/Commands/AwardCommand.cs +++ b/JetKarmaBot/Commands/AwardCommand.cs @@ -14,7 +14,7 @@ namespace JetKarmaBot.Commands { public IReadOnlyCollection Names => new[] { "award", "revoke"}; - public bool Execute(object sender, MessageEventArgs args) + public bool Execute(CommandString cmd, MessageEventArgs args) { if (args.Message.ReplyToMessage == null) { @@ -60,7 +60,7 @@ namespace JetKarmaBot.Commands } - [Inject(true)]Db Db { get; set; } + [Inject(true)] Db Db { get; set; } [Inject(true)] TelegramBotClient Client { get; set; } User Me { get; } diff --git a/JetKarmaBot/Commands/IChatCommand.cs b/JetKarmaBot/Commands/IChatCommand.cs index 5928e5a..ebfacc0 100644 --- a/JetKarmaBot/Commands/IChatCommand.cs +++ b/JetKarmaBot/Commands/IChatCommand.cs @@ -6,7 +6,7 @@ namespace JetKarmaBot.Commands public interface IChatCommand { IReadOnlyCollection Names { get; } - bool Execute(object sender, MessageEventArgs messageEventArgs); + bool Execute(CommandString cmd, MessageEventArgs messageEventArgs); } } diff --git a/JetKarmaBot/Commands/StartCommand.cs b/JetKarmaBot/Commands/StartCommand.cs index 0aa3516..d52b3ac 100644 --- a/JetKarmaBot/Commands/StartCommand.cs +++ b/JetKarmaBot/Commands/StartCommand.cs @@ -10,7 +10,7 @@ namespace JetKarmaBot.Commands public IReadOnlyCollection Names => new[] { "start" }; - public bool Execute(object sender, MessageEventArgs args) + public bool Execute(CommandString cmd, MessageEventArgs args) { Db.AddChat(new Db.Chat { ChatId = args.Message.Chat.Id }); Db.AddUser(new Db.User { UserId = args.Message.From.Id });