public string Execute(object sender, MessageEventArgs args) { var text = args.Message.Text; if (CommandString.TryParse(text, out var cmd)) { if (cmd.UserName != null && cmd.UserName != Username) { return(null); } if (Commands.ContainsKey(cmd.Command)) { return(Commands[cmd.Command].Execute(cmd, args)); } } return(null); }
void BotOnMessageReceived(object sender, MessageEventArgs args) { var message = args.Message; if (message == null || message.Type != MessageType.Text) { return; } if (!CommandString.TryParse(args.Message.Text, out var cmd)) { return; } if (cmd.UserName != null && cmd.UserName != Commands.Me.Username) { return; } RequestContext ctx = new RequestContext(Client, args, cmd); _ = Chain.Handle(ctx); }