pass through parsed string instead of sender to command

This commit is contained in:
jetsparrow 2018-12-19 22:45:57 +03:00
parent 4947351b89
commit 37236d50ff
4 changed files with 8 additions and 8 deletions

View File

@ -20,13 +20,13 @@ namespace JetKarmaBot
{ {
var text = args.Message.Text; 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; return false;
if (commands.ContainsKey(cs.Command)) if (commands.ContainsKey(cmd.Command))
return commands[cs.Command].Execute(sender,args); return commands[cmd.Command].Execute(cmd, args);
} }
return false; return false;

View File

@ -14,7 +14,7 @@ namespace JetKarmaBot.Commands
{ {
public IReadOnlyCollection<string> Names => new[] { "award", "revoke"}; public IReadOnlyCollection<string> Names => new[] { "award", "revoke"};
public bool Execute(object sender, MessageEventArgs args) public bool Execute(CommandString cmd, MessageEventArgs args)
{ {
if (args.Message.ReplyToMessage == null) 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; } [Inject(true)] TelegramBotClient Client { get; set; }
User Me { get; } User Me { get; }

View File

@ -6,7 +6,7 @@ namespace JetKarmaBot.Commands
public interface IChatCommand public interface IChatCommand
{ {
IReadOnlyCollection<string> Names { get; } IReadOnlyCollection<string> Names { get; }
bool Execute(object sender, MessageEventArgs messageEventArgs); bool Execute(CommandString cmd, MessageEventArgs messageEventArgs);
} }
} }

View File

@ -10,7 +10,7 @@ namespace JetKarmaBot.Commands
public IReadOnlyCollection<string> Names => new[] { "start" }; public IReadOnlyCollection<string> 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.AddChat(new Db.Chat { ChatId = args.Message.Chat.Id });
Db.AddUser(new Db.User { UserId = args.Message.From.Id }); Db.AddUser(new Db.User { UserId = args.Message.From.Id });