pass through parsed string instead of sender to command

This commit is contained in:
jetsparrow 2018-12-19 22:45:57 +03:00
parent 0bb9a58711
commit 1684b62e7d
4 changed files with 8 additions and 8 deletions

View File

@ -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;

View File

@ -14,7 +14,7 @@ namespace JetKarmaBot.Commands
{
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)
{
@ -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; }

View File

@ -6,7 +6,7 @@ namespace JetKarmaBot.Commands
public interface IChatCommand
{
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 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 });